Are you computoholic? Yep that's a word I just made up. Not present in any dictionary. Do you tend to get up from the seat in front of your computer at the evening with the sudden revelation that you didn't make it out of the room even two times within the day. Or are you suffering from eye problems due to excessive usage of computers. Then here is some thing that may worth checking out. Workrave is a small software which sits behind your back and says to you when to stop!. Yes you heard me. After certain interval it rings to you by giving visual indications that you should probably take some tea break or if not some exercises for your eye or your back. It plays you animations as well as how to do them. Pretty cool huh? The time intervals are configurable. So it is advisable to the set the break intervals that suites your work style. But don't cheat and set the interval to 4 hrs. You know what I mean. In Ubuntu you can install it by
$sudo apt-get install workrave
It is cross platform. Google workrave you will get many references.
Tuesday, 30 June 2009
Tuning the hard drive
Ever thought why your disk takes ages to move that all important film your private folder? May be Linux utility hdparm can help you. hdparm is a utility which allows you to view and change certain hard disk parameters whether it be SATA or PATA. Here are some useful commands which you can use to probe the status of your drive and find tune it.
Viewing hard drive information
* hdparm -I /dev/sda
Viewing hard drive performance
* hdparm -Tt /dev/sda
Syntax explanation
* Options
-T = Checks the how quickly data can be passed between the processor, memory, and disk cache
-t = Reads continuously from the hard disk without reading previously cached data. This gives an indication of the speed at which Linux can read sequential data from the disk
Tuning the drive
* hdparm -W1 /dev/sda (Turns write cache on. Use -W0 to set it to off)
* hdparm -A1 /dev/sda (Turns read ahead cache on. Use -A0 to set it to off)
* hdparm -a[n] /dev/sda (Turns read ahead cache on with n KB read ahead)
* hdparm -d1 [mode-option] /dev/sda (Turns DMA on with specified mode)
mode mode-option
pio0 -X08 Programmed I/O
pio1 -X09
pio2 -X10
pio3 -X11
pio4 -X12
mdma0 -X32 Multiword DMA
mdma1 -X33
mdma2 -X34
udma0 -X64 Ultra DMA
udma1 -X65
udma2 -X66
udma3 -X67
udma4 -X68
udma5 -X69
* hdparm -m[n] /dev/sda (Turns on mulisector I/O mode in which more than one sector can be transferred within one interrupt. n is the number of sectors. Typical 8,16 etc.)
Try experiment with these options and then measure disk performance with every change. You may be surprised with some improvements. But remember some setting may be too aggressive to your hard-drive. So think twice if you are setting too aggressive values to increase the performance.
Making things permanent
These changes will only be available in the current session. Modify /etc/hdparm.conf with these options to make the changes permanent across reboots.
Viewing hard drive information
* hdparm -I /dev/sda
Viewing hard drive performance
* hdparm -Tt /dev/sda
Syntax explanation
* Options
-T = Checks the how quickly data can be passed between the processor, memory, and disk cache
-t = Reads continuously from the hard disk without reading previously cached data. This gives an indication of the speed at which Linux can read sequential data from the disk
Tuning the drive
* hdparm -W1 /dev/sda (Turns write cache on. Use -W0 to set it to off)
* hdparm -A1 /dev/sda (Turns read ahead cache on. Use -A0 to set it to off)
* hdparm -a[n] /dev/sda (Turns read ahead cache on with n KB read ahead)
* hdparm -d1 [mode-option] /dev/sda (Turns DMA on with specified mode)
mode mode-option
pio0 -X08 Programmed I/O
pio1 -X09
pio2 -X10
pio3 -X11
pio4 -X12
mdma0 -X32 Multiword DMA
mdma1 -X33
mdma2 -X34
udma0 -X64 Ultra DMA
udma1 -X65
udma2 -X66
udma3 -X67
udma4 -X68
udma5 -X69
* hdparm -m[n] /dev/sda (Turns on mulisector I/O mode in which more than one sector can be transferred within one interrupt. n is the number of sectors. Typical 8,16 etc.)
Try experiment with these options and then measure disk performance with every change. You may be surprised with some improvements. But remember some setting may be too aggressive to your hard-drive. So think twice if you are setting too aggressive values to increase the performance.
Making things permanent
These changes will only be available in the current session. Modify /etc/hdparm.conf with these options to make the changes permanent across reboots.
Running Windows XP on Ubuntu with QEmu (QuickStart Guide)
Just for the fun of it I tried running XP on my Hardy box. Here are the quick start steps I used to make it work.
Step 1 - Making the file later used as the disk image.
dd if=/dev/zero of=win.iso bs=1M count=4300
This will make an 4GB .iso file on the current directory.
Step 2 - Installation
Insert the XP cd to your CD-ROM and execute the following in the terminal.
qemu -hda ./win.iso -cdrom /dev/cdrom -boot d -m 256 -localtime -usb
Syntax Explanation
-hda ./win.iso = This means win.iso is used as the hard disk 0 image.
-cdrom /dev/cdrom = Uses the CD-ROM image for the installation
-boot d = Boot on CD-ROM
-m 256 = Sets the virtual RAM size to 256MB
-localtime = Set the real time clock to local time
-usb = Enable the USB driver
Then the normal XP installation procedure begins and you can install it as you would normally do on a normal machine.
Step 3 - Running the installed image
To run the XP image at any time run the following.
qemu -hda ./win_dev.iso -boot c -m 256 -localtime -usb
Key Combinations
* Ctrl + Alt releases the cursor
* Ctrl + Alt + f toggles full screen
Step 1 - Making the file later used as the disk image.
dd if=/dev/zero of=win.iso bs=1M count=4300
This will make an 4GB .iso file on the current directory.
Step 2 - Installation
Insert the XP cd to your CD-ROM and execute the following in the terminal.
qemu -hda ./win.iso -cdrom /dev/cdrom -boot d -m 256 -localtime -usb
Syntax Explanation
-hda ./win.iso = This means win.iso is used as the hard disk 0 image.
-cdrom /dev/cdrom = Uses the CD-ROM image for the installation
-boot d = Boot on CD-ROM
-m 256 = Sets the virtual RAM size to 256MB
-localtime = Set the real time clock to local time
-usb = Enable the USB driver
Then the normal XP installation procedure begins and you can install it as you would normally do on a normal machine.
Step 3 - Running the installed image
To run the XP image at any time run the following.
qemu -hda ./win_dev.iso -boot c -m 256 -localtime -usb
Key Combinations
* Ctrl + Alt releases the cursor
* Ctrl + Alt + f toggles full screen
Friday, 1 May 2009
Partition
Recently I watched Partition, a movie with a story line built around an inter-racial love during the times of ethnic unrest when Pakistan split from India as a separate state. Well it has to be said theme that 'Love transcend all' is moving and the Canadian producer has done pretty good job in recreating an imagery consistent with what we have of the typical Indian society backed by some good musical compositions. I think the lead actor and actress has done a good job given that none of them are even Asian.
But I saw this fact itself has been subject to criticism in some quarters who suggest that an Indian lead actor couple would have brought more authenticity to the film. I also think this is reasonable as well. If you are narrating a typical Indian story line why would you go for non Asian actors when plenty of talent is present in India? Apart from that there are some ripe inaccuracies in the way the story is depicted. Almost all of the people in the story use English as their main form communication, one of the first inconsistencies I noticed straight away. And the way lovers express their affection (yes kissing :-)) is not very consistent with the conservative Asian culture even now(though constraints are lessening due to western influence) not to mention that this story line is narrating 50 years history. Some movie critics had even mentioned the way the story is narrated is not correct with the real historical events. Then again I don't think a movie should just a documentary totally depicting historical details in pin point detail. But disregarding or misinterpreting vital parts of the events may be problematic.
Had the above issues not been there it would have made real masterpiece about love without boundaries.
But I saw this fact itself has been subject to criticism in some quarters who suggest that an Indian lead actor couple would have brought more authenticity to the film. I also think this is reasonable as well. If you are narrating a typical Indian story line why would you go for non Asian actors when plenty of talent is present in India? Apart from that there are some ripe inaccuracies in the way the story is depicted. Almost all of the people in the story use English as their main form communication, one of the first inconsistencies I noticed straight away. And the way lovers express their affection (yes kissing :-)) is not very consistent with the conservative Asian culture even now(though constraints are lessening due to western influence) not to mention that this story line is narrating 50 years history. Some movie critics had even mentioned the way the story is narrated is not correct with the real historical events. Then again I don't think a movie should just a documentary totally depicting historical details in pin point detail. But disregarding or misinterpreting vital parts of the events may be problematic.
Had the above issues not been there it would have made real masterpiece about love without boundaries.
Sunday, 26 April 2009
Using HttPClient to invoke a web service
Assume that the web service operation accepts a zip file as a base64 encoded string in its SOAP message body. Here is a way how I got it to work using commons HttpClient.
import org.apache.commons.io.FileUtils;
import org.apache.commons.httpclient.*;
import org.apache.commons.codec.binary.Base64;
import javax.xml.soap.*
public class FileUploader{
public static void main(String args[]) throws Exception{
String serviceEndpointUrl;// assign the service endpoint url here
File uploadingFile=new File("HelloWorld.zip");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(serviceEndpointUrl);
RequestEntity re= getRequestEntity(uploadingFile)
method.setRequestEntity(re);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(1, false));
int statusCode = client.executeMethod(method);
String responseBody = method.getResponseBodyAsString();
System.out.println(responseBody);
}
static RequestEntity getRequestEntity(File file) throws Exception{
MessageFactory mFactory = MessageFactory.newInstance();
SOAPMessage message= mFactory.createMessage();
SOAPBody body= message.getSOAPBody();
SOAPElement zipElement=body.addChildElement("zip");
StringBuilder content= new StringBuilder();
byte[] arr= FileUtils.readFileToByteArray(file);
byte[] encoded= Base64.encodeBase64Chunked(arr);
for (int i= 0; i < encoded.length; i++) {
content.append((char) encoded[i]);
}
ByteArrayOutputStream b= new ByteArrayOutputStream();
message.writeTo(b);
String base64EncodedString= b.toString();
return new StringEntity(base64EncodedString);
}
You will need Apache commons jars in your classpath.
import org.apache.commons.io.FileUtils;
import org.apache.commons.httpclient.*;
import org.apache.commons.codec.binary.Base64;
import javax.xml.soap.*
public class FileUploader{
public static void main(String args[]) throws Exception{
String serviceEndpointUrl;// assign the service endpoint url here
File uploadingFile=new File("HelloWorld.zip");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(serviceEndpointUrl);
RequestEntity re= getRequestEntity(uploadingFile)
method.setRequestEntity(re);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(1, false));
int statusCode = client.executeMethod(method);
String responseBody = method.getResponseBodyAsString();
System.out.println(responseBody);
}
static RequestEntity getRequestEntity(File file) throws Exception{
MessageFactory mFactory = MessageFactory.newInstance();
SOAPMessage message= mFactory.createMessage();
SOAPBody body= message.getSOAPBody();
SOAPElement zipElement=body.addChildElement("zip");
StringBuilder content= new StringBuilder();
byte[] arr= FileUtils.readFileToByteArray(file);
byte[] encoded= Base64.encodeBase64Chunked(arr);
for (int i= 0; i < encoded.length; i++) {
content.append((char) encoded[i]);
}
ByteArrayOutputStream b= new ByteArrayOutputStream();
message.writeTo(b);
String base64EncodedString= b.toString();
return new StringEntity(base64EncodedString);
}
You will need Apache commons jars in your classpath.
Converting a String to org.jdom.Document
import org.jdom.*;
String xml="
SAXBuilder builder=new SAXBuilder();
Document doc = builder.build(new StringReader(xml));
Tuesday, 14 April 2009
Useful Linux Commands and Tools
To list the kernel routing table
$ netstat -nr
To get the information about USB buses in the system and devices connected to them
$ lsusb
To get a listing of open ports with associated processes
$ sudo lsof -i
or
$ sudo netstat -lptu
Using netcat to setup a server
$ nc -l -p[port]
Using netcat as a proxy
$ nc -l -p [listening-port] | nc [host:port] | nc -l -p [output-port]
$ netstat -nr
To get the information about USB buses in the system and devices connected to them
$ lsusb
To get a listing of open ports with associated processes
$ sudo lsof -i
or
$ sudo netstat -lptu
Using netcat to setup a server
$ nc -l -p
Using netcat as a proxy
$ nc -l -p
Thursday, 9 April 2009
Building ODE- Errors and Tips
It seems building ODE is not the easiest thing to do. I found this the hard way when I really messed up all sorts of things when trying to build ODE in my office machine. (Funny thing is that it went to the extent of reinstalling the OS). The process is quite strange if you are new to the Ruby world like me, because ODE uses a Ruby build system called buildr. Before installing buildr following packages has to be installed if Ruby is not installed in your system.
Ruby - packages related to the language
RubyGems - the Ruby package manager
buildr internally uses the Ruby build program Rake which is a simple ruby build program with capabilities similar to make.
So the second time I was prepared. I metaculously went through the instructions in the ODE and buildr sites. Since the information is scattered a bit across sites, here is the exact the steps I went through for a succesful ODE build. Note that ODE branch and ODE trunk uses different versions of buildr. So both versions of buildr has to be installed first.
Important: I am using an Ubuntu box. So these steps are for an Ubuntu system.
Installing buildr
Step 1 - Installing Ruby
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.2.10
//this version is used to build ODE branch
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.2
//this version is used to build ODE trunk
Step 4 - Source checkout
Now installing buildr has been done ODE can be built from its source. To checkout ODE.
Branch
Step 5 - Build ODE
Go to the checkout directory. In this case ode-1.x in case of branch and ode-trunk in case of trunk.
Building branch
Building trunk
Generating Eclipse project files
Generating IDEA project files
Note: It also work even if you don't mention the buildr version in trunk build. But in the branch build version number has to be used. Otherwise you may see an error similar to this.
rake aborted!
can't activate buildr (~> 1.2.4, runtime), already activated buildr-1.3.2
~/ode-1.x/Rakefile:17
Ruby - packages related to the language
RubyGems - the Ruby package manager
buildr internally uses the Ruby build program Rake which is a simple ruby build program with capabilities similar to make.
So the second time I was prepared. I metaculously went through the instructions in the ODE and buildr sites. Since the information is scattered a bit across sites, here is the exact the steps I went through for a succesful ODE build. Note that ODE branch and ODE trunk uses different versions of buildr. So both versions of buildr has to be installed first.
Important: I am using an Ubuntu box. So these steps are for an Ubuntu system.
Installing buildr
Step 1 - Installing Ruby
$ sudo apt-get install ruby-full ruby1.8-dev libopenssl-ruby build-essentialStep 3 - Installing buildr
Step 2 - Installing RubyGems
$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
$ tar xzf rubygems-1.2.0.tgz
$ cd rubygems-1.2.0
$ sudo ruby setup.rb
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.2.10
//this version is used to build ODE branch
$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.2
//this version is used to build ODE trunk
Step 4 - Source checkout
Now installing buildr has been done ODE can be built from its source. To checkout ODE.
Branch
$> svn checkout http://svn.apache.org/repos/asf/ode/branches/APACHE_ODE_1.X ode-1.X
Trunk$> svn checkout http://svn.apache.org/repos/asf/ode/trunk ode-trunk
Step 5 - Build ODE
Go to the checkout directory. In this case ode-1.x in case of branch and ode-trunk in case of trunk.
Building branch
$> buildr _1.2.10_ clean install TEST=no
Building trunk
$> buildr _1.3.2_ clean install TEST=no
Generating Eclipse project files
$> buildr eclipse
Generating IDEA project files
$> buildr idea
Note: It also work even if you don't mention the buildr version in trunk build. But in the branch build version number has to be used. Otherwise you may see an error similar to this.
rake aborted!
can't activate buildr (~> 1.2.4, runtime), already activated buildr-1.3.2
~/ode-1.x/Rakefile:17
Friday, 13 February 2009
Using Eclipse BatchCompiler
Using the BatchCompiler to compile a Java source at runtime is well documented in the Eclipse help system. The problem that I came across was providing the classpath for the compilation to happen. Actually the jars needed, I had included in the runtime classpath of my plugin and were inside the plugin project. First challenge was to get the classpath entries so that I can append them to compile String to be fed in to the compiler. Surprisingly it wasn't easy enough as I had thought. After some experimentations on plugin API I finally got following code to work.
Dictionary manifest=Activator.getDefault().getBundle().getHeaders();
Enumeration cpKeyEnum=manifest.keys();
String classpath;
while(cpKeyEnum.hasMoreElements()){
Object cpKey=cpKeyEnum.nextElement();
if(cpKey.toString().equals("Bundle-ClassPath")){
classPath=manifest.get(cpKey).toString();
break;
}
}
Activator is the plugin activator class. Here the classpath is obtained as a comma seperated list of relative paths included in the "Bundle-ClassPath" header of MANIFEST.MF.
After solving that soon I realised the BatchCompiler itself cannot access the jars from the relative paths I got from the earlier exercise. So I had to extract these jars to a temporary location and feed the absolute path of this location to the BatchCompiler.
Dictionary manifest=Activator.getDefault().getBundle().getHeaders();
Enumeration cpKeyEnum=manifest.keys();
String classpath;
while(cpKeyEnum.hasMoreElements()){
Object cpKey=cpKeyEnum.nextElement();
if(cpKey.toString().equals("Bundle-ClassPath")){
classPath=manifest.get(cpKey).toString();
break;
}
}
Activator is the plugin activator class. Here the classpath is obtained as a comma seperated list of relative paths included in the "Bundle-ClassPath" header of MANIFEST.MF.
After solving that soon I realised the BatchCompiler itself cannot access the jars from the relative paths I got from the earlier exercise. So I had to extract these jars to a temporary location and feed the absolute path of this location to the BatchCompiler.
Changing runtime classPath of an Eclipse plugin programmatically??
While I was developing some functionality for a Eclipse plugin I came across the need to change the classpath at runtime so that some runtime generated class files can be accessed by the code. I found a hack after some Googling. (http://forums.sun.com/thread.jspa?threadID=300557). It worked fine when run as a standalone Java program. But when tried to port my code to the plugin it failed miserbly.
Only other thing that I could think of was using a seperate classloader to load these classes which actually worked. Seems that's the way to go to be on the safe side.
Only other thing that I could think of was using a seperate classloader to load these classes which actually worked. Seems that's the way to go to be on the safe side.
Friday, 30 January 2009
Revolution or scam?
I happened to hit upon an incredulous site when I was lazily surfing the web. This site happens to be promoting a book which says the science that Newton and Einstien nurtured is fundamenatally flawed. First chapter is freely available at the site. This guy goes on to say that even the mathematical derivation of some of Einstien's equations are wrong. Not being much of a physicist I am not in a position to challenge them. But what can be said is that the first chapter is full of drama. He discredits most fundamental aspects of science concepts such as work etc. May be just like most Internet hypes this may well be a scam to make some quick buck. Anyway since radical thinking is the corner stone of science this may be an interesting reading to an open minded to ponder about.
Way to reach the site for anyone interested.
www.thefinaltheory.com.
Way to reach the site for anyone interested.
www.thefinaltheory.com.
Subscribe to:
Posts (Atom)