My Rambling Thoughts

Quote:

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Brian W. Kernighan

Quote:

If you ride a motorcycle often, you will be killed riding it. That much is as sure as night follows day. Your responsibility is to be vigilant and careful as to continue to push that eventuality so far forward that you die of old age first.

Unknown source

News:

Date: . Source: .

My Country, with love — or hate?

Today is Malaysia's national day. Just nice, someone reminded me of this controversial rapper from 3 years ago: namewee.

What was he infamous for? He composed a rap song called negaraku. Negaraku, I'm told, means "My Country". Of course, he didn't exactly spell it like that. (Anyway, you can search for it on YouTube.)

The rap song is pretty insulting, but you know what, it is the truth. If some parts make you smile and some parts bring a tear to your eyes, you know that you are still a Malaysian.

I'm sure every overseas Chinese Malaysian is torn between going home and wondering what's the point.

Home is where you grew up and there is just no place like home.

Code reviews, comments and asserts

programming

Code review

Code review is something everyone says is good, but nobody ever do — or do properly.

After doing a couple of code reviews after all the code was written, I now think we need to do some review earlier — as early as possible, before most of the code is written. When the code is done, people are not inclined to change it anymore. You find wrong assumptions, workarounds, hacks, inefficient coding and so on.

Recently, when I was listening to a colleague presenting his team's code review guidelines, something struck me: should we need to do code review at all?

Are we not trusting people to write code that is up to standards?

Here's something to think about: how about co-owners? Two or more people own a feature. They must care about the quality of their code. (If not, who else will?) They will feedback to one another from time to time.

If you are wondering, this is getting closer and closer to pair-programming.

Comments

I have almost never seen good comments. I don't write much comments myself, because I can read the code just fine. We are programmers — write code that programmers can understand. Keep it simple. Keep it short. Keep it readable.

One of my favourite quotes: if you need to write comments, you need to rewrite the code.

(This is not an excuse not to write comments. It just asks you to write simple code that does not need comments.)

Assert

Assert is not bad, but we have used it as a shortcut. Don't want to handle an error condition? Assert.

My manager mentioned something about it in his team meeting. I believe this is what he referred to: Go doesn't provide assertions. (...) Programmers use them as a crutch to avoid thinking about proper error handling and reporting.

But assert remains popular. Java started without asserts too. It was added in 1.4.

To assert or not?

Before you decide, ask yourself, why do some languages require it?

Why are we still using a language created in 1972 that has fixed-sized arrays? And worse — they don't even know their own length!

This language also only has rudimentary support for strings. Strings are nothing more than char arrays. But the really flawed design is NUL-terminated strings. It makes it so easy to overrun buffers.

Round in your favour

transport

In Mathematics, rounding is pretty fair. >0.0 to <0.5, round down, else round up. It is 50-50.

(Not that rounding is simple topic. There is a banker's rule that is fairer for finance-related transactions. It can be strange the first time you see it.)

But it can be gamed if you can control the input: you can make it round up or down in your favour.

For example, Shell rounds the litres pumped when converting to its Shell points. 1 litre = 1 point and points are whole numbers.

So what happens when you pump 0.499 litres? (They track to 3 decimal places.) 0 points. 0.500 litres? 1 point.

One person gaming the system is insignificant. If you pump once a week (double UOB SMART $ on Sunday for a limited time only), you are only going to get 52 extra points per year.

(Unless you pump multiple times per day. Hmm, that's an idea! :devil:)

You can use 600 points to get a $20 petrol voucher. Not all redemptions are equal; that is another topic.

Many drivers gaming the system, however, is more serious.

Is this the face?

"Is this the face that launch a thousand ships?"

Trust me, you don't want to hear the next three cheesy lines.

Some poems are better said on the beach, amidst howling winds and growling waves — and a dose of strong liquor.

What is 'ideal'?

News: Why settle for less than your ideal?

Date: 22 August 2010. Source: ST.

I don't want to settle for 'just good enough'.

I don't want to fall for just anyone or make exceptions simply to get hitched.

But it seems that that is exactly what young adults of my generation are being encouraged to do, at least according to the latest Ministry of Community Development, Youth and Sports (MCYS) campaign to try to get young singles to date.

Although the campaign is still in its planning stages, the tender for a communications agency to design the campaign made the suggestion that young adults 'moderate' their expectations of a partner.

But I don't want to fall for anyone less than ideal.

The words 'ideal' and 'perfect' are loaded. Needless to say, she was criticised left and right for it.

Also, the word 'compromise' is so bad that even the mere mention of it suggests that your date/partner is sub-standard.

In the real world, there is no 'ideal'. Everyone has some flaws. We have to accept that. This is not compromising. Nor is it trading off. It is just accepting the bad with the good.

Update: there are two things you definitely give up. Time and freedom. :lol:

Will blog for food

News: Food blogger who demands free meal sparks outrage online

Date: 23 August 2010. Source: Yahoo News.

A young food blogger who demanded that he and his three companions be given free meals at an upscale restaurant in the Joo Chiat area has sparked a huge furore online.

The group of four had walked into Private Affairs, a small but exclusive eatery in Joo Chiat, for its Sunday champagne brunch promotion that costs S$68++ per person.

Wah, I didn't know bloggers can eat for free. Hey, I'm a blogger too! :lol:

Update: the blogger has come out to present his side of the story. Still, I think the damage is done. From hero to zero just like that. I bet he thought only he could make or break other people through his reviews, and never thought he would be subjected to the same rules too.

What kind of service is this?

I went to my sort-of regular workshop to change oil and to look at my window problem.

First, they charged me for servicing, even though I said up-front I only wanted to change oil and oil filter.

Okay, fine.

When I drove back, I found that a small plastic cover was gone from my arm- rest. (It covers a screw that opens the door panel.) I called to ask about it. The mechanic denied seeing/losing it.

Well, I am very sure the cover was there because I took the door panel apart just a few days ago and I put it back.

I'll be a fool if I go back.

A "nice guys" rant

News: What happened to all the nice guys?

Date: 19 November 2007. Source: online.

I see this question posted with some regularity in the personals section, so I thought I'd take a minute to explain things to the ladies out there that haven't figured it out.

What happened to all the nice guys?

The answer is simple: you did.

See, if you think back, really hard, you might vaguely remember a Platonic guy pal who always seemed to want to spend time with you. He'd tag along with you when you went shopping, stop by your place for a movie when you were lonely but didn't feel like going out, or even sit there and hold you while you sobbed and told him about how horribly the (other) guy that you were ****ing treated you.

No idea whether it is true or not, but it makes a fairly good read. :-)

The other reason why Oracle sues Google over Android

programming

News: Why Oracle was right to sue Google

Date: 19 August 2010. Source: InfoWorld.com.

Oracle's Android lawsuit is just the first step in the long-awaited resurrection of the Java platform

The tech industry loves a good vendor slugfest, and the upcoming legal battle between Google and Oracle has all the makings of a truly spectacular one.

The first reason is of course to get royalties. Oracle is very profit driven. Its products are large, slow, require massive hardware to run — and very expensive.

And this is the reason why you should own your core assets — no matter the cost — so that you are not held hostage by someone else.

Java is past its time. Its syntax is atrocious, it is slow and it never lived up to its promises. If it weren't for large expensive servers with too many cycles to burn, Java would have been long laughed out of town. As for client-side Java apps, when was the last time you saw them?

And with Android as its competitor, Java ME (Micro Edition) is essentially dead.

(You can probably tell I don't like Java. :lol:)

But what will replace it? Unlike the author, I believe Google will use JavaScript. Who uses Go outside of Google?

JavaScript may seem an unlikely choice, but it is not. Augmented JavaScript can be typed and compiled.

JavaScript is the dark horse everyone underestimates.

It works differently when you are rich

finance

News: Local businessman loses $26m at RWS casino over 3 days

Date: 18 August 2010. Source: TodayOnline.com.

In what is said to be one of the biggest losses yet at a Singapore casino, a local businessman lost $26.3 million over three days of gambling in June. This included a staggering $18 million that he burned in one day alone, playing baccarat - a card game - at $400,000 a hand.

According to documents that Today has obtained, the businessman's tale of woe began in March, just weeks after Resorts World Sentosa (RWS) opened, when he was granted a credit line of $500,000 by the casino.

Lose already sue. Win how? RWS sue him?

To burn $18 million at $400k a hand, it takes just 45 straight losses. I guess he played some 60 to 90 hands.

Latest news: Jay Chou lost $2 million when he came here for his concerts. I hope he didn't lose form.

Depending how you look at it, he'll be back more often or he won't come back again!

The Lost Decade

News: HP Is Falling Apart

Date: 16 August 2010. Source: TheMotleyFool.com.

When Mark Hurd left the CEO chair of Hewlett-Packard (NYSE: HPQ) (or was forced out of it, depending on your sources), it was easy to panic. Hurd is, after all, widely credited with bringing fiscal responsibility and a new lease on life to the previously floundering tech giant.

You can go on and panic, but not over losing Hurd. The problems with HP run much deeper than that. The whole mess isn't Hurd's fault — but a lot of it is.

There will be a lot of pain in the path ahead.

Two comments: (i) HP is too big as a single company, (ii) it has not have a breakthrough product in years — if ever.

Downloading from a ratio tracker

Some trackers require the client to maintain a decent upload/download ratio.

The problem is that there are usually many seeds and few leechers. (This is opposite of free-for-all trackers.)

This is very well when you want to download, but it is not so good if you want to maintain your ratio. (Or you'll find yourself banned after a while.)

Trick: find a torrent that has a good leechers-to-seed ratio, preferably with multiple files. Download just one file inside. When it is done, you'll switch to seed mode and people will start to download from you. You can maintain your ratio easily this way.

Time to reflect

Do not confuse what is urgent with what is important.

Unknown source

A suitable quote for busy people who claim they are tied up 24/7.

A 24" LCD monitor vs a 32/42" LCD TV

finance

A 24" LCD monitor costs $330, a 32" LCD TV $700 and a 42" TV can cost just $1,400.

A TV is more worth it, but the problem in Singapore is that you got to pay the annual TV license of $110. Is it a big deal?

Somehow, it just annoys the hell out of me.

(How much TV did I watch in the past three months? How about zero?)

Planning for a diskless media player

With the Atom server up and running (although not 24/7 yet), I am now considering to build a separate media player.

This time, I will use a mini-ITX casing. :lol:

I also plan to run the PC entirely off the USB flash drive. It will be entirely diskless and get its files over the network.

A 4GB drive should be sufficient, but that is not what I'm worried about. Rather, I don't want to hit the flash write limit.

Some advice:

  • Use ext2 instead ofext3. Journaling writes to the partition.
  • Mount with the noatime flag.
  • No swap. This means at least 2 GB RAM.
  • Put these on tmpfs:
    • /tmp
    • /var/tmp
    • /var/lock
    • /var/log
    • /var/run
  • Edit /etc/fstab to enable async I/O. This will corrupt the flash drive if not unmounted properly, though.
  • Set vm.swappiness=30 in /etc/sysctl.conf. Lower = prefer to keep code rather than data in cache.
  • Set vm.vfs_cache_pressure=50 in /etc/sysctl.conf. Lower = prefer to keep inode/dentry in file cache.

It's that simple. Now, I just need a PC to give it a try. :-D

Expected budget

Atom D510 w/ ION2 $200
2 GB RAM $65
Mini-ITX casing $80
4 GB USB drive $13

$358. Time to save up!

What can the Atom do and not do?

The Atom D510 is dual core and both cores are hyper-threaded (HT). That means it appears as 4 CPUs to the OS.

Don't be fooled, though. It is still slow.

Also, HT is not a full processor, but around 20% of one. There are really only two main CPUs and two auxiliary ones.

When viewing the unified CPU usage, it is usual to see <20% CPU usage. However, the system is already starting to get loaded. It follows that 50% usage is really almost 100%.

What Atom D510 can do:

  • File server
  • Bittorrent
  • Surf net
  • Play MP3
  • Play DVD (MPEG-2)
  • Play 720p MPEG-4 videos

What Atom D510 cannot do:

  • 3D games
  • Play 1080p MPEG-4 videos
  • Encode videos (any sort); too slow

Basically, the Atom D510 is good for low-powered apps, but it is extremely poor at CPU intensive apps.

An Atom Server boots!

I decided to run Ubuntu (server edition) on my Atom PC. Installation took a while, but was smooth all the way.

The server is pure CLI, but it is apparently easier to install the desktop on it than the other way round:

sudo apt-get update
sudo apt-get install ubuntu-desktop

The Atom server boots up in 10s — from pressing the power button. This is the fastest boot time I have seen. Even my phone takes 30s to boot!

Partitioning

I allocated 20 GB to /, 2 GB each to /var and /tmp, 1 GB to swap and the rest (900+ GB) to /home.

20 GB seems an overkill for apps on a server, but who knows what I'll install in the future?

/home has quota enabled and has the atime flag turned off.

Apps

The apps I require are: SSH, VNC, Samba, Apache, PHP, MySQL and SVN.

I also installed Desktop, Transmission (a BitTorrent client; comes together with the desktop?) and Xchat (IRC client).

(I don't IRC, but I sometimes get files using DCC, so that's what the client is for.)

I added a script to start a VNC server on startup. SSH into the server to start it manually every time gets old pretty fast.

Slight hiccup

I have no sound.

After following online troubleshooting guides and troubleshooting for a couple of hours, I had a flash of inspiration: will root work? It does, so it is a matter of permission!

I'm very surprised I can't play audio by default.

I added myself to the audio group:

usermod -G audio myuserid

All is well, until I needed to run sudo. I could not do it anymore.

It dawned to me after a while: usermod must have removed it! The correct command to issue is,

usermod -G audio -a myuserid

(-a indicates append.)

I have to add the original groups back.

Except sleep/hibernate

The PC can't sleep nor hibernate. I know I made a mistake in the swap (swap partition must be >= memory), but the PC can't sleep too.

No big deal for now. I will figure it out eventually.

Do I need the GUI?

Surprisingly, no. Multiple SSH sessions work just as well, and they are much faster. VNC lags quite a lot. It is much slower than what I experience in office.

What can you do with an Atom PC?

Atom CPUs, designed for small footprint PCs, are very suited for two things: as a file server and for media playback.

I looked at 3 common Atom configurations:

  1. Atom D510 1.66 GHz w/ integrated graphics (GMA 3150)
  2. Atom D510 w/ ION2
  3. Atom N330 1.6 GHz w/ ION

Atom by itself is too slow for MPEG-4 video playback, even for the newest Atom D510. Config #1 can only be used for server.

There are some M/Bs with a PCIe expansion slot that allows you to put in a dedicated graphics card. However, config #2 is a more sensible choice.

Do we need ION2 for media playback? No. The previous gen N330, when paired with the Nvidia ION graphics processor, can decode even 1080p videos.

The only downside is that ION M/B is a little more expensive and uses a bit more power — a concern in a server.

Combined server/media playback?

Initially, I wanted a combined server/media playback solution. However, later I realized they are somewhat at odds.

A server requires at least 2 HDs, so it needs a large power supply. A media playback device is small and can fetch its files remotely.

Thus, I decided to go for a pure server solution.

Other thoughts for an Atom PC

I got the MSI Win Board D510 which does not come with HDMI and DVI ports. I'm fine with VGA, but media playback usually wants HDMI. Note that Intel currently restricts HDMI to 720p.

Some mini-ITX M/Bs are fanless. Some are not. The MSI Win Board D510 has a CPU fan, but it is very silent. (I thought all Atom D510 M/Bs were fanless, but I was wrong.)

First step to a 24/7 server

I am rapidly running out of backup storage. But rather than getting yet another external USB drive — I have too many of them — I want the storage to be on the network so that there are fewer restrictions how I can access it.

I want the server to be running 24/7, so I want something power efficient: Atom.

What I got:

MSI Wind Board D510 w/ Atom D510 (1.66 GHz) $160
Kingston 2 GB RAM (800 MHz DDR2 CL5) $65
Seagate Barracuda 1 TB HD (7200 RPM, 32 MB cache) $101
In Win BK 644 Micro ATX tower (300W) $100
SanDisk Cruzer Blade 4 GB $14

For a total of $440.

Some notes:

  • There is no monitor, keyboard and mouse as I intend to run the server "headless". I will borrow them to install the OS. Once it is up, I can access it remotely via SSH or VNC.
  • The Atom CPU+M/B is cheap, but not that cheap. I can get the Intel 2.7 GHz E5400 CPU with the MSI G31TM-P35 M/B for just $166. That is much more powerful.

    The ATOM CPU+M/B advantage: it uses much less power than a C2D CPU, and it has a ultra compact 17x17 cm mini-ITX form factor.

  • 1 GB of RAM should be sufficient, but I got 2 GB for some headroom. I may need to run Windows if I fail to install Linux on it. :lol:
  • I overlooked the need to get a power supply! The cheapest one is around $30, but a micro-ATX power supply around $70. At that price, I'll rather get a casing — reluctantly. My main objection is that the server's footprint becomes very large! From 17x17 cm to, say, 41cm (L) x 20cm (W) x 41 cm (H).
  • I got a small micro-ATX casing as mini-ITX casings are hard to find.
  • The flash disk is to install Linux without a DVD-ROM drive.

What I can do better

I overlooked that mini-ITX boards are not very popular. There are only a few to choose from. The shop recommended by my colleague did not have the M/B I wanted. I asked around before I found the MSI Wind Board.

I overlooked the need to get a power supply!

I also overlooked that mini-ITX casings are hard to find, and that they are pretty big too — a generic mini-ITX casing is almost indistinguishable from a small micro-ATX casing.

Custom build casings (with a complete Atom-based PC) are much smaller. Imagine your router. That is how it should be.

How do they do it? By using something like a picoPSU, which adapts a 12V power adapter to the ATX power connector.

What does 3 Mbps mean in real terms?

3 Mbps is around 375 kB/s. It may sound very slow, but it is a pretty decent rate. (In contrast, local network speed is ~5 MB/s and HD is ~20 MB/s.)

It is fast enough to play YouTube's 480p videos in real-time. (But not the 720p videos, though.)

A 7 GB 720p video can be downloaded in ~5.5 hours. However, I can't hit >350 kB/s all the time. Even 200 kB/s is a decent rate. It translates to 11 MB/min. A 7 GB file can be gotten in 10 hours (or overnight).

This is why I have opted for the 3 Mbps data plan for the past few years. It is one of the cheapest plans and it is good enough.

Programming Android, first thoughts

programming

It reminds me of Windows GUI programming in early 90s before GUI RAD tools, such as Visual Basic and Delphi. There is a ton of boilerplate and glue code.

(And also X Windows and later Java Swing/AWT. History repeats itself every 10 years.)

The good news: App Inventor for Android is going to be released by Google, and that is apparently a drag-n-drop GUI app builder.

No one should need to create a GUI app using code.

Simi Youth Olympic?

News: Singaporean set up Facebook to boycott Youth Olympic Games

Date: 25 July 2010. Source: The Temasek Review.

A Singaporean by the name of Kelvin Leong has set up a Facebook to boycott the Youth Olympic Games hosted by the PAP regime. It has attracted more than 100 members so far.

According to Kelvin, it was founded to protest against the PAP's splurging of public monies on the YOG:

"We are Singaporeans who are disgusted with the YOG. The government initially allocated a budget of $120 million but it somehow shot to $387 million. At the same time, the government is not bothered at all to spend a single cent to fight the raging flood problems that has caused untold hardships on the people."

Summer Olympic, Winter Olympic, Special Olympic. Now Youth Olympic?

To tell the truth, I've never heard of the Youth Olympic, so I googled it. It turned out this is the first ever Youth Olympic.

Will Youth Olympic work? I am skeptical.

Life is a one way arrow

News: When Mr Right comes at the wrong time

Date: 25 January 2005. Source: ST.

Timing is everything, even in love. And when you are not ready to commit, you could end up regretting it

SOMETIMES, timing rather than love decides who we end up being with - or without.

Only some lucky people marry the loves of their lives. The rest marry the most suitable person who comes along when they are ready to settle down.

Janice Wong (the article author) regretted her decision. However, I think she didn't make the wrong decision — it is hardpressed to ask someone to settle down at 23.

It was her misfortune not to meet anyone of the same calibre since...

But, she was just 28 when she wrote the article (5 years ago). That was not old enough to say she'll never meet a new Mr Right again.

Anyway, her article intrigued me enough to borrow her book, Single Picky Girl. (I was too cheap to buy her book for $15 :-P.)

Her articles work well enough as a newspaper column, but lack depth in a book.

Putting $36,000 COE into perspective

The 2nd July COE bidding ended with Cat A at $36,162.

$36,162, what does it mean?

Per year: $3,616.20. Per day: $9.90.

Almost $10 a day to own the car, even before you use it.

Rain means flood

News: Floods hit S'pore again

Date: 17 July 2010. Source: ST.

HEAVY rains lashed Singapore early on Saturday morning, uprooting trees and causing flash floods in many area.

The affected areas included Braddell Road, Changi Road and Bukit Timah, where rising floodwaters stranded several drivers in their vehicles.

Nowadays, a prolonged heavy rain means flood. This has not happened since the early 90s. There is something wrong with Singapore's drainage system.

North East on a bike

Key places: Old Thomson road, Bottle Tree Park, Yishun Dam, Seletar Airbase, Seng Kang, Punggol, Punggol jetty, TPE rain shelter, Pasir Ris Park.

Charging by distance

transport

Singapore changed to "distance fare" on 3 July 2010. It is fairer in theory. It is also supposed to be cheaper for 2/3 of the commuters. But there has only been one feedback since then: fares have gone up.

I could take a direct bus to office for $1.40. It now costs me $1.61. The website also cheerfully tells me I'm paying for 18.3 km.

What has gone up:

  • MRT fares have gone up
  • Long distance trips have gone up

The new fare now favours commuters who take bus and MRT trip. A colleague told me his MRT trip is now $1.82 instead of $1.60. However, his bus trip is just $0.02!

I suspect LTA did this to encourage people to live further away from MRT stations. Previously, it is best to take only MRT or a direct bus.

Good sales for YOG or not?

News: MOE buys 80,000 YOG tickets for all schools

Date: 26 May 2010. Source: ST.

STUDENTS in Singapore will be out in full force when the Youth Olympic Games (YOG) hits town in August.

The Education Ministry (MOE) is buying 80,000, or a quarter of the available tickets, for students from primary schools to junior colleges to watch both preliminary and final competitions during the Aug 14 - 26 event.

The ministry declined to say how much money would be spent on the tickets or whether there had been any concessions given.

News: YOG tickets selling fast

Date: 7 July 2010. Source: ST.

IF YOU want tickets to catch the Youth Olympic Games, you will have to act fast.

Ticket sales to the first Youth Olympic Games have been brisk, with more than 100,000, or close to 50 per cent of tickets, having sold out.

Unlike many people, I do believe the ST reports the truth. However, you have to pay attention, read between the lines and think for yourself.

Play down bad news: MOE bought 80,000 tickets. It is okay because that is just 25% of the total tickets.

Play up good news: more than 100,000 tickets, nearly 50%, sold.

When you compare the two figures, you'll quickly realize the true sales is just 20,000+ tickets! That is dismal.

True love or misguided love?

News: Widow found dead at block

Date: 5 July 2010. Source: ST.

THE widow of bridegroom Vernon Leong, who mysteriously fell to his death from the Hilton Hotel on the night of his wedding last November, died early Monday.

Ms Kerin Peh, 27, is believed to have jumped from the block where her family lives at Hougang Ave 8. Paramedics who arrived at the scene around 2am, pronounced her dead.

Last December, she also tried to take her life by slashing her wrists at the home of her parents-in-law in Balam Road.

Friends of the couple said then that Ms Peh had been an emotional wreck after her husband's death, and family and friends had had to keep close watch over her.

God give me the strength to go on in times like this.

(I am not a religious person, but in times like this, I do pray.)

This is a tragedy indeed.

Beyond KL

transport
KL Planetarium Space Theatre

A place in KL that transports you beyond KL.