Wednesday, December 27, 2006

A Java Program in Unicode

Here is one of my favourite Java programs - written entirely in Unicode. Who says you need to declare a class or even have any Java keywords?!


Save as, compile and run!

Monday, December 18, 2006

Program Without Class Keyword

Here is how you can write a standalone Java program WITHOUT a class keyword:

enum E{
System.out.println("Hello World");

Here is how you can write a standalone Java program WITHOUT a main method:

class Hello{
System.out.println("Hello World");

To avoid the "Could not find main method" exception, the System.exit(0); statement is used which terminates the program after printing out Hello World.

Update (1/1/2013): These examples work on older versions of Java but not on Java 6 and above.

Wednesday, December 06, 2006

Linux - CPU, Memory and Version

Find out which version of SuSE you are running:
more /etc/SuSE-release

SUSE LINUX Enterprise Server 9 (i586)

Find out how much Memory you have:
more /proc/meminfo

MemTotal: 8141344 kB
MemFree: 1983696 kB
Buffers: 74736 kB
Cached: 258836 kB
SwapCached: 2581836 kB
Active: 5485116 kB
Inactive: 444240 kB
HighTotal: 7299036 kB
HighFree: 1408888 kB
LowTotal: 842308 kB
LowFree: 574808 kB
SwapTotal: 9437144 kB
SwapFree: 5436028 kB
Dirty: 244 kB
Writeback: 0 kB
Mapped: 5571044 kB
Slab: 75912 kB
Committed_AS: 5085896 kB
PageTables: 28032 kB
VmallocTotal: 112632 kB
VmallocUsed: 9720 kB
VmallocChunk: 102640 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 2048 kB

Find out how much processor power you have:

I have a dual core 2.2 GHz machine.
more /proc/cpuinfo

processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4325.37

processor : 1
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4325.37

processor : 2
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4407.29

processor : 3
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4390.91

I am Perl

You are Perl. People have a hard time understanding you, but you are always able to help them with almost all of their problems.
Which Programming Language are You?

Tuesday, November 21, 2006

I am .ppt?

I came across an unusual personality test on Digg today. I don't normally do them, in fact I hate them, but I just HAD to find out what file extension I would turn out be! I have to say, the results are pretty accurate.

You are .ppt  You present yourself well, but co-workers still find you bording and annoying.  Keep it brief and you'll be well-liked.
Which File Extension are You?

Friday, November 17, 2006

What to Eat in Singapore

The people of Singapore have two simple pleasures: Shopping and Eating. Everywhere you go you will see numerous eating places. Each and every shopping mall has its own food court which is made up of lots of different food stalls selling everything from chinese and malaysian food to indian food.

When in Singapore, you must try the following:

The durian is a thorny fruit native to south-east asia. It is unlike any you've ever eaten. It tastes a bit like custard and has quite an unpleasant smell, which is why it is banned on all public transport! Try it - you'll either love it or hate it!

Singapore Chilli Crab
This is Singapore's unofficial "national dish". Don't be afraid to use your teeth or the pliers supplied to crack open the shell and eat the crab meat. Served with fried bread.

Fish Head Curry
This is one of the local delicacies and is basically a fish head, complete with eyeballs, in curry! It is quite spicy. Don't forget to try the eyeballs. They are the best bit ;)

Other things to try are:
  • chicken rice
  • fish ball noodles
  • nasi lemak (malaysian coconut rice with egg and dried fish)
  • duck
  • laksa (noodles in curry)
  • lime juice
  • multi-coloured ice-cream sandwich

Related Posts
You may also be interested in reading the following related entries:
Places to Visit in Singapore
Places to Visit in Singapore - II

Places to Visit in Singapore - II

Orchard Road
Singapore's central, vibrant shopping area. During my stay, the Great Singapore Shopping Sale was in full swing and the streets and shops were absolutely packed with people! Great for shoppers!

Little India
Little India is the focal point of Singapore's Indian community and is packed with small Indian shops selling everything from jewellery to saris and biryani. There are also some famous temples which are worth seeing (Sri Veeramakaliamman Temple, pictured below).

Mustafa Centre
This 24-hour six-storey shopping centre stocks everything from Indian chutney and diamonds to plasma TVs and cars, all at very reasonable prices. This is where I did most of my shopping. Don't forget to have your bags checked before you enter!

Sultan Mosque at Arab Street
With its massive golden dome and huge prayer hall, the Sultan Mosque is one of Singapore's most imposing religious buildings, and the focal point of Muslims in Singapore. You can also try Muslim food and buy Arab goods along this street.

There are lots of stalls selling Chinese bits and bobs. This is where I bought my hand drum (which you see used in Karate Kid II). Also check out Chinatown Heritage Centre and some Chinese Temples. Pictured below are Thian Hock Keng Temple and Trengganu Street.

Funan Digitalife Mall
Funan Digitalife Mall, Asia's leading IT shopping mall, is the one-stop haven that offers the latest, most innovative, and widest range of genuine and value-for-money IT and electronic gadgets. You can also try some really good Black Pepper Beef in the food court.

Sim Lim Square
Another place where you can pick up dirt cheap electronic gadgets. This is where I bought my iPod!

Related Posts
You may also be interested in reading the following related entries:
Places to Visit in Singapore
What to Eat in Singapore

Places to Visit in Singapore

I was in Singapore on a business trip from the 10th - 30th of June and stayed at the magnificent Ritz-Carlton Millenia Singapore. I got a deluxe room (room number 1417) with a picturesque view of the city. The room was fully furnished with two single beds, a large LCD TV and mini-bar and cost me SGD500 per night.

Here is a list on interesting places that you must visit when in Singapore:

The Esplanade
Esplanade – Theatres on the Bay is one of Singapore's architectural icons with its distinctive twin shells. It is sited just by Marina Bay at the mouth of the Singapore River.

Merlion Park
The Merlion, the lion head with a fish body resting on a crest of waves, is the emblem of Singapore. Unluckily, it was being renovated while I was there, so I wasn't able to see it in its full glory!

Fountain of Wealth at Suntec City
I used to go to work everyday at Suntec City's Tower 5. During our lunch break, we would roam around Suntec City Mall.

Suntec City is designed with a lot of emphasis on Chinese geomancy (feng shui). The five buildings and the convention center are arranged so that they look like a left hand when viewed aerially, and the Fountain of Wealth look like a golden ring in the palm of the hand. As the fountain is made of bronze, it is believed that the balance of metal and water paves the way for success. This fountain is the largest in the world!

Statue of Sir Stamford Raffles
Sir Stamford Raffles – Singapore’s founder – stands tall and proud in the form of a dark bronze statue in front of Victoria Theatre.

Parliament House

Related Posts
You may also be interested in reading the following related entries:
Places to Visit in Singapore - II
What to Eat in Singapore

Thursday, November 16, 2006

Bug in iTunes 7.0

iTunes 7 is flawed. Importing music CDs into your iTunes library is extremely slow - it takes hours to import a CD whereas it only used to take at most half an hour on the old version.

I have uninstalled version 7.0.1 and gone back to version 6.0.5. However my "iTunes Library.itl" file was no longer compatible with the old version, so I had to delete it and rebuild my library again!

I'm not upgrading until Apple have fixed this issue...

Yahoo! Answers is Fun

I've always enjoyed problem solving and have actively participated in online forums such as Sun's Java Developer Forums, Java Ranch and Google Groups. They allow you to expand your knowledge, share what you know with the online community and even help you establish yourself as a bit of a guru (if you're really good!).

I especially like Sun's Forums because they allow you to earn Duke Dollars based on how good your answers are. (I am currently worth 139 duke dollars!)

Recently, I stumbled across Yahoo! Answers which is a place to ask questions and get real answers from real people. It’s fun and educational because you can ask questions on any topic—from the serious to the not so serious. And when you know what's up, you get to help people out by answering their questions. You earn 2 points for answering a question and 10 if your answer is selected as the best answer! This has really got me hooked. I mostly answer the Mathematics and Computing questions but I also like taking part in the more general categories like Society and Culture.

Here is my little answers badge which shows all my questions and answers:

Tuesday, November 07, 2006

My Bash Profile

Bash is my favourite shell and here is my .bashrc which has grown substantially over the years as I have added (and will continue to add) more and more useful aliases and functions. These are very useful because they save time and also stop you from having to type in long error-prone commands.

My personal favourite alias is ll='ls -ltr' and I don't understand why some people still type in the long form for such a common command.



set -o notify
set -o braceexpand
set -o emacs




shopt -s extglob progcomp cdspell

# Make directory commands see only directories
complete -d cd mkdir rmdir pushd jd

# Make file commands see only files
complete -f cat less more chown ln strip nedit emacs

complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi)' unzip zipinfo
complete -f -X '*.Z' compress
complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
complete -f -X '!*.Z' uncompress
complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display
complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv
complete -f -X '!*.@(ps|PS)' gv ggv
complete -f -X '!*.@(ps|PS|pdf|PDF)' fmerge
complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype
complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
complete -f -X '!*.texi*' makeinfo texi2html
complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
complete -f -X '!*.fig' xfig
complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx appletviewer hotjava
complete -f -X '!*.tar' tar
complete -f -X '!*.java' javac
complete -f -X '!*.idl' idl idlj

# user commands see only users
complete -u su usermod userdel passwd write groups w talk

# bg completes with stopped jobs
complete -A stopped -P '%' bg

# other job commands
complete -j -P '%' fg jobs disown

# readonly and unset complete with shell variables
complete -v readonly unset

# set completes with set options
complete -A setopt set

# shopt completes with shopt options
complete -A shopt shopt

# unalias completes with aliases
complete -a unalias

# type and which complete on commands
complete -c command type which

# complete hostnames
complete -A hostname ssh telnet rlogin ftp ping traceroute


alias ..=cd ..
alias ...=cd ../..
alias ....=cd ../../..
alias .....=cd ../../../..

alias cl=clear
alias cla=clear;la
alias cll=clear;ll
alias cls=clear;ls
alias clal=clear;lal

alias rmdir=rm -rf

alias d=date
alias ff=find . -name $1
alias h=history

alias l=ls
alias la=ls -a
alias ll=ls -ltr
alias lal=ls -al
alias ls=ls -F
alias sl=ls

alias more=less
alias mroe=more
alias m=more

alias r=fc -s
alias igrep=grep -i


#kill a process by name
if [ -z $1 ]; then
echo -e \e[0;31;1mUsage: pskill [processName]\e[m;
ps -au $USER | grep -i $1 |awk {print kill -9 $1}|sh

#jump to a directory
if [ -z $1 ]; then
echo -e \e[0;31;1mUsage: jd [directory]\e[m;
findresults=( $(find . -type d -name $1) )
if [ $count = 1 ]; then
cd $file
if [ $count = 0 ]; then
echo No such directory
else echo Ambiguous: $count directories found
unset findresults
unset count

#display directory tree structure
echo -e \033[1;35m

(cd ${1-.} ; pwd)
find ${1-.} -print | sort -f | sed \
-e s,^${1-.},, \
-e /^$/d \
-e s,[^/]*/\([^/]*\)$,\ |-->\1, \
-e s,[^/]*/, | ,g

echo -e \033[0m

#mkdir and cd combined
if [ -z $1 ]; then
echo -e \e[0;31;1mUsage: mkcd [directory]\e[m;
if [ -d $1 ]; then
echo Changed to $1.;
cd $1;
mkdir $1;
echo Created $1;
cd $1;

# END #

mesg -n
echo -e \e[0;31;1m$USER logged in to `tty` on `date`\e[m

Sunday, October 29, 2006

Memory Leak in Windows Live Messenger 8.0

Yesterday, I thought I'd try out the new Live Messenger. It comes with some great new features such as offline messaging (as in Yahoo! Messenger) and also allows you to add and communicate with Yahoo! contacts.

The first thing I noticed was how slow it is. I decided to check its memory and CPU usage and so brought up the Task Manager. Here is what I saw:

Fig 1. Task Manager showing Windows Live Messenger 8.0

Live Messenger is using 95% CPU, but more shocking is the fact that it is using a whopping 210 Megs of RAM!

I have now uninstalled it and have reverted back to MSN Messenger 7.5. Just for comparison, here is a screenshot of my Task Manager now, which looks much better:

Fig 2. Task Manager showing MSN Messenger 7.5

Needless to say, I'm going to be sticking to 7.5 till Microsoft fixes this leak.

Thursday, October 19, 2006

Imagine Earth Without People

[From issue 2573 of New Scientist magazine, 12 October 2006, page 36-41]

Humans are undoubtedly the most dominant species the Earth has ever known. In just a few thousand years we have swallowed up more than a third of the planet's land for our cities, farmland and pastures. By some estimates, we now commandeer 40 per cent of all its productivity. And we're leaving quite a mess behind: ploughed-up prairies, razed forests, drained aquifers, nuclear waste, chemical pollution, invasive species, mass extinctions and now the looming spectre of climate change. If they could, the other species we share Earth with would surely vote us off the planet.

Now just suppose they got their wish. Imagine that all the people on Earth - all 6.5 billion of us and counting - could be spirited away tomorrow, transported to a re-education camp in a far-off galaxy. (Let's not invoke the mother of all plagues to wipe us out, if only to avoid complications from all the corpses). Left once more to its own devices, Nature would begin to reclaim the planet, as fields and pastures reverted to prairies and forest, the air and water cleansed themselves of pollutants, and roads and cities crumbled back to dust.

"The sad truth is, once the humans get out of the picture, the outlook starts to get a lot better," says John Orrock, a conservation biologist at the National Center for Ecological Analysis and Synthesis in Santa Barbara, California. But would the footprint of humanity ever fade away completely, or have we so altered the Earth that even a million years from now a visitor would know that an industrial society once ruled the planet?

If tomorrow dawns without humans, even from orbit the change will be evident almost immediately, as the blaze of artificial light that brightens the night begins to wink out. Indeed, there are few better ways to grasp just how utterly we dominate the surface of the Earth than to look at the distribution of artificial illumination (see Graphic). By some estimates, 85 per cent of the night sky above the European Union is light-polluted; in the US it is 62 per cent and in Japan 98.5 per cent. In some countries, including Germany, Austria, Belgium and the Netherlands, there is no longer any night sky untainted by light pollution.

"Pretty quickly - 24, maybe 48 hours - you'd start to see blackouts because of the lack of fuel added to power stations," says Gordon Masterton, president of the UK's Institution of Civil Engineers in London. Renewable sources such as wind turbines and solar will keep a few automatic lights burning, but lack of maintenance of the distribution grid will scuttle these in weeks or months. The loss of electricity will also quickly silence water pumps, sewage treatment plants and all the other machinery of modern society.

The same lack of maintenance will spell an early demise for buildings, roads, bridges and other structures. Though modern buildings are typically engineered to last 60 years, bridges 120 years and dams 250, these lifespans assume someone will keep them clean, fix minor leaks and correct problems with foundations. Without people to do these seemingly minor chores, things go downhill quickly.

The best illustration of this is the city of Pripyat near Chernobyl in Ukraine, which was abandoned after the nuclear disaster 20 years ago and remains deserted. "From a distance, you would still believe that Pripyat is a living city, but the buildings are slowly decaying," says Ronald Chesser, an environmental biologist at Texas Tech University in Lubbock who has worked extensively in the exclusion zone around Chernobyl. "The most pervasive thing you see are plants whose root systems get into the concrete and behind the bricks and into doorframes and so forth, and are rapidly breaking up the structure. You wouldn't think, as you walk around your house every day, that we have a big impact on keeping that from happening, but clearly we do. It's really sobering to see how the plant community invades every nook and cranny of a city."

With no one to make repairs, every storm, flood and frosty night gnaws away at abandoned buildings, and within a few decades roofs will begin to fall in and buildings collapse. This has already begun to happen in Pripyat. Wood-framed houses and other smaller structures, which are built to laxer standards, will be the first to go. Next down may be the glassy, soaring structures that tend to win acclaim these days. "The elegant suspension bridges, the lightweight forms, these are the kinds of structures that would be more vulnerable," says Masterton. "There's less reserve of strength built into the design, unlike solid masonry buildings and those using arches and vaults."

But even though buildings will crumble, their ruins - especially those made of stone or concrete - are likely to last thousands of years. "We still have records of civilisations that are 3000 years old," notes Masterton. "For many thousands of years there would still be some signs of the civilisations that we created. It's going to take a long time for a concrete road to disappear. It might be severely crumbling in many places, but it'll take a long time to become invisible."

The lack of maintenance will have especially dramatic effects at the 430 or so nuclear power plants now operating worldwide. Nuclear waste already consigned to long-term storage in air-cooled metal and concrete casks should be fine, since the containers are designed to survive thousands of years of neglect, by which time their radioactivity - mostly in the form of caesium-137 and strontium-90 - will have dropped a thousandfold, says Rodney Ewing, a geologist at the University of Michigan who specialises in radioactive waste management. Active reactors will not fare so well. As cooling water evaporates or leaks away, reactor cores are likely to catch fire or melt down, releasing large amounts of radiation. The effects of such releases, however, may be less dire than most people suppose.

The area around Chernobyl has revealed just how fast nature can bounce back. "I really expected to see a nuclear desert there," says Chesser. "I was quite surprised. When you enter into the exclusion zone, it's a very thriving ecosystem."

The first few years after people evacuated the zone, rats and house mice flourished, and packs of feral dogs roamed the area despite efforts to exterminate them. But the heyday of these vermin proved to be short-lived, and already the native fauna has begun to take over. Wild boar are 10 to 15 times as common within the Chernobyl exclusion zone as outside it, and big predators are making a spectacular comeback. "I've never seen a wolf in the Ukraine outside the exclusion zone. I've seen many of them inside," says Chesser.

The same should be true for most other ecosystems once people disappear, though recovery rates will vary. Warmer, moister regions, where ecosystem processes tend to run more quickly in any case, will bounce back more quickly than cooler, more arid ones. Not surprisingly, areas still rich in native species will recover faster than more severely altered systems. In the boreal forests of northern Alberta, Canada, for example, human impact mostly consists of access roads, pipelines, andother narrow strips cut through the forest. In the absence of human activity, the forest will close over 80 per cent of these within 50 years, and all but 5 per cent within 200, according to simulations by Brad Stelfox, an independent land-use ecologist based in Bragg Creek, Alberta.

In contrast, places where native forests have been replaced by plantations of a single tree species may take several generations of trees - several centuries - to work their way back to a natural state. The vast expanses of rice, wheat and maize that cover the world's grain belts may also take quite some time to revert to mostly native species.

At the extreme, some ecosystems may never return to the way they were before humans interfered, because they have become locked into a new "stable state" that resists returning to the original. In Hawaii, for example, introduced grasses now generate frequent wildfires that would prevent native forests from re-establishing themselves even if given free rein, says David Wilcove, a conservation biologist at Princeton University.

Feral descendants of domestic animals and plants, too, are likely to become permanent additions in many ecosystems, just as wild horses and feral pigs already have in some places. Highly domesticated species such as cattle, dogs and wheat, the products of centuries of artificial selection and inbreeding, will probably evolve back towards hardier, less specialised forms through random breeding. "If man disappears tomorrow, do you expect to see herds of poodles roaming the plains?" asks Chesser. Almost certainly not - but hardy mongrels will probably do just fine. Even cattle and other livestock, bred for meat or milk rather than hardiness, are likely to persist, though in much fewer numbers than today.

What about genetically modified crops? In August, Jay Reichman and colleagues at the US Environmental Protection Agency's labs in Corvallis, Oregon, reported that a GM version of a perennial called creeping bentgrass had established itself in the wild after escaping from an experimental plot in Oregon. Like most GM crops, however, the bentgrass is engineered to be resistant to a pesticide, which comes at a metabolic cost to the organism, so in the absence of spraying it will be at a disadvantage and will probably die out too.

Nor will our absence mean a reprieve for every species teetering on the brink of extinction. Biologists estimate that habitat loss is pivotal in about 85 per cent of cases where US species become endangered, so most such species will benefit once habitats begin to rebound. However, species in the direst straits may have already passed some critical threshold below which they lack the genetic diversity or the ecological critical mass they need to recover. These "dead species walking" - cheetahs and California condors, for example - are likely to slip away regardless.

Other causes of species becoming endangered may be harder to reverse than habitat loss. For example, about half of all endangered species are in trouble at least partly because of predation or competition from invasive introduced species. Some of these introduced species - house sparrows, for example, which are native to Eurasia but now dominate many cities in North America - will dwindle away once the gardens and bird feeders of suburban civilisation vanish. Others though, such as rabbits in Australia and cheat grass in the American west, do not need human help and will likely be around for the long haul and continue to edge out imperilled native species.

Ironically, a few endangered species - those charismatic enough to have attracted serious help from conservationists - will actually fare worse with people no longer around to protect them. Kirtland's warbler - one of the rarest birds in North America, once down to just a few hundred birds - suffers not only because of habitat loss near its Great Lakes breeding grounds but also thanks to brown-headed cowbirds, which lay their eggs in the warblers' nests and trick them into raising cowbird chicks instead of their own. Thanks to an aggressive programme to trap cowbirds, warbler numbers have rebounded, but once people disappear, the warblers could be in trouble, says Wilcove.

On the whole, though, a humanless Earth will likely be a safer place for threatened biodiversity. "I would expect the number of species that benefit to significantly exceed the number that suffer, at least globally," Wilcove says.

In the oceans, too, fish populations will gradually recover from drastic overfishing. The last time fishing more or less stopped - during the second world war, when few fishing vessels ventured far from port - cod populations in the North Sea skyrocketed. Today, however, populations of cod and other economically important fish have slumped much further than they did in the 1930s, and recovery may take significantly longer than five or so years.

The problem is that there are now so few cod and other large predatory fish that they can no longer keep populations of smaller fish such as gurnards in check. Instead, the smaller fish turn the tables and outcompete or eat tiny juvenile cod, thus keeping their erstwhile predators in check. The problem will only get worse in the first few years after fishing ceases, as populations of smaller, faster-breeding fish flourish like weeds in an abandoned field. Eventually, though, in the absence of fishing, enough large predators will reach maturity to restore the normal balance. Such a transition might take anywhere from a few years to a few decades, says Daniel Pauly, a fisheries biologist at the University of British Columbia in Vancouver.

With trawlers no longer churning up nutrients from the ocean floor, near-shore ecosystems will return to a relatively nutrient-poor state. This will be most apparent as a drop in the frequency of harmful algal blooms such as the red tides that often plague coastal areas today. Meanwhile, the tall, graceful corals and other bottom-dwelling organisms on deep-water reefs will gradually begin to regrow, restoring complex three-dimensional structure to ocean-floor habitats that are now largely flattened, featureless wastelands.

Long before any of this, however - in fact, the instant humans vanish from the Earth - pollutants will cease spewing from automobile tailpipes and the smokestacks and waste outlets of our factories. What happens next will depend on the chemistry of each particular pollutant. A few, such as oxides of nitrogen and sulphur and ozone (the ground-level pollutant, not the protective layer high in the stratosphere), will wash out of the atmosphere in a matter of a few weeks. Others, such as chlorofluorocarbons, dioxins and the pesticide DDT, take longer to break down. Some will last a few decades.

The excess nitrates and phosphates that can turn lakes and rivers into algae-choked soups will also clear away within a few decades, at least for surface waters. A little excess nitrate may persist for much longer within groundwater, where it is less subject to microbial conversion into atmospheric nitrogen. "Groundwater is the long-term memory in the system," says Kenneth Potter, a hydrologist at the University of Wisconsin at Madison.

Carbon dioxide, the biggest worry in today's world because of its leading role in global warming, will have a more complex fate. Most of the CO2 emitted from burning fossil fuels is eventually absorbed into the ocean. This happens relatively quickly for surface waters - just a few decades - but the ocean depths will take about a thousand years to soak up their full share. Even when that equilibrium has been reached, though, about 15 per cent of the CO2 from burning fossil fuels will remain in the atmosphere, leaving its concentration at about 300 parts per million compared with pre-industrial levels of 280 ppm. "There will be CO2 left in the atmosphere, continuing to influence the climate, more than 1000 years after humans stop emitting it," says Susan Solomon, an atmospheric chemist with the US National Oceanic and Atmospheric Administration (NOAA) in Boulder, Colorado. Eventually calcium ions released from sea-bottom sediments will allow the sea to mop up the remaining excess over the next 20, 000 years or so.

Even if CO2 emissions stop tomorrow, though, global warming will continue for another century, boosting average temperatures by a further few tenths of a degree. Atmospheric scientists call this "committed warming", and it happens because the oceans take so long to warm up compared with the atmosphere. In essence, the oceans are acting as a giant air conditioner, keeping the atmosphere cooler than it would otherwise be for the present level of CO2. Most policy-makers fail to take this committed warming into account, says Gerald Meehl, a climate modeller at the National Center for Atmospheric Research, also in Boulder. "They think if it gets bad enough we'll just put the brakes on, but we can't just stop and expect everything to be OK, because we're already committed to this warming."

That extra warming we have already ordered lends some uncertainty to the fate of another important greenhouse gas, methane, which produces about 20 per cent of our current global warming. Methane's chemical lifetime in the atmosphere is only about 10 years, so its concentration could rapidly return to pre-industrial levels if emissions cease. The wild card, though, is that there are massive reserves of methane in the form of methane hydrates on the sea floor and frozen into permafrost. Further temperature rises may destabilize these reserves and dump much of the methane into the atmosphere. "We may stop emitting methane ourselves, but we may already have triggered climate change to the point where methane may be released through other processes that we have no control over," says Pieter Tans, an atmospheric scientist at NOAA in Boulder.

No one knows how close the Earth is to that threshold. "We don't notice it yet in our global measurement network, but there is local evidence that there is some destabilization going on of permafrost soils, and methane is being released," says Tans. Solomon, on the other hand, sees little evidence that a sharp global threshold is near.

All things considered, it will only take a few tens of thousands of years at most before almost every trace of our present dominance has vanished completely. Alien visitors coming to Earth 100,000 years hence will find no obvious signs that an advanced civilization ever lived here.

Yet if the aliens had good enough scientific tools they could still find a few hints of our presence. For a start, the fossil record would show a mass extinction centered on the present day, including the sudden disappearance of large mammals across North America at the end of the last ice age. A little digging might also turn up intriguing signs of a long-lost intelligent civilization, such as dense concentrations of skeletons of a large bipedal ape, clearly deliberately buried, some with gold teeth or grave goods such as jewellery.

And if the visitors chanced across one of today's landfills, they might still find fragments of glass and plastic - and maybe even paper - to bear witness to our presence. "I would virtually guarantee that there would be some," says William Rathje, an archaeologist at Stanford University in California who has excavated many landfills. "The preservation of things is really pretty amazing. We think of artifacts as being so impermanent, but in certain cases things are going to last a long time."

Ocean sediment cores will show a brief period during which massive amounts of heavy metals such as mercury were deposited, a relic of our fleeting industrial society. The same sediment band will also show a concentration of radioactive isotopes left by reactor meltdowns after our disappearance. The atmosphere will bear traces of a few gases that don't occur in nature, especially perfluorocarbons such as CF4, which have a half-life of tens of thousands of years. Finally a brief, century-long pulse of radio waves will forever radiate out across the galaxy and beyond, proof - for anything that cares and is able to listen - that we once had something to say and a way to say it.

But these will be flimsy souvenirs, almost pathetic reminders of a civilization that once thought itself the pinnacle of achievement. Within a few million years, erosion and possibly another ice age or two will have obliterated most of even these faint traces. If another intelligent species ever evolves on the Earth - and that is by no means certain, given how long life flourished before we came along - it may well have no inkling that we were ever here save for a few peculiar fossils and ossified relics. The humbling - and perversely comforting - reality is that the Earth will forget us remarkably quickly.

[From issue 2573 of New Scientist magazine, 12 October 2006, page 36-41]

Saturday, September 23, 2006

A Day in Ramadan

Today is the first day of Ramadan and I wish all the Muslims over the world a happy and blessed month of fasting and prayer. Ramadan Mubarak!

I thought I'd write a bit about this month and its importance.


Ramadan is the holiest month of the Islamic lunar calendar. It is the month in which Allah revealed the first verse of the Holy Quran to the Prophet Muhammad, peace be upon him (pbuh) (on Laylat al-Qadr or the "Night of Power").

Fasting is the 3rd pillar of Islam and the Quran says:

"O you who believe! Fasting is prescribed to you as it was prescribed to those before you so that you can learn Taqwa" (Quran 2:183)

The Arabic word Taqwa is translated in many ways including God consciousness, God fearing, piety and self restraining. Thus we are asked to fast daily for one month from dawn to dusk and avoid food, water, sex and vulgar talk during that period.

Benefits of Fasting

Fasting is intended to help teach us self-discipline, self-restraint and generosity. It also reminds us of the suffering of the poor, who may rarely get to eat well. But most importantly, it brings us closer to Allah. We show Allah how much we love Him by giving up food - something which is essential for our survival. If I feel hungry, I can't just grab a chocolate bar because I know that Allah is watching my every action and non-action (thoughts). Therefore, it brings us closer to our Creator. During this month, we are supposed to remember Allah more; by reading the Quran and praying extended night prayers (Tarawih). It gives us a chance to ponder over the meaning of life and that we are in this world only to please Allah.

It has been proved that fasting also has various medical benefits in that it helps lower blood sugar, cholesterol and blood pressure. There are psychological effects of fasting as well. There is a peace and tranquility for those who fast during the month of Ramadan. Personal hostility is at a minimum and the crime rate decreases.

What do I do during Ramadan?

I wake up before Fajr (dawn), say around 4.30am and have my Sehri, which is a light meal taken in the mornings. This is Sunnah (an action of the Prophet) and I normally have a bowl of cereal and toast/paratha. Even if you aren't hungry, its still good to eat something e.g. dates.

After Sehri, you have to make your Niyyah (intention for fasting) which is simply:

"I intend to keep tomorrow's fast of Ramadan"

Now you are officially fasting and so have to abstain from eating, drinking, smoking, sex and other bad vices such as backbiting, lying, quarrelling and fighting till Maghrib (sunset). I then say my Fajr prayers and go to sleep for a bit, before waking up for work.

Work is pretty much a normal day. The only difference being that I try to think about my actions and Allah a lot more. I abstain from anything that will break my fast such as swearing, backbiting and vulgar thoughts. I always find that fasting at work is a lot easier because when you're busy doing something you don't tend to think about food much!

I have also downloaded a copy of the Quran onto my iPod and listen to it on my way to work or when I'm coming back home. I scoured the internet for one with an english translation to accompany the Arabic but couldn't find one. If you have any ideas, please let me know!

Maghrib (sunset) is the time when we break our fast. This is around 6.45pm these days, which means the fast lasts for about 14 hours. We first say a short prayer which goes like this:

"O Allah, I have fasted for You, believed in You, relied on You and have broken my fast with Your provision, so accept it from me."

We then have our Iftar, which is a small meal to break the fast. It is Sunnah to start eating with a date. I have my Iftar at work or on the bus during weekdays with a sandwich or crisps but on weekends it is at home and my Mum usually makes pakoras, samosas, fruit mix etc. This is definitely my favourite part of the fast! It feels amazing putting that first morsel of food into your mouth - both physically and spiritually. It makes you happy because you've been doing good deeds and thinking about Allah throughout the day and your fast culminates with the Iftar.

After Iftar, it is time for Maghrib prayers and then Isha prayers. In this month, we also have additional night prayers called Tarawih from 9pm to 10.30pm every day. During Tarawih, the Imam recites the Quran and aims to finish the entire Quran by the 27th day of Ramadan. I try to go to the mosque and pray behind the Imam. It is hard work, praying for nearly 2 hours but once again, the feeling I get when I'm walking back home from the mosque is amazing.

At the end of the month, it is Eid - a day of celebration!

Sunday, September 03, 2006

Shadow of the Colossus

This is by far the best PS2 game I have ever played! It is not like your average game in which you go around driving cars, beating people up or shooting aliens. Shadow of the Colossus is unique. The plot is simple, yet engrossing. The graphics amazing. I've never been hooked to any game as much as this. In fact I got so emotionally involved in the game that I used to look forward to coming home from work to continue the adventure and hunt down the next colossus!

Let me tell you about the game. You play the part of a young man called Wander whose mission is to seek and destroy 16 colossi that inhabit the forbidden lands, in order to revive the body of a dead girl. Wander only has his faithful horse Agro as his companion and is armed with only a sword and bow. At first you might think that the game would get boring and repetitive after you've fought the first few colossi but thats where you're wrong! The game just keeps getting better and better. Each colossus is different and you have to use your skill, wits and environment to figure out what strategy to use to defeat it. There are big ones, small ones, flying ones, swimming ones, burrowing ones...

I loved the game's graphics. The terrain is magnificent and so are the colossi. Details are so fine that you can see individual hairs on a colossus blowing in the wind, and the colossi’s movements are so graceful that while clinging to one of the creatures you feel as if you are moving yourself!

Its really hard to choose my favourite colossus. I found the 16th one the most challenging because you have to use everything you've learnt from the previous wars in order to kill it. I also liked fighting the one in the desert, in which you have to use your horse riding skills to get close enough and then leap off onto its wings! And then there was the small but fast dog-like colossus which you have to send crashing off a cliff using a torch.

On the whole, Shadow of the Colossus is a fantastic adventure. I felt so sad when it was all over and there were no more to fight. If you haven't played this game, go out and get it!

Monday, August 28, 2006

Why Choose Windows?

  • Choose Bill Gates as your Dark Lord.
  • Choose service packs every three months to fix the 800 bugs introduced in the last one.
  • Choose an assload of obscure shovelware apps and shitty games and an Office suite that needs 18 gigs to write a letter.
  • Choose selling your soul to piracy.
  • Choose cheap ass parts from Korea.
  • Choose Winamp skins that look like snot.
  • Choose the blue screen of death.
  • Choose hordes of 133t skript kiddiez clogging the internet with their shit.
  • Choose running Norton and ZoneAlarm constantly to fight off the newest viruses.
  • Choose using letters for drives while wondering where the hell B:\ went.
  • Choose Steve Balmer jumping across the stage like a gorilla in heat.
  • Choose a damn crapshoot every time you install a program or add a peripheral.
  • Choose Microsoft squashing competitors and finding new ways to take over the world.
  • Choose sitting on your fat ass, mocking Linux users in chatrooms and forums, drowning in your own bile about Intel and AMD who think stealing from others is "innovation".
  • Choose your future.
Choose Windows.

Wednesday, August 23, 2006

Decompiling Java Class Files On-The-Fly

Being a Java developer, I sometimes want to look at the source code of class files just by double-clicking on the class file itself. There are lots of programs out there, such as DJ Java Decompiler, which allow you to do just this, but I was looking for a quick and easy way without the overhead of having to install memory intensive software.

Create ClassViewer.bat

I came up with this simple Windows batch script which uses the Jad Decompiler to decompile any Java class file that is clicked on. It then displays the decompiled code in your favourite text editor e.g. TextPad.

jad -p "%*" > "%*"
"C:\program files\TextPad 4\TextPad.exe" "%*"
sleep 5
del "%*"

Save this script as ClassViewer.bat

Associate Class files with ClassViewer.bat

Open File Explorer and click on Tools > Folder Options > File Types. Scroll down to the CLASS Extension (or if it is not there, add it by pressing the New button) and then press Change. A new window will open up asking you to select the program you want to use to open files of this type. Browse to ClassViewer.bat and hit OK. You have now associated this program with files with the .class extension.

Test it out...

Double-click a Java class file and see it execute the script and display decompiled code in your editor! You can even double-click class files within jars!

Friday, August 18, 2006

Only Apparently Real

I used to believe the universe was basically hostile. And that I was misplaced in it, I was different from it... fashioned in some other universe and placed here, you see. So it zigged while I zagged. And that it had singled me out only because there was something weird about me. I didn't really groove with the universe.

I had a lot of fears that the universe would discover just how different I was from it. My only suspicion about it was that it would find out the truth about me, and its reaction would be perfectly normal: it would get me. I didn't feel that it was malevolent, just perceptive. And there's nothing worse than a perceptive universe if there's something wrong with you.

But this year I realized that that's not true. That the universe is perceptive, but it's friendly...I just don't feel that I'm different from the universe anymore.

- Philip K Dick in an interview, 1974
(from Only Apparently Real)

Thursday, August 17, 2006

Software Review - SlickRun

SlickRun is a must-have program for techies like me, who are used to a *NIX environment and hate having to leave their keyboards to double-click icons on their desktop. I can't even remember what my desktop looks like or what wallpaper I have anymore! (Hmmm... I bet its something to do with Space though.)

SlickRun is a small command-line floating window which sits in the bottom right-hand corner of my screen. I simply press Win+Q and it flies up to my cursor and grabs focus, allowing me to enter any one of my favourite magic words. A "magic word" is basically a shortcut to various frequently used programs. All you do is type it in and press Enter and it launches your program(s). You can set up as many magic words as you like and even pass in arguments to your magic words.

For example, the magic word "firefox" would launch the Firefox browser and typing in "define Supercalifragilisticexpialidocious" would take you to the web definition of the word. (For those interested, "Supercalifragilisticexpialidocious" is the 34 lettered song title from the 1964 movie Mary Poppins. As a song title, it is a proper noun, but the word, and variations, has entered the English language as an adjective. It is one of the longest words in the English language.)

Any Windows commands such as "calc" are magic words anyway, so you don't need to set them up. You can even set up a single magic word to run multiple commands, so that after a reboot, you can simply type it in to start up all your programs.

SlickRun also auto-completes magic words for you and you can use the arrow keys to scroll through your history of previously invoked commands.

The main thing I love about SlickRun, is how simple it is. It doesn't get in your way or take up much CPU power. It just sits innocently in a corner, responds quickly to your commands and allows you to be more productive!

Here are some of my magic words that I thought I'd share with you:
  • define - goes to google definitions
  • eclipse
  • excel
  • firefox
  • google
  • jsql
  • mail - launches Lotus Notes
  • mydocs - goes to My Documents
  • paint
  • pf - goes to C:\Program Files
  • player - Windows media player
  • putty
  • shutdown
  • startup - launches all my programs after a reboot
  • toad
  • weather
  • windiff
  • word
  • xmlspy
  • ymail
  • ymsgr
  • ! - runs cmd /k e.g. ! ipconfig
  • lots of folder/drive shortcut names
Download SlickRun here!

Tuesday, August 15, 2006

Oracle 10g's New Row Timestamps

One of the systems I work on, maintains a cache of data which is reloaded from the database every time an update is made. Using a cache, rather than hitting the database each time, has some significant performance advantages. However, one of the downsides is the time taken to load the cache. Due to the large amount of data involved, sometimes reloading the cache takes up to 15 minutes!

The main reason for this is that because we don't know which rows of data have changed, we end up loading the entire cache each time. This means that we will reload 50,000 rows of data even if only 1 row has changed!

One solution would be to add a "last_updated" column to each of our tables and use that in our cache-refresh query. A better way, however, would be to use an exciting new feature that comes in Oracle 10g...

In Oracle 10g, a new pseudocolumn called ORA_ROWSCN is available on every row which "returns the conservative upper bound system change number (SCN) of the most recent change to the row". This is useful for determining approximately when a row was last updated. Also, the SCN_TO_TIMESTAMP function can be used to convert an SCN to a timestamp!

So coming back to the cache problem, we can determine which rows were modified simply by writing a query which gets all rows having an SCN_TO_TIMESTAMP(ORA_ROWSCN) greater than the time that the cache was last reloaded!

Sadly, we're still on Oracle 9i so will have to wait to use this awesome new feature:(

SELECT ORA_ROWSCN, last_name FROM employees
WHERE first_name = 'FAHD';

UPDATE employees SET salary = salary*10
WHERE first_name = 'FAHD';

WHERE first_name = 'FAHD';


Oracle®: ORA_ROWSCN Pseudocolumn

Monday, August 14, 2006

Changing Your Java Classpath at Runtime

Someone recently asked me how they could modify their Java classpath at runtime.

It is not possible to do this, simply by changing your java.class.path property because this property is only read when the JRE is first instantiated. After that, it is not re-read. Therefore, any changes you make to the property don't really do anything to the existing virtual machine!

BUT there is still a way to accomplish this:
  • Get hold of the SystemClassLoader
  • Call its addURL() method. Since this method is protected, you have to use reflection to sneakily change its accessibility in order to invoke it. I love hacks!
try {
File fileToAdd = new File("HelloWorld.class");
URL u = fileToAdd.toURL();
ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
if (sysLoader instanceof URLClassLoader) {
sysLoader = (URLClassLoader) sysLoader;
Class sysLoaderClass = URLClassLoader.class;

// use reflection to invoke the private addURL method
Method method = sysLoaderClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.invoke(sysLoader, new Object[] { u });
catch (Exception e) {

Using reflection to invoke private or protected methods is not good programming practice. Especially for hacking into system classes such as the Runtime ClassLoader!

Sunday, August 13, 2006

My First Post

Hello World!

This is my first post in my first ever blog.

So why have I started blogging?

  • Because everybody else is
  • Because I'm bored and have nothing better to do
  • Because I enjoy talking to myself
  • Because I want to create a stronger web presence
  • Because I want to share my ideas and thoughts with the rest of the world
  • Because I want to connect with other geniuses like myself

And what am I going to blog about?

  • My life - so I have a history of everything I've done
  • My interests - mostly technology and programming
  • Whatever I'm thinking about
  • Whatever I think will be interesting to share with others

Let the blogging begin!