Tuesday, December 18, 2007

Regular Expression matching more than a single line in Vim

As grep doesn't allow for regular matching of multiple lines, I've found that vim is a handy substitute if I didn't have use it as a pipe to another program's input.

The trick that allows vim to do so, is to enable multiple line matching by using the special regular expression escape '\_.' combined with a greedy qualifier.

The help line in the vim documentation offers how this trick is accomplished:


\_. Matches any single character or end-of-line.
Careful: "\_.*" matches all text to the end of the buffer!


It's precisely the warning highlighted in red that we are going to 'exploit' in order to allow multi-line matching to occur.

An example where this sort of matching usually applies are usually found in data formats like HTML/XML, where data sets can span multiple lines, separated by markups rather than newline characters.

As an example, say, if you wanted to match data that's bounded by <div> markup pairs, you'll have the following regular expression:


<div>\_.\{-}</div>


I often use this technique as a 'quick and dirty' way of breaking up markups into separate data easily, especially if it's only for a one-off use that doesn't merit writing a Perl or Awk scripts.

If you like reading this, you may also enjoy:
Wednesday, December 12, 2007

Ada Lovelace, The First Programmer

It is interesting that while in the IT industry today, programming is generally a male-dominated profession, but did you know that the first programmer in the world happens to be a woman?

Augusta Ada King (1815-1852), or more commonly known in Computer Science as 'Ada Lovelace', is widely regarded as being the first computer programmer. The etymology of her surname 'Lovelace' may sound funny, but that's only because of her formal title as 'The Right Honourable Augusta Ada, Countess of Lovelace', having received the honorific from her marriage to the Earl of Lovelace. Ada Lovelace is the most common form of reference to her in terms of modern literature.

Ada got to know of Charles Babbage, inventor of the mechanical general computer, the analytical engine, and through which, she undertook the task of translating Italian mathematician Luigi Menabrea's memoir on Babbage's machine.

In her translation, she had additional notes written to clarify the functioning of the analytical machine, in which the last section had contained an algorithmic example, detailing how the analytical engine should be programmed to compute Bernoulli Numbers. That was recognized by most historians as the first computer program, hence making Ada the world's first programmer.

Besides that fame, Ada was probably one of the more learned women of her time, having gone under the the tutelage of many of the contemporaries of her time. Ada was home schooled by a number of prominent people, one of which was Augustus De Morgan, who was another important person in CS history.

Augustus has contributed to one of the most important concepts that makes programming computers a possibility today. He was the first person to use the algebraic mathematical symbols that we know of today, and was the principal person behind boolean algebra. I'm sure 'De Morgan's Theorem' will ring a bell to most people who had to do engineering mathematics in school.

We may think very little of it today, but without the logic that we use with in 'if-else' that are prevalent in almost all programming languages, computers wouldn't have been too useful at all. It is just as remarkable that 'modern' technology that we know and use today are based on the things that were discovered some 200 years ago.

Ada died at the early age of 36 from medicinal bloodletting, a commonly prescribed procedure in those days, in an attempt to treat her from cancer. Today, the name Ada is probably most well known as a computer language, named in her honour by the U.S. Defence Department.
Sunday, December 09, 2007

Adding text before and after a regular expression match in Vim

Let say that you have a series of lines of text that you want to convert into 'System.out.println' or 'printf' statements, for example:


1 myapplication - an application that does something
2 usage: myapplication [-abch] param1 param2
3 -a: does a particular feature
4 -b: does another feature
5 -c: does yet another feature
6 -h: shows this help message


It's is laborious to append all those print statements manually, so the generally you'll want to use regular expressions to replace it for you. One way of doing this with POSIX compliant regular expression with grouping:


:'<,'>s/\(.*\)/printf("\1");/


(Note that this assumes that you have selected the given block with the 'v' keystroke or from the mouse already. Subsequent examples will also assume the same.)

Vim requires escapes for the parenthesises, by which one of the ways of shortening it may be by using the '\v' (very magic) operator:


:'<,'>s/\v(.*)/printf("\1");/


But the shortest way so far that I've found in vim is to use the '\&' matching operator, which works even when grouping is not explicitly used:


:'<,'>s/.*/printf("\&");/


The resultant output should for the quoted example is shown below, if you are too lazy to try it and see for yourself:


1 printf("myapplication - an application that does something");
2 printf("usage: myapplication [-abch] param1 param2");
3 printf(" -a: does a particular feature");
4 printf(" -b: does another feature");
5 printf(" -c: does yet another feature");
6 printf(" -h: shows this help message");


It's certainly much more powerful to be able to perform replacements like that with pinpoint accuracy at a single go, something that 'search and replace' text editors that do not have regular expressions capabilities are able to do.

If you like reading this, you may also enjoy:
Thursday, December 06, 2007

What is a Ruby 'symbol'?

A symbol is something that looks like ':symbol' in ruby code, where it is like a variable name but preceded by a colon character. It is used extensively in Rails, which had been confusing me in the past, and it still does, given that I have not grasped full clarity of its significance yet.

The explanation given to me was that the definition of a symbol is 'like a string you never intend to show to the outside world'. The example told to me as an illustration was primarily utilized as hash keys, which I am told that it is cheaper than using strings (probably because it's immutability, which I suspect it's acting like a singleton object too). The closest example that I keep associating to, is the C preprocessor usage of '#define'.

Other than its extensive usage in Rails, I'm don't see how much it will be of any average coding use yet, unfortunately. There's still some way to go in the path of Ruby enlightenment for me.
Wednesday, November 28, 2007

Short Week in Singapore

Last week, I had to head back to Singapore to help out and attend my brother's wedding. Past that initial rush during the first few days up till the wedding, I did manage to get a breather to do a bit of 'sightseeing' before returning back to work.

So quickly another year has passed since I was last back, yet within a single year, there seems to be remarkable amounts of changes throughout the island. The first thing that I observed is that the effects of population increase seems to be manifesting itself already: out of the few days that I have been travelling on the roads, there is not a single day that I have not encountered traffic delays.

Peak hour commute on the trains seems to be filled to the brim too, and while trains during non-peak hours are slowed down to 20-minute intervals, which is really annoying. But on the etiquette side, Singaporeans seems to have improved a little, given that they sometimes do adhere to the rule of giving way and standing to one side of the escalator now, if they are not moving.

The increase in foreigners is noticeably apparent too, but the difference since last year, is that it has not just been an increase of the Chinese from the PRC, but also the 'Ang Mohs', who have started to move into the traditional 'heartland' areas too. In fact, I was rather surprised to see one sitting down in a Yishun coffeeshop reading 'The New Paper' one morning while I was taking a walk! Maybe that was an isolated case, but I did still observe that there is an increasing concentration of Caucasians travelling to Ang Mo Kio, which I guess is where they are living.

Two thoughts that I have:

One, the increase in rental prices around the island must have hurt, even for the stereotypical  'well-paid' westerner expats, hence resulting in their move into the heartlands. Maybe more so for the Americans, given the US dollar has been rapidly depreciating the past year.

Two, some of these Caucasians aren't your typical 'foreign talents' that you may be expecting. I think at least half the number of them I saw are typical working-class people. Ceding executive positions to 'foreign talents' isn't enough anymore these days, so now we're having to cede mid-level jobs too?!

And if you held the belief that westerners are generally much better dressed than us locals, think again. I saw one shabbily dressed Caucasian fella carrying a number of cases while travelling on the MRT, and another one strolling along Orchard road. With the way they dressed, I would have thought of him as a 'karung guni' man! If he is the kind of 'foreign talent' who has recently immigrated to Singapore, we're in trouble!

Blame me for judging a book by the cover you may, but lest I be accused of being xenophobic, having lived in foreign countries for almost 7 years, I'd be surprised that I'm any less tolerant than anybody else. One thing I'm certain about, is the point of attracting quality people, irrespective of where you come from. Talents are talents, and riff-raffs are riff-raffs, foreign or not. I'm just concerned about making the numbers for 2.5m more people, which without more stringent quality control in the immigration policy, may result in having more riff-raffs in the future.

On physical changes, there are massive redevelopments all around the island. I've seen lots of upgrading works around in Bedok, perhaps stemming from their concern about the possibility of losing their wards since the last election? Besides the covered walkways, the addition of new lifts to every floor seems to be the predominant type of upgrades, probably in the anticipation for our aging society.

There's also a large number of condominium projects around the island, especially areas that are in close proximity to the CBD, like Somerset and Tiong Bahru. The number of condos around the Tiong Bahru area are just staggering! Another trend I've noticed is that pockets of land close to MRT stations have also quite popular for condominiums projects too. With the condo projects sprouting up like mushrooms, they must be building in anticipation of the influx of foreigners, given that they ineligible to public HDB apartments.

Shopping centres too, which the AMK centre is the latest I've seen. Even with older shopping malls, like Bugis Junction and Raffles City, are being retrofitted to utilize every free inch of free space available, to the level of absurdity! Just take a look the retail space outside Kinokuniya bookstore outside Bugis Junction. It's just a bloody pane of glass! Some may think it is 'creative use of space', but I digress. The tranche of land beside Wisma Atria is also in development now, where I read somewhere that it'll be one of those 10-storey shopping buildings modelled after Shibuya.

Pfft... like we don't have enough shopping centres already!

Rather than increasing the number of shopping areas, I much rather that steps be taken to slow the increases in consumer prices instead. Dense shopping complexes will only push up the rents for increasingly limited spaces, the inevitable result of the 'hub' concept that the entire island is redeveloping itself into.

This is however, making retailing more expensive. I've been told that those 'push carts shoplets' rent around $1800 a month at the cheapest and rent for a single foodcourt stall is at least $2500 and up. It is unsurprising why things are getting more expensive by the day. And it'll become increasingly more so. Travel to Yew Tee, and you'll have a taste of what the future will be like: the centralised 'hub', dominated by only a single food-court operator, have prices starting at $4.00 and up. Landlords increasingly have coercive monopolistic powers on rent, which will ultimately trickle down to the average consumer. No wonder  some "Singaporeans are fed, up with progress!"

And finally, what's with Singaporeans' latest fad with doughnuts?! After chasing after 'Hello Kittys', going through the bubble-tea mania and yearning for kopi buns, and now, doughnuts? It's one of those deja vu moments for me, since I have heard of this hare-brained idea from a friend a couple of years ago. He was rather enthused by the idea of importing the 'Krispy Kreme' franchise to Singapore. He should have recently graduated and returned to Singapore, surely, this doughnut 'bubble' can't be part of his handiwork?

PS:Oh, one more thing, I've lost my Motorola Razr phone sometime out at my brother's wedding. It has a US T-Mobile SIM card in it, which makes it easily identifiable, so if any kind Samaritan who manages to pick it up, please do return it! Much appreciated! Namaste! Gam Sia!
Sunday, November 25, 2007

Efficient Market Theory applied to Relationships

I know of a friend who keeps associating relationships with market talk. Well here's another one:
Okay, I'm tired of beating around the bush. I'm a beautiful (spectacularly beautiful) 25 year old girl. I'm articulate and classy. I'm not from New York. I'm looking to get married to a guy who makes at least half a million a year. I know how that sounds, but keep in mind that a million a year is middle class in New York City, so I don't think I'm overreaching at all.

Are there any guys who make 500K or more on this board? Any wives? Could you send me some tips? I dated a business man who makes average around 200 - 250. But that's where I seem to hit a roadblock. 250,000 won't get me to central park west. I know a woman in my yoga class who was married to an investment banker and lives in Tribeca, and she's not as pretty as I am, nor is she a great genius. So what is she doing right? How do I get to her level?

Here are my questions specifically:

- Where do you single rich men hang out? Give me specifics- bars, restaurants, gyms

- What are you looking for in a mate? Be honest guys, you won't hurt my feelings

- Is there an age range I should be targeting (I'm 25)?

- Why are some of the women living lavish lifestyles on the upper east side so plain? I've seen really 'plain jane' boring types who have nothing to offer married to incredibly wealthy guys. I've seen drop dead gorgeous girls in singles bars in the east village. What's the story there?

- Jobs I should look out for? Everyone knows - lawyer, investment banker, doctor. How much do those guys really make? And where do they hang out? Where do the hedge fund guys hang out?

- How you decide marriage vs. just a girlfriend? I am looking for MARRIAGE ONLY

Please hold your insults - I'm putting myself out there in an honest way. Most beautiful women are superficial; at least I'm being up front about it. I wouldn't be searching for these kind of guys if I wasn't able to match them - in looks, culture, sophistication, and keeping a nice home and hearth.

* it's NOT ok to contact this poster with services or other commercial interests

PostingID: 432279810

THE ANSWER

Dear Pers-431649184:

I read your posting with great interest and have thought meaningfully about your dilemma. I offer the following analysis of your predicament. Firstly, I'm not wasting your time, I qualify as a guy who fits your bill; that is I make more than $500K per year. That said here's how I see it.

Your offer, from the prospective of a guy like me, is plain and simple a cr@ppy business deal. Here's why. Cutting through all the B.S., what you suggest is a simple trade: you bring your looks to the party and I bring my money. Fine, simple. But here's the rub, your looks will fade and my money will likely continue into perpetuity...in fact, it is very likely that my income increases but it is an absolute certainty that you won't be getting any more beautiful!

So, in economic terms you are a depreciating asset and I am an earning asset. Not only are you a depreciating asset, your depreciation accelerates! Let me explain, you're 25 now and will likely stay pretty hot for the next 5 years, but less so each year. Then the fade begins in earnest. By 35 stick a fork in you!

So in Wall Street terms, we would call you a trading position, not a buy and hold...hence the rub...marriage. It doesn't make good business sense to "buy you" (which is what you're asking) so I'd rather lease. In case you think I'm being cruel, I would say the following. If my money were to go away, so would you, so when your beauty fades I need an out. It's as simple as that. So a deal that makes sense is dating, not marriage.

Separately, I was taught early in my career about efficient markets. So, I wonder why a girl as "articulate, classy and spectacularly beautiful" as you has been unable to find your sugar daddy. I find it hard to believe that if you are as gorgeous as you say you are that the $500K hasn't found you, if not only for a tryout.

By the way, you could always find a way to make your own money and then we wouldn't need to have this difficult conversation.

With all that said, I must say you're going about it the right way. Classic "pump and dump." I hope this is helpful, and if you want to enter into some sort of lease, let me know.
Wednesday, November 21, 2007

Random Ruby Notes

I have been using Ruby much more than Perl these days to do all my dirty work in scripting most text handling tasks, which I find it is much better at doing these days. My only problem is mainly just the learning curve, which is typical of learning any software language, irregardless of how much conceptual and ideological similarities both languages may share.

Each language comes with it's own 'best practices', little idiosyncrasies and conventions that are unique, and so I'll try to present the following points that I've picked up for Ruby. Pardon me when I litter my subject headings with the 'right way' of doing things, it just means it's the conventional practice usually adopted by Ruby programmers.

The '?' or '!' behind the names of methods

They are both just a language convention. For the question mark, it is normally only for calls that return 'true' or 'false'. For the exclamation mark, it is used to mark that the method modifies 'self', rather modifying a copy while leaving the original unchanged.

It's helpful to note that having the punctuations behind the method names has no other significance besides that, something which is helpful to starters, especially if one is actually looking for an operational difference where there is none.

How do I know what class an object belongs to?

Either by:
object.class == Class

Or:
object.kind_of? Class

This applies only to Ruby being a full object oriented language. Perl does have OOP glued onto it, but seems quite ill-conceived that I hardly use it compared to the usual quick and dirty un-OOP that I'm used to.

The difference between the '==' operator and 'kind_of?' is that the former only matches the exact class, where kind_of? (probably) matches ancestor and descendant classes. I guess that's similar to the 'instanceof' keyword that I'm rather familiar in Java.

The right way for checking if a variable is defined
if defined? variable
puts "right way of checking variable is defined"
end

Where I've originally have been checking for 'defined-ness' by comparing to nil:
if variable == nil
puts "wrong way of checking variable is defined"
end

The right way for checking for array emptiness or non-emptyness

Rather than using arr.size == 0 or arr.size != 0, the two methods in ruby is arr.empty? or arr.any?. A comparison that checks the presence of an array is not a valid comparison for emptiness, i.e:
if [] then
puts "not the right way to check emptiness"
end

The above code is incorrect, because it will always return true as it checks for an array being defined, which is always true (for an empty array), rather than checking for the length of the array being zero.

Class loading mechanism in Ruby

If you needed to load a class definition dynamically, usually by passing the string of the class at Runtime, in Java the facility is:
Class c = System.getSystemClassLoader().loadClass("String");

The equivalent in doing this for Ruby:
s = Object.const_get("String");
Saturday, November 10, 2007

Changing Gmail SSL certificate

I was curious why I couldn't fetch my mail to my laptop from Google's gmail service, when it has been promptly dropping my mail onto my Blackberry. I tried running the 'fetchmail' command manually where I was greeted with the following message:

fetchmail: pop.gmail.com fingerprints do not match!
9203:error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:894:
fetchmail: SSL connection failed.
fetchmail: socket error while fetching from
[my email]@pop.gmail.com
fetchmail: Query status=2 (SOCKET)
Seems like Gmail has changed their certificates! The way in solving the problem is to pull the new certificate and update the MD5 key in .fetchmailrc:

% openssl s_client -connect smtp.gmail.com:995 -showcerts
CONNECTED(00000004)
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
-----BEGIN CERTIFICATE-----
MIIC3TCCAkagAwIBAgIDCDijMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDcxMDI1MTc1MzE2WhcNMDkxMjI0MTg1MzE2
WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
TW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xFjAUBgNVBAMTDXBv
cC5nbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO03QxerFKZV
8yeomuL4zSl8Pr7hMWnKMMgp/CwhwadeBmL0LQHHbjL/6z/Z59ZQvrztqkwhchA2
APKzUwRVTyn7Shx6vBqk6oFmTqoOLmY6hbq6l8uVdUv0AfbHwio8CnLpK2+nbuFl
flPwx1DH0E3grD8+CrH5SmScfTWbDkcXAgMBAAGjga4wgaswDgYDVR0PAQH/BAQD
AgTwMB0GA1UdDgQWBBTJRG/OFpZt+BV43JM3NshHMjpwazA6BgNVHR8EMzAxMC+g
LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDAf
BgNVHSMEGDAWgBRI5mj5K9KylddH2CMgEE8zmJCf1DAdBgNVHSUEFjAUBggrBgEF
BQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEAOKr3mhxtwFCS3J6lbeaf
3KrHKi935BZkI75sRbON+hog0t2ovcM2i7fxs3xneH8USLsHgfxNBj9tkMogMK/K
sO/NUVZ/IfyqcNNkp2619qTQXthKRH42JKpAKgNhT1bdno3pxn+eDEpqmU3CE7IP
HDCjWOK1fGkZ/yFAuTxuxAc=
-----END CERTIFICATE-----

---
Server certificate
subject=/C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
issuer=/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
No client certificate CA names sent
---
SSL handshake has read 891 bytes and written 314 bytes
---
New, TLSv1/SSLv3, Cipher is DES-CBC3-SHA
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : DES-CBC3-SHA
Session-ID: BEE4859291CC8325784BE44785F2F705D47CD462B0A5ADC98B62A86A1851B41E
Session-ID-ctx:
Master-Key: 4E085FD56B0A36C4C278C7250BC1D5BC144CE8E7CF979D07086AA1D5E7C40D64DB76285057E16EAD027F789B9B0E1D84
Key-Arg : None
Start Time: 1194725790
Timeout : 300 (sec)
Verify return code: 21 (unable to verify the first certificate)
---
+OK Gpop ready for requests from [MY IP ADDRESS]
Copy the part coloured in red into a new file, e.g. '/etc/ssl/certs/new_gmail.pem' and then you have to recreate the symbolic links for their hash value, before generating the MD5 checksum to update in .fetchmailrc:

% c_rehash /etc/ssl/certs
... lots of other output ...
new_gmail.pem => 7f549ca4.0

% openssl x509 -fingerprint -md5 -noout -in new_gmail.pem
MD5 Fingerprint=44:A8:E9:2C:FB:A9:7E:6D:F9:DB:F3:62:B2:9E:F1:A9
Replace the old hash with the new hash value in .fetchmailrc, given in my example here:

poll pop.gmail.com with proto POP3
auth password user "myusername" there with password "mypassword" is vince here
options keep no fetchall sslcertck
# options keep ssl sslfingerprint '59:51:61:89:CD:DD:B2:35:94:BB:44:97:A0:39:D5:B4'
options keep ssl sslfingerprint '44:A8:E9:2C:FB:A9:7E:6D:F9:DB:F3:62:B2:9E:F1:A9'
Replace the old line in blue with the new MD5 checksum as shown above. Fetchmail should resume working now!
Tuesday, October 30, 2007

Tricks on handling multiple line inputs and outputs

There are some of the trivial bag of tricks that I don't normally take notice, which does often comes back to bother me. I just have to trip on Finagle's Law whenever I forget these tricks after long disuse. Things like handling multi-line inputs and outputs seems to fit into that category, so here's all I can recall form my own reference:

Printing multiple line outputs with a single echo command

The special escape for newline in bash is $'\n'. Here's an example how it's being used:


% echo "Hello$'\n'World"
Hello
World


Other non-printable characters can be similarly escaped this way (e.g. The NUL terminator represented by $'\0').

Reading multi-line inputs from stdin

This is achieved by using the << operator:


% cat <<TEST
> This is a test
> Hello World
> TEST
This is a test
Hello World


Reading multi-lines of a file into a single variable

Because spaces are treated as field separators in bash, and it won't try to read past the first separator, you need to force the shell to treat nothing as a separator, by modifying the IFS (Input Field Separator):


OLDIFS=$IFS IFS= var=($(< filename.txt)) IFS=$OLDIFS


This above example assumes that you have a file called filename.txt, and at the end of the operation, the entire contents of the file is stored in the var variable.

Matching multiple lines using grep

When searching for two or more consecutive words within a sentence on a text file (or HTML), sometimes it is possible that the words are span across multiple lines, hence making typical word search, barring from using a script, difficult. One of the neat tricks to accomplish this without using any script, is through GNU grep's -P flag.

Assuming that you have a file called test.txt that spans two or more lines:


I like to say a nice warm "Hello
World" to all of you out there!


To search for the consecutive words "Hello World":


grep -P "Hello\WWorld" test.txt


Curiously, it does not seem to work on Gentoo/Ubuntu linux's version of grep but works only on my old RedHat distro only. Maybe it's something that has been phased out.

Splitting inputs into multiple lines

The easiest way to split things on the command line is to use the sed
command:


% echo "Hello World" | sed -e 's/ /\n/'
Hello
World


If you want to do this within vim, it is a little bit less straightforward but still doable:


:s/ /<CTRL-V><ENTER>/


Replace the items in the angled-braces with the actual keystroke itself. The screen the output actually looks like:


:s/ /^M/


So don't be concerned by the visual difference.
Saturday, October 27, 2007

Wireless problems on ipw2200 (Intel Centrino) on Linux

I am quite pleased that the gentoo-sources for the Linux kernel has been upgraded to use version 1.2.0 of ipw2200 driver. The ipw2200 driver is used for all(?) of Intel's built-in wireless laptop chipset. The last stable update, 1.1.4, was incorporated into the kernel that has been unreliable for me in connecting to certain access points, especially to the Apple Airport that I have in the office.

On Ethereal/Wireshark, I keep seeing 10-15 resend packets per packet sent to the Airport successively, and 10-15 duplicated packets returning from time to time, annoying the least, but almost unlikely to be a connectivity problem, given that the airport just sits 0.5m and is facing squarely my laptop.

Access to open wireless access points, however, seems to work without a hitch. Maybe is just problems with WEP encryption with version 1.1.4, or maybe it is just something else. Whatever it is, it seems like version 1.2.0 has taken it away.

The other good news about the kernel source version 2.6.22, is that it allows the 'promiscuous' mode of the wireless card to be available as a configurable option now. This means that WEP cracking tools like aircrack-ng will be able to listen, and use replay-injection attacks, something that was only available to older, established wireless chipsets like Atheros, Prism or Orinoco in the past.

Not that I find it fun cracking WEP networks. But having to know I can, makes it useful if I ever were ever in desperate need for Internet access in a non-open wireless network environment. I very much doubt so though.

With the Blackberry, and in the future, more iPhone-like Internet access becoming ubiquitous, it'll be even harder to find an (il-)legitimate reason to need to piggyback on other people's wireless network, because you won't need to!
Friday, October 26, 2007

Find out version of libraries installed in Linux

It is just one of those things about Gentoo that I never could remember. I was needing to find out what version of libgtk I was using, and for the life of me, I couldn't remember what command was required to find it out, until someone kindly told me that you can do that using 'emerge -pv'.

Funnily, it didn't come to me intinctively, even though I use the command to query before upgrading packages all the time. It is just that I've never thought to use it as a tool for library version checking. Guess that might be the same way on other distributions to find out about their the versions of their installed libaries as well. For .deb (Debian/Ubuntu) based distros, try the 'apt' command, while those on the .rpm (RedHat/SuSE) based distros, try 'rpm' or 'yum'.

What package names should you search under? Frankly, I don't have a clue. If there is one bad thing about having a fragmented market distribution base like Linux, it'll have to be the confusion of configuration layouts among the competing distributions, which makes finding a solution a rather time consuming process.
Monday, October 15, 2007

Blog Action Day - Stop Being 'evian'!

Bloggers Unite - Blog Action Day 'evian' in reverse is spelt 'naive', which sometimes lead me to suspect if the bottled water manufacturer is really thinking about consumers that way.

Perhaps so, given that the bottled water market is an unnecessary one, one that is fueled by consumers' irrational demand for wanting to pay for a healthier, chic drink to soda.

Unfortunately the problems caused by the demands for bottled water exhibit itself as a strain on the world, manifesting itself as a net contributor to global warming. If you think about it, transporting water from some Swiss mountain range a continent away and shipping to you as drinking water that has no material differences in terms of quality, is just a blatant waste of resources.

The energy costs of involved in storing, bottling, and transporting the water though, is substantial, especially when compared in relation to the negligible benefits it brings you compared to typical tap water.

Generally, there fundamentally nothing wrong with the water from the tap, as often is the case in most countries around the globe. In fact, in comparison, tap water usually have to pass even more stringent water quality tests, in addition to that, usually comes fortified with elements like fluoride, which helps in preventing tooth decay.

The increase in demand for bottled water has increased the drink industry's ravenous hunger for plastic, like the polyethylene terephthalate (PET) bottles that we are commonly use for soda drink bottles.

While recycling these bottles is a viable alternative, statistics are showing that our recycling efforts have not been stepping up with our consumption demands. In the end, a sizable amount of these single use bottles often end up polluting the lakes, rivers and seas of the world.

Some people I've met had strenuous objections to drinking tap water, citing reasons that it tasted awful compared to the refreshing taste of bottled water. I shall not argue on whether if these perceptions are just psychological, but instead I'll like you to think about it in a rational, economically-inclined way: paying for a bottle of water that costs 4-8 times more expensive than a litre of petrol, really sounds like extreme lunacy.

It's thus no wonder why companies can call us 'naive' and still be able to get away with it.
Saturday, October 13, 2007

Education: NOT a Requisite for Success

By success, let me use an arbitrary (and pardon me, superficial) definition, as a person's net worth that is a magnitude greater than his peers of the same age group.

The first person I knew who qualified that criteria was a classmate of mine many years ago. He was someone who frequently skipped school, and eventually got himself held back for a year because of his failing grades. The reason, was that he was out and about, starting his own mobile phone business, initially by buying up used phones and reselling them, and later 'modding' them for resale at substantially marked-up prices.

I had a pretty bad impression of him, not just because of his truant behaviour, but of his cut-throat attitude, even towards friends. But in all fairness, he had always been upfront about it, telling us not to seek him for deals, because business was all about making profits, not friends.

Back in those days, I had a staunch but naive belief that success only comes from the books. But he proved me wrong, big time.

When he first started out, it was just running about the campus as a middleman, buying and selling phones from people and making small profits on the side. By the time I graduated, he had earned enough to start his own store, and proudly declared that he was raking sufficient money to pay for his own car upfront.

Which was no mean feat even for an adult, considering that a modest car in Singapore those days would have costed up of $100,000. My net worth was no more than $1000 then, making him the first person I know who got successful independently.

Since those days, I've gotten to know many other successful people, and those who did attain success through the education route. Many of them have reached the pinnacle of their careers, one of them who is a Vice-President of a Fortune 500 company, while another is an executive who holds directorship in a number of publicly listed companies.

But what fascinates me is not about them, but the stories that they tell of their bosses: One did not complete his high school education and the other was a university dropout. Surprisingly, even from my limited sample of the most successful people I've personally met, this trend holds, where the majority of them came from a background where education is not the decisive factor for their success.

I have met many people who have this misguided belief that education is a 'be all and end all'. In fact, I was one myself too. But that isn't really so. There are some who blindly pursuit the paper chase without considering the implications of their actions, only to end up without a purpose after graduation and laden with huge debt of student loan to repay.

Truth be told, education does not even guarantee you a job, let alone success in life.

I have known people that had graduated in my field who ended up becoming tele-marketers, insurance agents and even one who now works in a fast food outlet. They may be the few cases that I personally know of, but I believe they can't be the only ones who buck the maxim.

But don't mistake me for trying to lambast the value of education. I'm not.

Education is important, if you have the passion to learn. But we must be aware that a piece of academic qualification will only help to open that first door of opportunity for you, but it is certainly no guarantee of an automatic success in life. That is ultimately decided by factors like personal motivation, aptitude, and opportunities when they present themselves to you.

While we do not have a choice in deciding our smarts, or when lady luck will smile on us, but one thing that we're able to influence, that is how determined we are to achieve success. My philosophy on success is easily summed up by Margret Thatcher's quote:
"I do not know anyone who has got to the top without hard work. That is the recipe. It will not always get you to the top, but should get you pretty near."
Those who are motivated, will be the ones who make the most out of their education, or excel in whatever they do. But the reverse is almost never true.
Thursday, October 04, 2007

Links Between Singapore and Burma

I've long known about the connection between Burma and Singapore before the recent increased media coverage on the plight of the Burmese under the military junta's rule that has brought the issue back into focus. The knowledge of the drug links between Singapore and Burma was first raised by Dr. Chee Soon Juan, highlighting the government's association with Steven Law, the son of the drug kingpin Lo Hsing Han. He was just a lone voice among the wilderness then, and there were hardly anybody who noticed or even bothered.

Not at least until the recent spate of atrocities committed by the military against the protesters for democracy. There has since been a number of reports that has resurfaced, linking Singapore's nefarious associations with the junta, through online sources from The Online Citizen, and foreign news agencies, like Sydney Morning Herald and The Age[1].

Singapore is known for being particularly litigatious when it comes to questioning the integrity of the government, often resulting in punitive lawsuits against individuals or even news agencies, whenever there are any remarks that even whiff anywhere near slanderous towards their political leaders.

But we are greeted with silence, when presented with these allegations that our country has been providing with infrastructure for spying on their citizens, providing military hardware for the junta to commit these atrocities, yet it was hardly given any investigative coverage upon, let alone to be open enough to be disputed or challenged in the political arena. To me, this amounts to a tacit admission, that the sources of these allegations are likely to be true.

This is also stark proof of the poor journalistic freedom in Singapore. If there is truly freedom for investigative journalism, such articles will have been on the front pages of our papers, and not though the Internet by the efforts of active citizen journalism[2]. It is the function of the free press 'in keeping them honest'[3], without which, is probably the reason why these clandestine transactions with Burma are left unchecked in the first place.

Our country is not as innocent from blame as we would like to have. Our police force behaves as if it is the natural extension of the Burmese junta, in deploying the same intimidation tactics against anybody who supports the cause of peaceful democratic protests. Ironically in a way, we are seeing a reflection of Burma through the actions of our own country. To quote lalaland9:
"I am totally ashamed when I saw how the police were stopping people from entering St Martin's Drive (where the Burmese embassy is situated), demanding their NRIC number and intimidating them to leave."
From the limitations of a free assembly by the people[4], like the Odex protest incident, where 8 youths were met with an excessive force of 4 anti-riot trucks, to the restriction of personal freedoms in expressing our moral views by preventing us from wearing shirts that supports the Burma cause, they are all gross violations of our rights as citizens of Singapore. When we cast ourselves in that light, how much better are we Singaporeans when compared to the Burmese?

Internationally, besides famous for being straight-laced and inflexible people, we are now slapped with an additional tag of being 'without a heart', as mercenaries, people who are swayed only by financial gains. If that is the impression the Burmese and the rest of the world have about us, it would only mean that there is something really wrong with our society. If so, then it is probably high time we examine and reflect upon our own actions.

If the government is complicit in aiding the military junta, the facts and details has to be made known to the public. On a personal capacity, there is little we can do, legally. As I have mentioned in the past, I believe that actions can and should be directed at the parliamentary process, that we should press the elected minsters to question and address these issues in parliament. It is only appropriate that we, as voting members of this country, let our constituency MPs know of our concerns about these purported links with the military junta.

While I am neither optimistic, nor counting on the responses (if even any at all) of the PAP constituents in regards to this issue, I do hope that other MPs, be it the opposition or NMPs, take up the cudgels, in at least motioning for a parliamentary inquiry to take place, or to table in these questions, questions that needs to be asked.

It is time we all know the facts, and learn how deep the rabbit hole truly goes.



[1] The Australian coverage from the two papers are apt, given that they circulate both in Sydney and Melbourne. They form the largest collective group of Singaporeans outside Singapore. Source: Straits Times, Sep 30, 2007, Home away from home For Singaporeans overseas - "[T]he OSU, which is under the Prime Minister's Office, began with Sydney and Melbourne as Australia has the largest concentration of overseas Singaporeans - some 40,000 reside there."

[2] I must commend on 'The Online Citizen's coverage of this issue in a factual, objective manner, as well as the other news that the mainstream press have been refusing to cover. The site is honesty starting to act like a contender to as an alternative journalistic outlet. Keep up the good work guys!

[3] The phrase is pinched from CNN's segment 'keeping them honest', where their investigative journalism helps to keep the government and politicians in check.

[4] IANAL, but as far as I know, the freedom of free assembly is enshrined in the Constitution. It is totally absurd, unconstitutional that a statue of limitation an assembly of more than 5 people can be legal, given that it runs against the spirit accorded by our rights that's defined by the Constitution.



This article is written in support of The Free Burma movement.

Free Burma!

Wednesday, October 03, 2007

The Preference for Hard Languages

A language is a tool. When skilfully used, it allows you to craft great works. This is the same for computer languages. Engineering a good piece of software is, more art than science. The skill in designing and writing pieces of code that function seamlessly is like that of a sculptor, who is constantly crafting his works to achieve perfection. Those little touches of detail on usability and functionality, or in just providing a sensible error prompt, are equivalent to the amount of detail a dedicated sculptor puts in, chipping away the pieces of imperfection to reach the ultimate state of beauty.

Unsurprisingly, some tools are better than others. A chisel is and a hammer is better used for carving rocks than sandpaper is. A stick of dynamite makes it faster to shape Mount Rushmore than with just a pair of chisel and hammer. In the end, it is a matter of choosing the right tool for the right job.

It is not uncommon to come across people who are adamant on their choice of a 'hard' language when it comes to writing software. But the myth about computer languages is, that 'hard' is really subjective.

The choices of newly popular languages like Python or Ruby is generally no harder than old school languages like C or Java. 'Hard' languages can be easily spun around and to be interpreted as 'easy'. Easy because it will allow you to write solutions with considerable less lines of code.

Prolog and Lisp are more suited for solving logic problems, like the 'Missionaries and Cannibals' problem. It will probably just take a skilled programmer less than 10 lines of code to solve, whereas the same thing will take a good C or Java coder hundreds of lines to accomplish.

Conversely, higher level languages take away the nitty-gritty details of the underlying hardware for which may sometimes be undesirable. Someone can write a Ray Tracer in Python or Ruby, but nobody will expect the language will be a real fit, or to be executing at a speed that is of any realistic practicalities. Abstraction has its cost, and while this cost may be acceptable for some classes of applications, will not be so for others.

In the end, the choices of languages are all about its expressiveness and suitability. For people who love the self-celebration of their choice of 'hard' languages, it either smacks a sense of insecurity seeking justification, or a case of 'the person with a hammer' - everything else looks like a nail!

Such people if they can't stop ranting about how hard or cool 'language X' is, my remedy is to recommend them to learn Malbolge, the language that is hard. Good luck trying to code in that :)
Tuesday, October 02, 2007

Profiling in Java

In any Computer Science lectures that has anything to do with the topic of profiling, the story of how 'awk' got a performance boost by 25% just using gprof never fails to not be mentioned. The story ends with finding that offending loop code that accounted for most of the wasted computational time.

What makes it such a good story, is probably because that a quarter of the performance drag hinges on just a single line of code. But before anybody starts embarking on their own witch hunts in looking for such performance bottlenecks, I'll like to remind you about the other story that CS students are always told, the one related to by the 'Grandpa of Computer Science', Donald Knuth, on premature optimization:
'There is no doubt that the 'grail' of efficiency leads to abuse. Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.'
This is important, because the first thing that a programmer should look out for, is correctness. You can always speculate about where performance bottlenecks are, but unless you're using something as obvious as a 'Bubblesort', you can't really be sure where the major performance overhead is going to come from.

This is why profilers are handy. It tells you where exactly the performance bottlenecks are, rather than trying to make wild guesses about them before implementation, and writing obscured optimizations that will most likely add unnecessary complexities and potentially introduce more bugs.

Profiling in Java

The equivalent of 'gprof' in the GNU/C world is named, unimaginatively, as 'hprof' for Java, a natural succession from the letter 'h' to 'g', just as the 'C' language is the successor to 'B'. Gosh, aren't Computer Scientists lacking in imagination!

An example syntax for invoking a profiler looks like:


java -agentlib:hprof[=options] ToBeProfiledClass


Hprof allows for the measurement of CPU cycles, Memory Usage, and Thread traces, so it is absolutely helpful in determining the state of the application, and sometimes gives you additional insights in bug tracking either from traces, or locate the sources of memory leaks. I won't provide more usage details, but a more comprehensive run through of hprof can be found here.

Understanding Hprof's output


SITES BEGIN (ordered by live bytes) Sat Sep 29 13:46:46 2007
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 18.07% 18.07% 387192 16133 390912 16288 302005 java.lang.String
2 12.04% 30.11% 258144 16134 258144 16134 302007 com.sun.tools.javac.util.List
3 6.14% 36.25% 131512 2 131512 2 301079 com.sun.tools.javac.util.Name[]
4 6.12% 42.36% 131088 1 131088 1 301080 byte[]
5 6.12% 48.48% 131072 1 131072 1 301679 byte[]
6 3.06% 51.54% 65536 1 65536 1 301187 byte[]
7 3.06% 54.59% 65536 1 65536 1 301677 byte[]
8 1.60% 56.19% 34240 428 34800 435 302250 byte[]
9 1.11% 57.30% 23856 426 23856 426 302248 com.sun.tools.javac.code.Symbol$MethodSymbol


The various columns indicates the following:
  • rank - self explanatory
  • percent self - percentage of memory taken up
  • percent accum - cumulative percentage of memory taken up from rank 1 to rank N
  • live vs. alloc'ed - the actual objects that are active vs. objects still held in memory i.e, not garbage collected
  • stack trace - The corresponding id given to a thread trace that is holding onto a reference to this memory
  • class name - The type of object the memory is allocated
A profile dump is only meant to be an indicative measurement of the application at the given time, so when you profile is important as well. You'll most likely want execute a profile dump when the CPU load is high rather than when it is idle. The magic keystrokes that allows you to do a dump, is 'ctrl-\' in Linux and 'ctrl-break' in Windows.

Using Hat

Hat or (JHat as is now called in Java 6 SE), is a profile analysis tool which allows you to have make relational queries (like SQL) of memory usage, which is something that's pretty interesting.

( Screenshot of Hat's Web Application Interface )

While I've known Hat for quite a while already, but I have given up a long time ago for not managing to get it to work. But recently, there is a new bug report filed for the error, which explains the reason for my problem is because Hat only being able to read the binary format output from hprof.

So make sure you have the following parameter for binary format activated:


java -agentlib:hprof=agentlib:hprof=heap=sites,format=b ToBeProfiledClass


If you read the bug report, you'll realise I wasn't the only person being annoyed that such a trivial bug isn't fixed for such a long time, not to mention the immense confusion that it's caused. Perhaps someone should start renaming JHat as 'asshat' instead!
Saturday, September 29, 2007

The Rich Men who Saved

Leafing through last night's Wall Street Journal, I found a book review about Chuck Feeney (here's a similar article I found online), my first response was, Chuck Who?

If you're like me who didn't know, Chuck was actually ranked 23th on Forbes Richest List in 1988. Except now, he isn't. He has already given out most of his wealth to charity. He belongs to a class of wealthy people whom I greatly admired. Among that class, the list includes people like:
  • Andrew Carnegie (Industrialist Magnate)
  • Warren Buffet (Berkshire Hathaway)
  • John D. Rockafeller (Standard Oil)
  • Sam Walton (Walmart)
  • Ingvar Kamprad (Ikea)
What distinguishes these men, are not just about their immense wealth, but that they lived a more modest lifestyle than most ordinary people despite being rich. This list is further segregated down to a few of my favourites, at the top being Warren Buffet, followed by Andrew Carnegie and J.D. Rockafella.

There is a common theme among these 3 I've mentioned, that they have contributed much to philantrophy. Buffet had given out his wealth under the auspices of the 'Bill and Merlinda Gates Foundation', not under his name. Carnegie and Rockafeller had also given their immense fortunes away, but they left behind a legacy that carried past them, in terms of their foundations, as well as with famous landmarks like Carnegie Hall and Rockafeller Centre.

I love people who are great contributors to philantrophy, but I believe that the motivations behind the contributions are equally important too. To quote John Train, from one of my favourite books, "Money Masters of Our Time":
"Philantrophy, while meritorious, on a large scale, becomes a political act. The tycoon who extracts a fortune from the public to build a museum in one place rather than another has not created new beauty, only imposed his priorities on society."
That is what really impressed me about Chuck. As rich as he is, he has given his wealth anonymously, not seeking to have his name etched into a monument for posterity.

It's just me, but I really enjoy people who are truly altruistic, because I believe that's what humanity is all about. I know it probably doesn't amount to much Chuck, but I'd like you to know that you have topped my list as the new No. 1 of the people that I have aspirations to be.

Personal Experiences

Over the course of my career, I had the opportunity to know a very well-off executive who holds a number of major positions in a number of Australia's biggest companies. He is however, a frugal man, who does not spend his money on excessive luxury items or fund himself for a flamboyant lifestyle. Not just that, he is an amazingly affable person, someone who has never carried himself as being snobbish or showoff-ish at all.

Between the occasional Subway lunch treats, and the dollar notes he dishes out of his wallet into the hands of the homeless people on the streets, I really don't see how different the rich are from the poor. The only differences that I know of, are those of jerks who install gold plated taps and those who are not.

Lesson Learnt

I see a lot of commonalities between these rich people, that they have inculcated the value of frugality in their lives. Perhaps it was the combination of an impoverished background and upbringing in their earlier years that defines this virtue, something I can relate from the experiences of my own personal life.

If rich men can live with such frugality, I certainly can't see why common people like us should have an excuse to participate in frivolous consumerism[1]. The credit card and the debt driven culture many have grown addicted to should be something that should be curtailed. If there is a lesson that everyone can take away from it will be that we should only spend what we can afford, but not in excess of it.



[1] The keyword here is frivolous. I don't think that consumerism is bad, per se. In the words of Henry Ford, "More production could lead to better wages, which in turn would lead to more spending by the public, yet more production and eventually even higher wages."
Monday, September 24, 2007

Why More Lisp and Less Prolog in the U.S.

Reading through the topics on Y Combinator, there seems to be renewed interest from people in learning Lisp, which is a language I've never heard of until recently. So I looked online for a primer on Lisp, to my surprise, I find Lisp similar to Prolog (in intent), which is something that I'm more familiar with, in relation to the AI classes that I took during my undergraduate studies.

But I was still curious why Prolog was hardly mentioned until I found this:
Q: How does Prolog differ from Lisp?

Lenat: There has been a constant dream in AI, by a large fraction of people in the field for 25 years, of the form: there really ought to be some way of formalizing and axiomatizing human thought and reason. But time and time again, all attempts at axiomatizing things have led people to trivialize them, to the point where they no longer apply to what they were originally modelled after in the real world.

There are a lot of people in the field who want to be sure, who want to believe that they can get absolutely precise, logically guaranteeable models that are close to what is going on in the real world. If you believe that, then the kinds of operations you want as primitives are logical operations, those involved simply in theorem proving. Those are the sort of operations that are present in Prolog.

Q: Why is Prolog used more in Europe than in the U.S.?

Lenat: In most European countries [and elsewhere- jb], you have very rigid hierarchies of 'ancient' professors, and then younger professors, and then research associates-- and then it filters down about seven levels to the people actually writing the programs. It is the people at the top who decide what research is going to get done, not the people at the bottom who have experience with what is actually happening.

The people at the top-- who [may] want to believe in a nice, simple, mathematical, axiomatizable universe-- basically determine the kind of research that is going to get done. The experiences that would lead them to change their minds are simply not occurring to them, they are occurring to the people at the bottom, who have no say.
(Quoted off: http://www.robotwisdom.com/ai/ilsmemoir.html)

That was just hilarious. I didn't realise that North America and the rest of the world hated each other so much when it comes to AI. Well, here's a more measured historical reference of why Lisp is used more commonly than Prolog in North America.
Sunday, September 23, 2007

Weekend Reading

It's been a while since I've been to a bookstore to pick up a book to read anymore, solely because that there is just so much to read online these days. However, unlike books, there is much less quality control on the net, and thus I tend to be even more picky in the things that I read. The following are a few I've picked that I'll like to share:

Pmarca
This is the blog of Marc Andreessen of the Netscape fame. Post-Netscape, he has been founded Opsware (which was acquired by HP) and Ning, a social-network creation site. If you're interested in the details of how startups, entrepreneur-ism, and his thoughts on the capital market, his blog will be an insightful read.

Brazen Careerist
As the author of Brazen Careerist, Penelope writes mostly about things related to career building, chatting about issues related to the workplace, lots of it by example. She sometimes talks about issues that are personal to her life as well, which gives a rather genuine feel to her blog than most.

Sudden Debt
While this guy writes anonymously about the market gyrations on Wall Street, he sounded like someone who is either and insider or pretty senior in the financial market. If you are interested in learning what the next major market pitfall might be, this blog will be for you, besides the fact that he has a wicked sense of humour!

Coding Horror
Who says that Computer Science can't be fun? Jeff Atwood, who writes on his blog called 'Coding Horror', deals with mostly fun stuffs related to Computer Science and IT in general. One of the sites that makes an entertaining read.



If there are any good quality blogs that you enjoy reading, feel free share what your favourite genre of blogs that you read, leave a URL as a comment, but no spammy, ad-laden sites please!

And have a good weekend read!
Thursday, September 20, 2007

My First 3 Lines of Code

When I was really young, my life ambition was to be a magician, followed by being a chef (which I did become briefly, as I mentioned in 'about me'). It was only in my early teens that I had my first hand experience with a computer which has piqued my interest in wanting to become a software hacker, ultimately which is now my career.

The trigger of it all, started from my first experience with a computer, during a school excursion I had to the Singapore Science Centre when I was 11. I remembered that it was an IBM PC computer, running a text-based graphical application with colours on a CGA display, which was probably quite an expensive model those days, given that computers usually came with green tinted monochrome monitors.

There was already an application running on the computer, which I only vaguely recalled that it had something to do with elevators. It was some sort of application teaching about some mathematical concept, using elevators as an example. How boring was that?!

Being the mischievous kid I was, rather than using the application 'correctly', the first thing I instinctively did was to start sweeping my palms across the keyboard, seeing if I could cause the application to do something that deviated from standard behaviour. By deviated, gee, I probably considered crashing the application as satisfying my criteria!

(Microsoft's GW-BASIC, the closest screenshot to what I remembered. Courtesy of Wikipedia)

But I got more than what I bargained for, as my random sweepings invoked the BASIC interpreter, which was built into the PC. That was a curious sight for me, given that the only thing that was visible was a flashing cursor, and a function menu at the bottom of the screen. I kept banging on the keyboard (rather violently), which really didn't do any much more, besides producing random gibberish on the screen.

It happened that there was a young man with his girlfriend, both probably in their mid-20's, who saw what I was doing, and walked towards me. I gave the guy a sheepish smile, thinking that he was going to give me an admonishment. Instead, he took over to the keyboard and typed the following:
10 INPUT "What is your name ?"; A$
20 PRINT "Hello "; A$
30 GOTO 10
Finishing that, he executed the application, and asked me to type in my name:
What is your name ? Vincent
Hello Vincent
What is your name ?
That was the first time I saw code and I was immediately hooked. The guy gave me a smile and walked off with his girlfriend, leaving me to tinkering around the with application.

While there's really not terribly much that I could code without any more knowledge, but even with that limitation, I did try writing my own variation of the application based on the only 3 instructions I knew and wrote a really lousy version of a text adventure game that I got bored real quick.

It'll be a few more years before I got to learn more programming, but that was how I've learnt my first 3 lines of code.

So what's your story with your first coding experience?
Tuesday, September 18, 2007

Installing Flash for Opera

The instructions for installing flash on Opera seems to be a little bit lacking, given that the flash installer script seems to think that Firefox is the only browser that I have and refuses to offer me an alternative installation path.

The way to get around that is to manually copy libflashplayer.so into the /plugins subdirectory under Opera's root directory. ( Thanks to the guy in #opera@freenode who told me to look under Tools |Preferences | Advanced tab | Content | plug-in options | to find out where to stick libflashplayer.so )

It's not too difficult to install the flash plugin, just download it, untar the archive, copy libflashplayer.so into the subdirectory and you're done!

While Flash works, it does not seem like it's working completely yet. On my console, I've noticed a couple of error messages like the ones below, which seems to suggest that the plugin isn't working as intended:
(process:27461): GLib-GObject-CRITICAL **: gtype.c:2254: initialization assertion failed, use IA__g_type_init() prior to this function

(process:27461): Gtk-CRITICAL **: gtk_clipboard_get_for_display: assertion `GDK_IS_DISPLAY (display)' failed
Adobe FlashPlayer: gtk_clipboard_get(GDK_SELECTION_PRIMARY); failed. Trying to call gtk_init(0,0);
opera: Plug-in 27461 is not responding. It will be closed.
opera: Define environment variable OPERA_KEEP_BLOCKED_PLUGIN to keep blocked plug-ins.
On sites like YouTube and Yahoo Finance, Flash seems to work properly, even with the error messages shown, but on kongregate.com, most of the Flash game widgets will not load, where the only output is only a grey box, indicating that the plugin isn't running.

('top' showing ~90% CPU utilization for Opera)

Other times, visiting sites with flash content on Opera will cause a 90% CPU utilization, the culprit being 'operapluginwrap'. This seems to affect other plugins as well.

Opera 9.50 is still an Alpha version, so I'll give it a benefit of a doubt. Hopefully these issues can be resolved in the Beta stage, and definitely I won't want to see this in a 'release-candidate'. Hope that the issue will be fixed soon!
Sunday, September 16, 2007

Analysis of a Mail Scam

It is actually surprising that that actually a spam/scam phishing mail actually made it past Gmail's filter, given that I have only had a handful of spam mails making through out of the years I've had the account.

If that made through, I'm sure other people would have received the same thing as well, so it might be a good idea to share with others this information, lest someone gets their bank account broken into.

Besides marking out my email addresses with XXXXX, the entire body of the message remains the same:
Delivered-To: XXXXX@gmail.com
Received: from gmail-pop.l.google.com [209.85.163.109]
by localhost with POP3 (fetchmail-6.3.4)
for <XXXXX@localhost> (single-drop); Sat, 15 Sep 2007 13:30:05 -0700 (PDT)
Received: by 10.114.109.12 with SMTP id h12cs126573wac;
Sat, 15 Sep 2007 13:21:15 -0700 (PDT)
Received: by 10.100.46.19 with SMTP id t19mr4664427ant.1189887674970;
Sat, 15 Sep 2007 13:21:14 -0700 (PDT)
Return-Path: update@yahoo.com
Received: from mail.com ([76.224.245.158])
by mx.google.com with SMTP id i10si2529292wxd.2007.09.15.13.20.55;
Sat, 15 Sep 2007 13:21:14 -0700 (PDT)
Received-SPF: neutral (google.com: 76.224.245.158 is neither permitted nor denied by domain of update@yahoo.com) client-ip=76.224.245.158;
Authentication-Results: mx.google.com; spf=neutral (google.com: 76.224.245.158 is neither permitted nor denied by domain of update@yahoo.com)
smtp.mail=update@yahoo.com
Message-Id: <46ec3eba.0a87460a.1faa.47a0SMTPIN_ADDED@mx.google.com>
From: Bank Of America Security Team <update@yahoo.com>
Subject: *** Important Notice From Bank Of America Security Center ***
Date: Sat, 15 Sep 2007 13:21:16 -0700
MIME-Version: 1.0
Content-Type: text/plain;
charset="Windows-1251"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

We recently have determined that different computers have logged onto your Online Banking account, and multiple password failures were present before the
logons. We now need you to re-confirm your account information to us.

If this is not completed by September 17, 2007, we will be forced to suspend your account indefinitely, as it may have been used for fraudulent purposes. We
thank you for your cooperation in this manner.


To confirm your Online Banking records click on the following link:
http://76.225.156.194/verify/sslencrypt218bit/online_banking/


Thank you for your patience in this matter.

Bank of America Customer Service

Please do not reply to this e-mail as this is only a notification. Mail sent to this address cannot be answered.

2007 Bank of America Corporation. All rights reserved.
The parts highlighted in red is the ones that people should look out for. Firstly, Bank of America decided to send me a mail via Yahoo, how interesting. The second part, being that instead of linking to Bank of America's website, an IP address is used for this purpose. That's a giveaway that the server isn't legitimate.

Doing a reverse DNS lookup via 'host' yields the following information:
adsl-76-225-156-194.dsl.pltn13.sbcglobal.net
Isn't that interesting to find out that Bank of America has to rely on someone's home ADSL connection. sbcglobal.net is one of the America's Internet providers, so I assume this has originated from somewhere in the US.

Doing a 'traceroute' seems to confirm that it came from somewhere in the East Coast, possibly New York, and the machine is still up and running.

Well either the hacker is really dumb, or some poor guy's machine has been compromised and became an unwitting accomplice in a phishing scam attempt. If you are one of the few who has received any warning email from Bank of America, take note, and don't fall for it.
Saturday, September 15, 2007

Cscope with Vim for finding Java symbols

Cscope, like ctags, allow you to find symbols in your source from multiple files in your project easily. While it was originally developed for C (easily inferred by the name), the project has extended to cover a number of other languages as well, Java included.

Before you mistake cscope as a rehash of my tip on using exuberant-ctags, let me explain why scope is different. Cscope has semantic knowledge of the Java as a language, and understands when you are looking for a symbol (a variable or method definition), and other useful search functions, like finding out other methods that invoke method you want, or listing all the methods definition uses.

(Image of Cscope in Action)

The advantage of semantic knowledge is that when you are looking for a variable or method, you won't be sent to some uncharted parts of your code, such as within your comments, just because there is a piece of text that matches the name.

To use it with vim as the default editor, you'll have to set that in the environment in your shell (where the following is for bash) if it isn't set already:


export EDITOR=/usr/bin/vim


You'll need to generate a list of files for cscope to be able to generate cross references to. This is easily done by using the find command in the root directory where your java files are found:


find ./ -name *.java > cscope.files


cscope.files is the filename that cscope will read each time it starts up, so make sure you adhere to that.

There are ways to allow cscope to run within vim instead of the other way round, but while I managed to do it after a bit of experimentation, I did find that I've used it with cscope invoking vim more commonly, whenever I need to fire it up and look for the methods or variables that I want from time to time. Happy cscoping!

If you like reading this, you may also enjoy:
Friday, September 14, 2007

Opera 9.50 Alpha

I have just downloaded Opera 9.50 for a test run, because Opera 9.23 wouldn't render my blog's menubar properly. The good news is, Opera 9.50 has fixed up the problem already. At least it means that Opera 9.23 is the problem, rather than my CSS code :)

(Image of Opera 9.50 running on Linux)

While I have been a happy Firefox user for the last few years, using Opera has been more of 'the spur of the moment' event, after reading Slashdot.org's article about Opera's remarkable speed with respect to other browsers. While I wasn't not too keen on swapping browsers originally, I'm must say that I am pretty impressed by Opera's sleek user interface and it's high quality page renderings.

Although it is still a struggle for switching from what I'm used to, on the overall Opera is a pretty impressive browser, with some unusual features and capabilities that other browsers do not offer.

So for now I'm quite happy to give Opera a go, but it still remains to be seen if my preferences will stick in the long run.
Thursday, September 13, 2007

Hot Tech Gossips Heard Through the Grapevine

The things I've learnt about the Computing Industry today:

- That VMWorld is having a fantastic sellout with 10000+ attendees, each paying $1800 just to get into the event. At this number, it's more lucrative for VMWare to be an events company than trying to make money from selling software licenses.

- That the bad news is, Google's new data centre at North Carolina has cooling systems that spans an entire floor itself. The good news is, it's powered with hydro-electricity from some nearby dam. The bad news is, some hippie stood up in a conference moaning that Google is sucking up all water required for the hydro-power and killing all the salmons, maaaan. The good news is, well, it's probably unsubstantiated anyway. The bad news is, well, nobody really cares.

- That if Sun keeps giving software away to the open-source movement, they might as well change their ticker from 'JAVA' to 'FREE'. And while they are at that, they can start giving away their hardware for free too. At least they can make it all up with all the increase in volume.

- That Google is rumoured to have breached the 1 million machines mark with all their data centers combined. And that number is still growing, fast. Unfortunately, future growth will solely be limited by the moods of the delivery guys on a given day from now onwards.

Now that's a lot of heavy hitting disclosure from me within a single day. I'm seriously pushing it, man. Might even lose my job for disclosing them, you know?
Wednesday, September 12, 2007

Do not RTFM!

How many times have you ever been told to RTFM (Read the Fine Manual) when you got stuck with a problem? As a technically inclined person, even I myself find such responses unhelpful, especially when it propagates a snobbish, elitist attitude towards those who may be genuinely seeking help.

For most non-trivial problems, RTFM is probably the most time-consuming and least rewarding activity. Even worse, when the problem is truly cryptic, there is even a likely possibility that the manual will not have what you are looking for!

Unfortunately, the phenomenon of not finding what you want in the manuals happens more often than not in real life. Besides, the quickest way to learn something, is to ask somebody who already knows the subject matter well.

Most will be able to provide you with the right information straight on, or at least point you to the right direction to start looking. Just by knowing where to look will already massively reduce the time you'll spend scour at all the wrong places, minimizing unnecessary time loss from scanning through wrong documentation.

If you do not have the luxury of a friend who may know, Google is your next best friend. Querying a search engine will probably people who may have the same questions you have, and if it is widespread, generally someone will have posted up the solution out there.

If Google turns up with nothing, the next thing to try is to look out for mailing lists, IRC channels, or forums where you can locate people who share the same interests. Many will be helpful, and some will probably be experienced enough to give you an immediate answer to what you're looking for. Personally, it has been amazing to find out how much you can learn by just reading chatlogs of special interest group channels on IRC.

If there is one class of people who should be subjected to the RTFM treatment, it has to be the serial offenders who always leech onto you for help, even for the most trivial of things. For such situations, the RTFM is always an appropriate and recommended response:

"Read The F**king Manual!"
Monday, September 10, 2007

Coming out, then taken down

It seems like just within a day, there is a lot of buzz generated about a teacher from Raffles Institution, one of the top schools in Singapore. The major news is that he has came out of the closet, asserting his gay identity, but has promptly taken down his article shortly after.

But when the genie's out of the bottle, it's hard to put it back in again, as a search on Google's cache easily pulled out the original article. I believe he has his reasons to take down his post, so re-posting it will only fan the flames and not be helpful to his cause, so it won't be appropriate to give any links to the article in respect of his privacy.

I pretty much share the same views with Aaron Ng on this issue, and like him, I do have an aversion for gays. But this is well justified for, given that I've been 'picked up' by random gay men on the streets before, unsurprisingly. After all, I live in two of the largest gay cities in the world. Sexual assult by homosexual men is not unheard of.

But I am alright with gay people, just not with random sexual harassment from men. (Women who wish to do so are perfectly welcomed to :P) There is a broad distinction between homosexuality and sexual harassment, and we should not to blur those two issues together, and stigmatise them just because of their sexual orientation.
Saturday, September 08, 2007

Installing Internet Explorer on Linux

You've heard me right. I'm talking about installing Microsoft's Internet Explorer on Linux.

There is a pragmatic reason for this. Because of the incompatibilities and quirks that emerged between web browsers from the 'Browser Wars', the same HTML generated may be rendered in different ways among browsers, which is why it is still important to check across different browsers.

One thing to note is that Windows' native PE executable format will not work natively on Linux, so it is necessary to install 'wine', a software compatibility layer in order for you to run Windows applications within a Linux environment.

Rather than fumbling around trying to install Internet Explorer manually via wine, there is a better way to do it. ie4linux is a prepackaged installer that will automatically do for you. From my personal experience, I have found it to be a really great and hassle free way to install Internet Explorer automatically.


(A screenshot of my blog rendered with IE)

Unless it's wine that's causing a problem, people using IE really should consider switching, given that IE's text rendering looks abysmal. The font display doesn't seem to be anti-aliased and the jagged edges are pretty visible.

It also looks like I'll have to generate better IE-friendly CSS as well, given that it doesn't look exactly the way I wanted it to. (The menus are a little off to the right.) Besides that, I can't be sure if the lack of transparency for my icons are there because of wine or an issue with my CSS code, which is a little troubling.

I do recommend ie4linux to those who are concerned with browser cross compatibility, especially when you are not using the Windows platform. If you're reading this from Internet Explorer, do leave me a note if my icon's transparency is incorrect, so that I can try to see if I can do something about it.
Friday, September 07, 2007

The Dangers of Auto-boxing in Java

This is one of the those subtle bugs that I have unwittingly coded in because of the inherent laziness that is afforded by Autoboxing, a feature that was available with Java 1.5 onwards.

What auto-boxing means, is that Java will perform conversion between primitives to its Object equivalents and vice-versa for you automatically, rather than via the new() constructor way that you do traditionally.

However, because of the inherent non-obvious assumptions made, it can lead to subtle bugs that can be hard to spot. It did for me, especially when it was enmeshed in a part of a long stretch of code.

To give an illustrative example of the bug:


import java.util.*;
public class Test {
static HashMap<Integer,String> hm = new HashMap<Integer, String>();

public static void main(String args[]) {
byte b = 1;
hm.put(1, "Hello World");
String s = hm.get(b);
System.out.println("The result is: " + s);
}
}


As said, this example will only compilable with 1.5 and above, so take note if you want to compile it. Java will 'intelligently' determine the type of the primitive variable and turn them into objects for you, making it easier to use primitives with utility libraries such as java.util.HashMap. But if you run it, you're going to find that it is printing 'null' rather than 'Hello World'.

Caught the bug yet?

If you haven't, let me show you what Java has implicitly converted the code into through Autoboxing:

     ...
public void main(String args[]) {
byte b = 1;
hm.put(new Integer(1), "Hello World");
String s = hm.get(new Byte(1));
System.out.println("The result is: " + s);
}
...


I've shown the offending lines in blue. As you should know, Java objects of the same value but of different types are fundamentally not equal, i.e. Integer(1) != Byte(1). That is the sole culprit of the problem, which is being masked by using Auto-boxing.

That is a good reminder to look out and be careful of pitfalls like this, one which costed me 2 hours to find. Next time I'll think twice and look triply hard before relying on Autoboxing to do the right thing again!
Wednesday, September 05, 2007

The Story Behind My Ragged Schoolbag

This my personal story about a ragged little schoolbag I had with me for the last 18 years. Some of my friends may have seen me carrying it around from time to time, but probably didn't know that I had it so long, even less are those who knew the story behind it.

The bag was stolen merchandise, one of the things that mother had not paid for. That happened a long time ago, about when she was divorced. In those days, she had little education and no skills to provide for my brother and I. My father was a serial womanizer who had lost all his money and declared himself a bankrupt a few years before. That had exonerated him from all his responsibilities, to which he had not paid even a single cent of alimony till this day.

I can still recall vividly the day mum got caught stealing from a supermarket. I was only a child of 8 or 9 years then, as I remembered this woman walking up to mum and grabbed her by the arm. She didn't say much, merely uttering a single phrase, "You're coming with me", before towing her towards the to back of the supermarket.

The lady, a store detective, looked pretty stern, even though she did not look at me throughout the entire time. I had no idea what was going on and didn't understand why mum had not resisted, only seeing a defeated look on her face. That scared me and I began to cry, which had probably blown the detective's cover, given that everybody was staring at me while I sobbed, trailing behind them as they headed to the store office.

That was the first time that I realised that mum had stolen in order provide for us. All those Transformers, Mask, He-Man and Lego toys that I had, were stolen just to not make us feel deprived, all that, for her little boys who had meant a world to her. I felt guilty, even at that tender age, to learn that I was the reason for her crime.

I had not stop wailing even within the store office. There were a few people there, one of which was the manager who was sympathetic, seeing that she was a hapless mother with a child. They decided to let us go, but warned her not to do it again. They could have called in the police, which would have meant sending her to jail, and my brother and I, either into state custody, or of my father's, neither of which would have been a pleasant outcome.

The bag was probably the very last thing she had stolen from that period of her life. I do not remember if I had ever mentioned about not wanting her to steal anymore, but I had since consciously never asked her for anything frivolous, for the fear that she would have to resort to pilfering once again.

That is why I have kept this schoolbag with me, as a reminder to work hard, be frugal and be sensible with life so that we'll never have to be destitute again. Some people have mistakenly believed that I am a bloody cheapskate before, for not even bearing to replace an old tattered bag, a claim I readily admit, for I can never be sure how much it will cost to buy the lesson that came along with it.

If they only knew.