Java Web Start in 64-bit Linux

If you are using 64-bit linux, you might have found out that jvm 64-bit version doesn’t have a java web start. (Update: Java Web Start is added to 64-bit package since the version 6u12) I don’t know any particular reasons for this, however jnlp files seem to be very simple. The jnlp file contains an url to a jar file, which we can download and run separately. I only tried this with topcoder arena – it works without any problems. Here is a python script for handling simple java web start files.

#!/usr/bin/env python

import xml.dom.minidom
from xml.dom.minidom import Node
import os,sys

if len(sys.argv) != 2 :
	print "Usage " + sys.argv[0] + " [jnlp file]"
	sys.exit()

doc = xml.dom.minidom.parse(sys.argv[1])

jnlp = doc.getElementsByTagName("jnlp")[0]
codebase = jnlp.getAttribute("codebase")

resources = jnlp.getElementsByTagName("resources")[0]
jar = resources.getElementsByTagName("jar")[0].getAttribute("href")

application = jnlp.getElementsByTagName("application-desc")[0]
main = application.getAttribute("main-class")
arguments = application.getElementsByTagName("argument")

cmd = ""

for a in arguments :
	cmd += " " + a.firstChild.data

filename = jar.split("/")[-1]

if not jar.startswith("http:") :
	jar = codebase + jar

os.system("wget -N "+jar)

os.system("java -jar " + filename + cmd)

Tags: , , ,

Browser Wars 2.1

We all know the historical story of first browser war between Netscape and Microsoft. Microsoft ended it by crushing Netscape into pieces, for the time being. Microsoft controlled over 95% of browser market. Netscape had nothing else to do, but to back off – but they took a shoot on their way back to home : They open sourced their code.

A small group of people, also known as hackers, formed a small foundation called “mozilla” and started hacking. As a result, they released “Firefox” in 2004. That was the beginning of second browser wars. Although Firefox mainly started it, It wasn’t a two player game this time. Apple was the other player. It was not easy to fight from the scratch. So, Apple forked the KHTML rendering engine and create Webkit project and the Safari browser. This war bought the life to many amazing technologies – Web 2.0 has emerged during the war. Yet, the war is not finished yet. Firefox is catching up with the market share with it’s newest release, Firefox 3.0 forming Guinness records.

Upto this point, the war was about new features, and the memory usage of browsers. Then, in September of 2008(yes, this month), Google turned the flow – they released one of their secret projects, Chrome. Like Safari, chrome is also built on Webkit, but Google has rewritten the javascript engine from scratch. This new engine, V8 is several times faster than the current script engines used in other browsers. Eventhough, Google released Chrome first, highlighting V8 and it’s speed, other projects have been also working on their own javascript optimizations. This is the beginning of Browser Wars 2.1.

So, this weekend I did some test runs on those engines. Namely, SpiderMonkey used in Firefox 3.0, TraceMonkey used in Firefox 3.1 and SquirrelFish Extreme used in Webkit. Unfortunately, Google hasn’t released the Chrome for linux yet – so, I wasn’t’ able to run accurate tests on V8 – but I’ve used a VM just to checkout the results anyway.

There are several javascript benchmarking tools available such as Sunspider, Dromaeo, and V8 benchmarks. If you do a little search on the internet, you’ll find tons of sites with benchmarking new engines using those. So, I decided to write few simple javascript functions based on commonly used techniques and benchmark them. These tests are further away from perfect, but it’ll give a rough idea.

Following graphs show how many of times the given function can be executed within one second. Each test has been run for 10 times and the mean is taken – Bigger is better.

Note : V8 tests have been run under a VM, you should technically ignore them.

Dom Create

function dom_create() {
	for ( var i = 0; i < 100; i++) {
		var d = document.createElement('div');
		d.innerHTML = "whatevertest";
	}
}

Dom Append

I wanted to append the ul to document but firefox(both 3 and 3.1) crashed.

function dom_append() {
	for ( var i = 0; i < 100; i++) {
		var x = document.createElement('ul');
		x.appendChild(document.createElement('li'));
	}
}

Update Inner HTML

Note : only function is measured, ‘var garbage = ….’ line is only called once before starting the benchmark.

var garbage = document.getElementById('garbage');

function dom_inner_html() {
	for ( var i = 0; i < 100; i++) {
		garbage.innerHTML = "<div>this should be some large string</div>
<p>with html elements</p><ul><l>>this</li><li>is</li>
<li>a</li><li>list</li> </ul>" + i;
	}
}

Get Element by ID

function get_element() {
	for ( var i = 0; i < 1000; i++) {
		var d = document.getElementById('garbage');
	}
}

Conclusion

(Chrome is not considered in this section, you can give it the benifit of doubt and come to your own conclusions)

As you can see, SquirrelFish Extreme has got an extreme boost over almost everything, except innerHTML updates. Tracemonkey wins the innerHTML updates from unbelievable margin. Both dom based techniques and innerHTML updates are used heavily in ajax based applications. For the time beign, SquirrelFish Extreme seems to have won the overall speed race.

However, browser is not just javascript and rendering. One of the strong features of Firefox is it’s huge number of extensions and the XUL interface which makes the life easier for extension developers. When you combine that with the current market share of Firefox, Firefox will rule the web for next few years.

Script

You can get the html file I used to benchmark from here. The benchmarking functions are taken from John Resig’s benchmarking quality blog post.

Tags: , , , ,

Greasemonkey script for highlighting google results

Each individual on internet have their own browsing habits. For example, I have seen lot of people type the web address directly in the search box instead of the addressbar(If you look at the top searched queries, you can see yahoo.com, etc).

One of my browsing habits is to look for wikipedia articles. If it’s a movie, I look for imdb. So, instead of spending 1/2 seconds to go through results and analyze site address, i decided to write a simple greasemonkey script.

You can grab the script from here. If you have your own list of sites, you can simply edit the source(greasemonkey provides you a simple interface) and change the “sites” array.

Tags: , , ,

Nautilus Tabs

If you are a gnome user, you might have seen the TABs meme in gnome planet during GUADEC. Most of them are crazy mockups and if implemented totally useless(some are really funny). However, nautilus tabs is really useful and have been a long awaited feature. So today, I compiled the nautilus trunk and now I’m a happy user of nautilus tabs.

For ubuntu 8.04, I had to compile, libgnome-2.23.4, intltool-0.40, gnome-desktop-2.23.4 and eel-2.23.4 before compiling nautilus svn trunk(svn://svn.gnome.org/svn/nautilus/trunk).

Tags: ,

Live iso(distro) without burning & partitioning

“A picture is worth a thousand words” – how about a live experience? If you digg around the internet a little bit, you’ll find hundred of distros lying around. Just like the distro’s site, explains why they are unique, and provides screenshots, most of those comes with a live CD. You’ll get a nice iso image, burn it, run it, and install it if you like.

But it’s annoying to burn a CD for each distro you are going to try. One option is to use a USB drive. Unfortunately, my USB flash drive is USB1.0 but my motherboard only allows me to boot from USB2.0 devices. Another options is to copy the files into a new partition, and install grub/syslinux on that partition – but It’s not a good idea to mess around with partitions.

After experimenting a little bit with the ISOs and grub configuration, I manage to boot the distro, from the file resides in a sub directory of root.

Note : I used following commands in Ubuntu 8.10 – the file locations might be different based on your distribution.

Puppy Linux

Puppy Linux

Puppy linux is a light weighted, very small distro, yet contains most of the important applications for the daily use. In my opinion, this is a nicely designed great distro. My network card and video card worked without giving any trouble, but the sound card failed.

This distro is specially designed aiming towards portable users, who will run the distro in either a USB or a CD. Puppy linux uses squashfs compressed files to keep it’s root file system, and the init scripts are searching for these files in all hard drives, cdroms, and usb drives. So the installation is really easy.

1. Download the image, and mount it to a directory.

sudo mount -o loop puppy-linux.iso /media/cdrom

2. Create a directory in your root partition and copy the files from iso.

sudo mkdir /puppy
sudo cp -r /media/cdrom/* /puppy/

3. Modify your grub config file(/boot/grub/menu.lst) pointing to the puppy kernel and initrd file. Here is the menu entry I added, you’ll have to change the root according to your disk configuration.

title		Puppy Linux
root		(hd0,0)
kernel		/puppy/vmlinuz
initrd		/puppy/initrd.gz
quiet

That’s it – you can reboot the computer, select Puppy Linux from grub and boot.

Good OS – gOS

gOS gOS

gOS is a distribution based on ubuntu designed for web 2.0 internet users (Latest version specially aims toward myspace users). I can’t really see a practicle advantage of using gOS, despite the fact that theming and dock is superb. Other than that, it’s just firefox bookmarks on desktop(dock).

The gOS root file system is also packed in a squashfs file, but the init scripts are different. So, the installation is bit tricky.

1. Mount the gOS image.

sudo mount -o loop gos-space.iso /media/cdrom

2. Then you’ll need the squashfs file, kernel and the initrd file.

sudo mkdir /gos
sudo cp /media/cdrom/casper/filesystem.squashfs /gos
sudo cp /media/cdrom/casper/vmlinuz /gos
sudo cp /media/cdrom/casper/initrd.gz /gos

(Note : You can also extract the squashfs file and make the process simpler, but that’ll require much more free space.)

3. When we do changes in the OS, we need those to be persistence. So, I choose to save changes on a file. Following commands will create a 500MB file, and format it as a ext3 drive.

sudo dd if=/dev/zero bs=1048576 count=500 of=/gos/filesystem.ext3
sudo mkfs.ext3 /gos/filesystem.ext3

4. Now we need to configure the init scripts to use our files for root file system. So, first extract the initrd file.

cd /tmp
cp /gos/initrd.gz ./
gunzip initrd.gz
mkdir content; cd content
cpio -i < ../initrd

Now you have the initramfs on /tmp/content

5. We need loop, squashfs, and unionfs drivers. Edit the "conf/modules" file and append following.

squashfs
loop
unionfs

6. The default init script will get the "root" kernel parameter and mount it as "/root" in initramfs. We need a script to remount our files. Create a file called gos in scripts/init-bottom and paste the following content. (gedit scripts/init-bottom/gos)

#!/bin/sh -e
# initramfs premount script for gos

PREREQ=""

# Output pre-requisites
prereqs()
{
	echo "$PREREQ"
}

case "$1" in
    prereqs)
	prereqs
	exit 0
	;;
esac

mkdir /realroot
mount --move ${rootmnt} /realroot
mkdir /sqroot
mount -o loop /realroot/gos/filesystem.squashfs /sqroot
mkdir /extroot
mount -o loop /realroot/gos/filesystem.ext3 /extroot
mount -t unionfs -o dirs=/extroot:/sqroot none ${rootmnt}

Make the file executable.

chmod a+x scripts/init-bottom/gos

7. Create a new initrd file, and replace the old file.

cd /tmp/content
find . | cpio --quiet --dereference -o -H newc | gzip > ../initrd.gz
cp /tmp/initrd.gz /gos/initrd.gz

8. Edit your grub config file(/boot/grub/menu.lst) to boot from it. You'll need to change the devices according to your disk configuration.

title		gOS
root		(hd0,0)
kernel		/gos/vmlinuz root=/dev/sda1 rw quiet single
initrd		/gos/initrd.gz
quiet

First time we have to boot in the single user mode and configure the system.

9. Before rebooting, we need to create a fstab. To do that, we have to mount our ext3 filesystem.

mkdir /tmp/gos
sudo mount -o loop /gos/filesystem.ext3 /tmp/gos
sudo mkdir /tmp/gos/etc

10. Copy the following content into /tmp/etc/fstab. (/dev/sda5 should be your swap partition - check your /etc/fstab)

unionfs	/	unionfs rw 0 0
tmpfs	/tmp tmpfs nosuid,nodev 0 0
/dev/sda5	none            swap    sw              0       0

11. Now reboot your computer and select "gOS" from grub. It'll boot into single user mode(called maintenance mode in ubuntu). Once you get into shell, create a user, and configure your X. There are two nice wizards, you can just follow those.

user-setup
dpkg-reconfigure xserver-xorg

12. Reboot back to your main OS and edit the grub - simply remove the "single" parameter. (You can also mount the root partition within the gOS single user mode, and change grub)

title		gOS
root		(hd0,0)
kernel		/gos/vmlinuz root=/dev/sda1 rw quiet
initrd		/gos/initrd.gz
quiet

Now, reboot and enjoy. This process is obviously bit long, and not perfect. So, if you are going to keep using that distro, I recommend you install it on a separate partition.

Tags: , , ,

Get Adobe Flash playerPlugin by wpburn.com wordpress themes