XPath is awesome !

Web July 29th, 2006

I am really annoyed by the huge images in some linuxfans users’s signatures when surfing the forum, so I decided to hack a user script using Greasemonkey before the moderators of the forum takes any actions.

The XPath is really powerful to manipulate the HTML DOM tree. The signature image is in the the last span element with class attribute equal to postbody in the td element:

allElements = document.evaluate(
    “//td/span[@class='postbody'][last()]/img”,
    …

You can download this user script from here. Of course, you need to install Firefox and Greasemonkey first.

We are moving - Done

Web July 25th, 2006

The one-year plan on DreamHost is going to end this summer. I decided to move to a new ISP, Globat due to the one-year web hosting FAR promotion. Some features, like SSH, SVN are missing in globat.com, but what can beat free?

You may make my deal more sweet. If you signed in with my referral, I can get another one year hosting free of charge.

Globat Referral


Is Google Browser Sync Plugin a troublemaker?

Gentoo July 23rd, 2006

I just installed Google Browser Sync a few days ago, to manage my Firefox profiles across the computers, one in Gentoo, one in Windows XP(VMWare), one in Mac. Today, after the upgrade the world, the firefox failed to launch with this error message:

bookstack@tiger ~ $ firefox
No running windows found
firefox-bin exited with non-zero status (1)

Have I broken something in the upgrade? I double checked the emerge log via genlop, and found nothing relavent. Then I check the strace output:

bookstack@tiger ~/.mozilla/firefox $ strace -e stat64 firefox
… …
stat64(“/home/bookstack/.firefox/*/compreg.dat”, 0xbfefb368) = -1 ENOENT (No such file or directory)
stat64(“/home/bookstack/.firefox/*/chrome.rdf”, 0xbfefb368) = -1 ENOENT (No such file or directory)

It is quite strange that the Firefox would check $HOME/.firefox, it is supposed to check $HOME/.mozilla/firefox instead. There must be something wrong with the current profile. Here we are, the $HOME/.mozilla/firefox/profiles.ini is truncated to zero bytes! Once this is fixed, Firefox works again.

I don’t want to FUD Google Browser Sync, but it is the only relavent change about Firefox. If you have met the same problem, could you drop a comment here? I might need to dig into the source code before jumping to a conclusion.

The light of the dark side

Development July 18th, 2006

I went to the dark side in the last few days to meet the milestones. The C code is just simply a FORTRAN translation regardless the coding style. The messy code really annoys me when I decided to debug it. So I stepped aside to find a pain relief first.

Here is the light of the dark side, GNU indent, it does not refine your algorithm or logic, but polish your code to make it more readable. The indent has 3 built-in styles: K&R, GNU and BSD/KNF. None of them is my cup of tea, then I decided to hack a BSD/Allman from BSD/KNF style, like this:

-nbad -bap -bbo -nbc -bli0 -c33 -cd33 -ncdb -nce -nlp -ci3 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -ts4 -i4 -ip0 -l75 -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss

You can use the long argument above in indent, or copy it to $HOME/.indent.pro as the default indent style.

TIP: translate FORTRAN array to C

Development July 17th, 2006

I am really bored to convert the FORTRAN array decorator () to C array [], and eventually, I hacked this small script to do the tendious work:

#!/usr/bin/env python

import sys, re, string
p = re.compile( ‘([A-Z]+)\(([^\(\)]+)\) )
for line in sys.stdin:
    print string.rstrip( p.sub( r\1[\2]‘, line ))+“;”

The usage is quite simple:

bookstack@tiger ~/work/bra_par $ ./main.py  < test
              RHOil=(DX[i-1]*RHO[ij]+DX[i]*RHO[il])/(DX[i]+DX[i-1]);
              RHOil=1.0/(RHOil+TINNY);
              RHOjt=(DY[j+1]*RHO[ij]+DY[j]*RHO[jt])/(DY[j]+DY[j+1]);
              RHOjt=1.0/(RHOjt+TINNY);

Here is the trick: the array consists variable name(captilized letters), (, whatever, ). we group the variable name and whatever as group 1, 2; then replace (, ) with [, ]. A simple demostration of how powerful the regular expression is.