Why Ruby

Posted in Ruby by sausheong on June 30, 2006

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

Posted in general, Ruby by sausheong on June 28, 2006

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!


Posted in general by sausheong on June 27, 2006

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.


Posted in general, Ruby by sausheong on June 19, 2006

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

Lost connection to MySQL server during query problem

Posted in Rails, Ruby by sausheong on June 13, 2006

For a while I got this error message : “Lost connection to MySQL server during query” which was pretty irritating as it randomly works or not work. Apparently it’s an issue with the MySQL adapter in Ruby and there are a couple of fixes for it.

Some explanation from the Rails wiki

This post from Roderick explains it well for Windows and it worked pretty well for me.


Get every new post delivered to your Inbox.

Join 454 other followers