tag:blogger.com,1999:blog-42221179516223005902024-02-20T08:07:40.994-08:00Chamith in cyber space timeChamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-4222117951622300590.post-48584225442395940032009-06-30T08:48:00.001-07:002009-06-30T09:05:39.926-07:00Do you workrave??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 <br /><br />$sudo apt-get install workrave<br /><br />It is cross platform. Google workrave you will get many references.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-69662016495449850892009-06-30T08:32:00.000-07:002009-06-30T08:47:26.427-07:00Tuning the hard driveEver 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.<br /><br /> Viewing hard drive information<br /> * hdparm -I /dev/sda<br /><br /> Viewing hard drive performance<br /> * hdparm -Tt /dev/sda<br /> <br /> Syntax explanation<br /> * Options<br /> -T = Checks the how quickly data can be passed between the processor, memory, and disk cache<br /> -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<br /><br /> Tuning the drive<br /> * hdparm -W1 /dev/sda (Turns write cache on. Use -W0 to set it to off)<br /> * hdparm -A1 /dev/sda (Turns read ahead cache on. Use -A0 to set it to off)<br /> * hdparm -a[n] /dev/sda (Turns read ahead cache on with n KB read ahead)<br /> * hdparm -d1 [mode-option] /dev/sda (Turns DMA on with specified mode)<br /> <br /> mode mode-option<br /><br /> pio0 -X08 Programmed I/O<br /> pio1 -X09<br /> pio2 -X10 <br /> pio3 -X11<br /> pio4 -X12<br /> mdma0 -X32 Multiword DMA<br /> mdma1 -X33<br /> mdma2 -X34<br /> udma0 -X64 Ultra DMA<br /> udma1 -X65<br /> udma2 -X66<br /> udma3 -X67<br /> udma4 -X68<br /> udma5 -X69<br /> * 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.)<br /><br />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.<br /><br />Making things permanent<br /><br />These changes will only be available in the current session. Modify /etc/hdparm.conf with these options to make the changes permanent across reboots.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-67794935041145193992009-06-30T07:57:00.000-07:002009-06-30T08:31:02.168-07:00Running 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.<br /><br />Step 1 - Making the file later used as the disk image.<br /><br />dd if=/dev/zero of=win.iso bs=1M count=4300<br /><br />This will make an 4GB .iso file on the current directory. <br /><br /><br />Step 2 - Installation<br /><br />Insert the XP cd to your CD-ROM and execute the following in the terminal.<br /><br />qemu -hda ./win.iso -cdrom /dev/cdrom -boot d -m 256 -localtime -usb <br /><br /><br />Syntax Explanation<br /><br />-hda ./win.iso = This means win.iso is used as the hard disk 0 image.<br /><br />-cdrom /dev/cdrom = Uses the CD-ROM image for the installation <br /><br />-boot d = Boot on CD-ROM <br /><br />-m 256 = Sets the virtual RAM size to 256MB<br /><br />-localtime = Set the real time clock to local time <br /><br />-usb = Enable the USB driver<br /><br /><br />Then the normal XP installation procedure begins and you can install it as you would normally do on a normal machine. <br /><br />Step 3 - Running the installed image<br /><br />To run the XP image at any time run the following.<br /><br />qemu -hda ./win_dev.iso -boot c -m 256 -localtime -usb<br /><br /><br />Key Combinations<br /><br /> * Ctrl + Alt releases the cursor<br /> * Ctrl + Alt + f toggles full screenChamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-54577939013143618532009-05-01T09:07:00.000-07:002009-05-01T09:35:32.565-07:00PartitionRecently 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.<br /><br />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.<br /><br />Had the above issues not been there it would have made real masterpiece about love without boundaries.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com1tag:blogger.com,1999:blog-4222117951622300590.post-42617952137164111532009-04-26T05:06:00.000-07:002009-05-26T23:28:45.905-07:00Using HttPClient to invoke a web serviceAssume 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.<br><br /><div class="mycode"><br /><span style="font-size:85%;"><br />import org.apache.commons.io.FileUtils;<br />import org.apache.commons.httpclient.*;<br />import org.apache.commons.codec.binary.Base64;<br />import javax.xml.soap.*<br /><br />public class FileUploader{</span><br /><br /><span style="font-size:85%;">public static void main(String args[]) throws Exception{<br />String serviceEndpointUrl;// assign the service endpoint url here<br /></span> <span style="font-size:85%;"> File uploadingFile=new File("HelloWorld.zip");<br /></span> <span style="font-size:85%;">HttpClient client = new HttpClient();<br /></span> <span style="font-size:85%;">PostMethod method = new PostMethod(serviceEndpointUrl);<br /><br /></span> <span style="font-size:85%;">RequestEntity re= getRequestEntity(uploadingFile)<br /></span> <span style="font-size:85%;">method.setRequestEntity(re);<br /><br /></span> <span style="font-size:85%;">method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,<br /> </span> <span style="font-size:85%;">new DefaultHttpMethodRetryHandler(1, false));<br /><br /></span> <span style="font-size:85%;">int statusCode = client.executeMethod(method);<br /><br />String responseBody = method.getResponseBodyAsString();<br />System.out.println(responseBody);<br />}</span><br /><br /><span style="font-size:85%;">static RequestEntity getRequestEntity(File file) throws Exception{<br />MessageFactory mFactory = MessageFactory.newInstance();<br />SOAPMessage message= mFactory.createMessage();<br />SOAPBody body= message.getSOAPBody();<br />SOAPElement zipElement=body.addChildElement("zip");<br /><br />StringBuilder content= new StringBuilder();<br />byte[] arr= FileUtils.readFileToByteArray(file);<br />byte[] encoded= Base64.encodeBase64Chunked(arr);<br /><br />for (int i= 0; i < encoded.length; i++) {<br />content.append((char) encoded[i]);<br />}<br /><br />ByteArrayOutputStream b= new ByteArrayOutputStream();<br />message.writeTo(b);<br />String base64EncodedString= b.toString();<br /><br />return new StringEntity(base64EncodedString);<br />}<br /></span><br /></div><br /><br />You will need Apache commons jars in your classpath.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-81540655810823754712009-04-26T04:46:00.000-07:002009-05-26T23:28:14.969-07:00Converting a String to org.jdom.Document<div class="mycode"><br /><span style="font-size:85%;">import org.jdom.*;<br /><br />String xml="<name><name> buddhika</name> < /name >";<br /><br />SAXBuilder builder=new SAXBuilder();</span><br /><span style="font-size:85%;"><br />Document doc = builder.build(new StringReader(xml));</span><br /><pre><br /></pre><br /></div>Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-66683250687834249992009-04-14T20:36:00.000-07:002009-04-14T20:52:07.212-07:00Useful Linux Commands and ToolsTo list the kernel routing table<br />$ netstat -nr<br /><br />To get the information about USB buses in the system and devices connected to them<br />$ lsusb<br /><br />To get a listing of open ports with associated processes<br />$ sudo lsof -i<br />or<br />$ sudo netstat -lptu<br /><br />Using netcat to setup a server<br />$ nc -l -p <port>[port]<br /><br />Using netcat as a proxy<br />$ nc -l -p <listening> [listening-port] | nc <host:port> [host:port] | nc -l -p [output-port]<output><br />Any request sent via the listening port will be directed to the host defined in the second stage of the pipe and the results can be gathered from the output port.</output></host:port></listening></port>Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com3tag:blogger.com,1999:blog-4222117951622300590.post-80631323782719208292009-04-09T04:56:00.000-07:002009-04-09T05:42:59.713-07:00Building ODE- Errors and TipsIt 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 <span style="font-weight: bold;">buildr</span>. Before installing buildr following packages has to be installed if Ruby is not installed in your system.<br /><br />Ruby - packages related to the language<br />RubyGems - the Ruby package manager<br /><br />buildr internally uses the Ruby build program Rake which is a simple ruby build program with capabilities similar to make.<br /><br />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.<br /><br /><span style="font-weight: bold;">Important:</span> I am using an Ubuntu box. So these steps are for an Ubuntu system.<br /><br /><span style="font-weight: bold; font-family: courier new;">Installing buildr</span><br /><br /><br /><span style="font-style: italic; font-family: courier new;">Step 1 - Installing Ruby</span><br /><pre><span class="nv">$ </span>sudo apt-get install ruby-full ruby1.8-dev libopenssl-ruby build-essential<br /><span style="font-style: italic;font-size:130%;" ><br />Step 2 - Installing RubyGem<span style="font-weight: bold;">s</span></span><br /><span style="font-style: italic; font-family: courier new;"></span><span style="font-size:130%;"><span style="font-style: italic;"></span></span><br /><span class="nv">$ </span>wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz<br /><span class="nv">$ </span>tar xzf rubygems-1.2.0.tgz<br /><span class="nv">$ </span><span class="nb">cd </span>rubygems-1.2.0<br /><span class="nv">$ </span>sudo ruby setup.rb<br /><span class="nv">$ </span>sudo ln -s /usr/bin/gem1.8 /usr/bin/gem<br /></pre><span style="font-style: italic;">Step 3 - Installing buildr</span><br /><span style="font-size:85%;"><br />$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.2.10</span><br />//this version is used to build ODE branch<br /><span style="font-size:85%;"><br />$ sudo env JAVA_HOME=$JAVA_HOME gem install buildr -v 1.3.2</span><br />//this version is used to build ODE trunk<br /><br /><span style="font-style: italic;">Step 4 - Source checkout</span><br /><br />Now installing buildr has been done ODE can be built from its source. To checkout ODE.<br /><br />Branch<br /><pre class="code-java">$> svn checkout http:<span class="code-comment">//svn.apache.org/repos/asf/ode/branches/APACHE_ODE_1.X ode-1.X<br /><br /></span></pre>Trunk<br /><pre class="code-java">$> svn checkout http:<span class="code-comment">//svn.apache.org/repos/asf/ode/trunk ode-trunk</span></pre><br /><span style="font-style: italic;">Step 5 - Build ODE</span><br /><br />Go to the checkout directory. In this case ode-1.x in case of branch and ode-trunk in case of trunk.<br /><br />Building branch<br /><pre class="code-java">$> buildr _1.2.10_ clean install TEST=no<span class="code-comment"></span></pre><br />Building trunk<br /><pre class="code-java">$> buildr _1.3.2_ clean install TEST=no<span class="code-comment"></span></pre><br />Generating Eclipse project files<br /><pre class="code-java">$> buildr eclipse<span class="code-comment"></span></pre><br />Generating IDEA project files<br /><pre class="code-java">$> <span style="font-family: Georgia,serif;">buildr idea</span></pre><br />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.<br /><br /><span style="color: rgb(255, 102, 102);">rake aborted!</span><br /><span style="color: rgb(255, 102, 102);">can't activate buildr (~> 1.2.4, runtime), already activated buildr-1.3.2</span><br /><span style="color: rgb(255, 102, 102);">~/ode-1.x/Rakefile:17</span>Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-78022289914818932102009-02-13T08:10:00.000-08:002009-02-13T09:04:10.138-08:00Using Eclipse BatchCompilerUsing 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.<br /><br />Dictionary manifest=Activator.getDefault().getBundle().getHeaders();<br />Enumeration cpKeyEnum=manifest.keys();<br />String classpath;<br /><br />while(cpKeyEnum.hasMoreElements()){<br /> Object cpKey=cpKeyEnum.nextElement();<br /> if(cpKey.toString().equals("Bundle-ClassPath")){<br /> classPath=manifest.get(cpKey).toString();<br /> break;<br /> }<br />}<br /><br />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.<br /><br />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.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-64339033538736697142009-02-13T06:22:00.000-08:002009-02-13T08:38:43.487-08:00Changing 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. (<a href="http://forums.sun.com/thread.jspa?threadID=300557">http://forums.sun.com/thread.jspa?threadID=300557</a>). It worked fine when run as a standalone Java program. But when tried to port my code to the plugin it failed miserbly.<br />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.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-3024761169079426302009-01-30T08:22:00.000-08:002009-01-30T08:36:09.950-08:00Revolution 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.<br /><br />Way to reach the site for anyone interested.<br />www.thefinaltheory.com.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-40277047828291832182008-11-06T05:07:00.000-08:002008-11-06T06:01:04.019-08:00Lessons to be learntSo finally it happened. What many Americans thought impossible to occur within their lifespan. The first black president at the helm of American power machinery. What's more important is to reflect what took him there with having a big barrier that so many thought would crush him, the color of skin.<br /><br />Apart from political reasons (economic downturn, tax policy etc. etc.) I think there were other factors at play which decided it for Obama.<br /><br />The best place to start lies within the end itself. That acceptance speech he did. The indisputable fact of his oratorship was portrayed time and time again in that speech. For me it's not been about his policy (being neutral), but the style and variations in his speech that struck to me as remarkable, which I thought were far better than Mr. MaCain. The final touches were as impressive as ever. The grandma who lived to see the how the generations has changed, boy he is a conjurer of creating imagery and penetrative words. Did I see some lady in tears when he spoke that? No doubt he was effective.<br /><br />One of the remarkable things that even in the acceptance speech I saw was amount of youth excitement and participation. The secret was partly in the way that he reached out the masses. He was talking to the modern America using modern ways. How about at his funding campaign? The decison of not being restricted to federal funding and reaching masses with an effective online funding mechanism was highly successful and proved to be a winning decision at the end of the day in both monetary wise and political wise. Today I was brought to notice about his Twitter account. Guess how many were following his posts. More than 100,000. I was surprised. How many limitless possiblities these new avenues in technology has brought us allowing us to communicate better and effectively. No doubt Obama had clearly understood the changing times has strategically adapted to them in his campaign. His effective online presence no doubt would have reached scores of young floating votes. At the end MaCain had to admit that he was addressing the 'old' America using old ways which was one of the reasons for the downfall of him.<br /><br />One thing is clear. Change or no change Obama has pulled off a great campaign all together and he derserves what he's got.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0tag:blogger.com,1999:blog-4222117951622300590.post-71133571369401538422008-10-29T07:47:00.000-07:002008-10-29T08:59:50.015-07:00Tomcat Installation - TROUBLES!!!Why are somethings seem to be so trivial but sometimes become so hard to pull off specially when in a hurry. That is what exactly happened when I tried to install tomcat in to my new Ubuntu (hardy) box. Here's what happened.<br /><br />After extracting tomcat to the installation folder and making sure necessary JAVA_HOME & JDK_HOME variables are there in .bashrc I tried to start the server with <span style="font-weight: bold;">./startup.sh</span>.<br /><br /><span style="color: rgb(204, 204, 255); font-weight: bold;">Output</span>- Permission denied.<br /><span style="font-weight: bold; color: rgb(255, 204, 0);">Reaction</span> - Hmm. Should try a sudo sh startup.sh<br /><br /><span style="color: rgb(204, 204, 255); font-weight: bold;">Output</span>- Cannot find startup.sh<br /><span style="color: rgb(255, 204, 0); font-weight: bold;">Reaction</span> - What! '<span style="font-weight: bold;">ls</span>' shows file is there. What about<span style="font-weight: bold;"> ls -al</span><br /><br /><span style="color: rgb(0, 0, 102); font-weight: bold;">Discovery !</span><span style="color: rgb(0, 0, 102);">!</span>!- No execute permissions for startup.sh file<br /><span style="color: rgb(255, 204, 0); font-weight: bold;">Reaction</span>- <span style="font-weight: bold;">chmod +x startup.sh</span>. Again tried <span style="font-weight: bold;">./starup.sh</span>.<br /><br /><span style="color: rgb(204, 204, 255); font-weight: bold;">Output</span>- Cannot find catalina.sh<br /><span style="color: rgb(255, 204, 0); font-weight: bold;">Reaction</span> - ok. should try <span style="font-weight: bold;">chmod +x *.sh</span>. Again ./startup.sh<br /><br /><span style="font-weight: bold; color: rgb(204, 204, 255);">Output</span>- The BASEDIR environment variable is not defined correctly<br />This environment variable is needed to run this program.<br /><span style="color: rgb(255, 204, 0); font-weight: bold;">Reaction</span>-What the heck!@#@#. Only help now is google.<br /><br />Little bit of googling brought my attention to the CATALINA_HOME variable. So<br />I set it to tomcat_installtion_folder/bin in .bashrc. When tried ./starup.sh it gave this.<br /><br /><span style="font-weight: bold; color: rgb(204, 204, 255);">Output</span>- Cannot find /home/chamith/Installations/apache-tomcat-6.0.18/bin/bin/setclasspath.sh<br />This file is needed to run this program<br /><span style="color: rgb(255, 204, 0); font-weight: bold;">Reaction</span>- What now????<br /><br />Again little bit of googling brought my attention to the following part in the source of catalina.sh.<br /><br /><br /><span style="color: rgb(204, 102, 204);"> if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then</span><br /><br /><span style="color: rgb(204, 102, 204);"> BASEDIR="$CATALINA_HOME"</span><br /><span style="color: rgb(204, 102, 204);"> . "$CATALINA_HOME"/bin/setclasspath.sh</span><br /><br /><span style="color: rgb(204, 102, 204);"> else</span><br /><br /><span style="color: rgb(204, 102, 204);"> echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"</span><br /><br /><span style="color: rgb(204, 102, 204);"> echo "This file is needed to run this program"</span><br /><br /><span style="color: rgb(204, 102, 204);"> exit 1</span><br /><br /><span style="color: rgb(204, 102, 204);"> fi</span><br /><br />Got the culprit. CATALINA_HOME set wrong. Should not include bin in the path of CATALINA_HOME. Should have noticed in the previous shell output.<br />Hope this would work.<br /><br />Yep. It worked. At last............<br />What a relief.<br /><br />P.S.: I was on the notion that CATALINA_HOME was not essential to include since the script sets it in the runtime. Anyway now the tomcat works even when I remove the CATALINA_HOME entry from the .bashrc.Chamithhttp://www.blogger.com/profile/01144671767943005833noreply@blogger.com0