Why Ruby

When I talk Ruby (the programming language – duh) to some people, I’m often asked — what’s so good and different about Ruby? It’s normally quite hard for me to be articulate and yet not sound like a fan-boy, so I’m often annoyed when I can’t explain it too well.

That’s what blogs are for.

I’ll just write down a couple of things at the top of my head that I think is really cool about Ruby. This is totally unstructured and there’s plenty more of really cool stuff, but these are some that stuck to my mind.

First is that everything is an object. So something like this can be done:

3.times do
p "something"

which loops and prints “something” 3 times. How cool is that?
Another one, slightly more elaborate:

solution_architects = ['Oscar', 'Ravi', 'Jimmy', 'Gnani', 'Andrew']
lab_managers = ['Bernard', 'Pierre', 'Thomas']
person = "Oscar"
case person
when *solution_architects
p "Come up with a good solution!"
when *lab_managers
p "Manage the team well!"

This prints ount “Come up with a good solution!” No more mucking around with looping around to check if the array contains an object.

Last one, from the Pickaxe book, which needs a bit more explanation:

def fibonacci_up_to(max)
i1, i2 = 1, 1        # 1
while i1 < = max
yield i1 # 3
i1, i2 = i2, i1+i2 # 2

fibonacci_up_to(1000) { |f| print f, " " }  # 4

What did I just do?

  1. #1 – parallel assignment, very brief, very understandable
  2. #2 – again parallel assignment, notice that I can do a variable swap without messy temporary variables – yuck
  3. # 3 – yield is a special keyword that allows me to pass entire function blocks to a method!
  4. # 4 – passing the function block, within the curly braces ‘{}’

Think again — you can pass function blocks to a method! Not just miserly variables but true-blue blocks of code!

How cool is that? Now I’m really repeating myself.

Minor bugfix for ScreenSvr

Thomas fixed a small (and silly) bug in ScreenSvr last week and I just managed to recreate a new installer based on it. I had all the settings to change the timing of the configuration, but I forgot to include it in the data generator! *Smack forehead* Thanks Thomas!


I was at Porquerolles last week for a team-building exercise with the team in France. Porquerolles is an island off the southern French Mediterranean coast, the biggest of the three islands of Or in the Hy√®res gulf. It’s a beautiful island with fresh sea breeze and a simple idlyic quaintness to vilage and the port. The beaches are pretty in a pictureque sort of way and the sun sets lazily over the peaceful red dusk that lulls you into an easy sense of calm and tranquility. Holiday makers from all over France and Europe make their annual summer pilgrimage here, simply to lie on the beautiful sandy beaches of Plage d’Argent with a book in hand and suntan lotion on the back, with the more adventurous mountain biking the various trails leading across the island or sailing the sapphire blue seas with sailboats of all sizes.

Porquerolles beach Porquerolles port Porquerolles port in the evening

The team-building exercises were interesting but what was more memorable was the short insight into a different lifestyle from the one I’m used to in Singapore. Maybe we do miss out on what really matters in life — to enjoy it and live it.


This is a Windows screensaver I wrote over the weekend.

The idea now is to go to Flickr, grab their photos and run it through as a screensaver on your Windows PC. Nothing really fanciful, simple clean functions. I’m thinking of doing a full page write-up on how I did it step-by-step but it’ll probably have to wait till I have more time. But here’s roughly what I used:

  • Internet Explorer (generally)
  • Ruby (programming language used)
  • Javascript (the slideshow)
  • Flickr REST APIs
  • Tar2RubyScript and RubyScript2Exe
  • Autohotkey
  • NSIS

Quite a gamut of technologies, but that’s that. This is the end result. DOWNLOAD THIS. It’s a bit big though.


  1. Install it (download and click click click)
  2. Open up your Windows screensaver tab (usually right click, select ‘Properties’ and click on Screen Saver)
  3. Click on the combo box and scroll until you see ‘screensvr’
  4. Click on the ‘Settings’ button
    • You will see a list of configurations. You can normally ignore the slideshow timings though. What is interesting is the username and the search text.
    • Username allows you view all the photos from this Flickr user
    • Search text allows you to find all photos based on the search criteria you have (if used in combination with username, it will search photos for that user, otherwise, it will search from Flickr in general)
    • If you don’t put anything in either, it will just get the most recently submitted photos from Flickr (and ignore the sorting criteria)
  5. Click on ‘generate data’ to generate the data for your screensaver. This might take a while as it will need to go to Flickr and grab the photos
  6. Close the configuration dialog box, and click on ‘Apply’

You’re set to go!

Drop me some comments on this. I’m releasing the source code under GPL. I’m releasing this under RubyForge at http://screensvr.rubyforge.org

World Cup starts tomorrow!

World Cup will be starting in 22 hours time! Although it’s terribly commercialized, but football is football. I think enough people still love the beautiful game. I compare football to programming actually. Both needs experience, flair and a certain passion, and a good piece of code just like a ball well passed and well scored is a marvel on its own. On the flip side, sadly sometimes it doesn’t matter if you have the best skills or the best code, but it’s the scoreline or the final deliverable that matters. No matter if you dived to get a penalty or scrapped by a lucky goal, a goal is still a goal and a match win is all that matters. No matter how well you code, it’s the final product that still matters. You might have coded extremely well but if your software fails to deliver the functionalities, it’s still a failure. You still lose the match.

Still. Not all is lost.

Maybe I’m idealistic but good code is like football well played. It’s not just the accolades you get, but the deep down satisfaction that you have done it and you have done it well and with flair and style. The feeling that you have snubbed the opposition in his face, there you go, take that! The rush and thrill of creating something out of nothing, that you have fought entropy and all its minions dragging you down, and you have won. Something is born, you give life to a piece of code that maybe struggled when it was first born, but the wonder and amazement of creation, still.

Over dramatic? Yah. I suppose it’s the same rush some people get jumping off planes or off buildings with rubber bands tied to their feet. But weird though. I can be such a geek sometimes. Oh well.

Space invaders update

I’ve been bad. I’ve neglected my Space Invaders project for the past few weeks though I did manage to get up to the part where I have a laser shooting out bullets at an array of invaders that bounce off the left and right walls of the screen. They don’t explode yet though — haven’t done the collision detection bit yet.