Writing asynchronous JavaScript

This library — async.js — is excellent in writing asynchronous JavaScript. It’s one of JavaScript’s strengths and it’s only that often get really messy.

In my use case, there are a several data sets to fetch and populate into graphs. One way is to perform a for each loop and just AJAX requests to get dataset from the web server and adding it one by one. But why do that when you can do so asynchronously. Ideally, all sets of data should be downloaded at the same time and not one after another. Some data sets are larger than others and will take a longer time to complete, so we can always add the completed sets into the graph first.

With that library we can do something like:

[code language=”javascript”]
async.map([‘url1′,’url2′,’url3’], getUrl, function(err, results){

});
[/code]

I’ll write more as I explore. Really nice library if you’re looking to do more than jQuery’s Defered.

WordPress cannot resize uploaded images?

Just encountered an issue where WordPress cannot resize my uploaded photograph to thumbnail, small or medium. All the radio buttons are grayed out but the full size option.

This is due to a certain module not installed. If you are using Ubuntu:

[code lang=”bash”]sudo apt-get install php5-gd[/code]

If you don’t have access, you might have to advise your web host to do so.

GD library is a simple image processing library used by WordPress to perform resizing and cropping.

Spider-Man spotted at NUS library

Always nice to see Spider-Man again.

Was mugging (studying) in school during study week as usual and this happened at around 130am.
Is this a NUSSU (student union) ‘event’ or is it some idiot trying to play the fool… or is it really SPIDEY???? 😛 See for yourself. Whatever it is, it was cool to relieve some of the stress from us muggers.

Spiderman spotted at NUS central library 23/04/09

[via Daryl Li]

Writing silly introductions in books

I was browsing through some Java books at the Choa Chu Kang library yesterday. Yes it’s boring I know. One of the top I was intending to read up on was Java Swing. I have to implement some Java Swing stuff at school and I, for the 217067th time, do not like Java.

My complaints aside. I chance upon this really thick book – you know what they all say about thick books – The Definitive Guide to Java Swing.

The Definitive Guide to Java Swing book cover

And I flipped to the first few pages, probably the introduction. And yes, I always read prefaces and introduction. I felt that understanding the author’s background and intent for writing a book is important. It helps you deciding on book purchases too.

Here’s what The Definitive Guide to Java Swing has to say about Java:

About Java

Java is one of 13,000 islands that makes up Indonesia, whose capital is Jakarta. It is home to about 120 million people with an area about 50,000 square miles (132,000 square kilometers). While on the island, you can hear traditional music such as gamelan or angklung and enjoy Java’s main export, a coffee that is considered spicy and full-bodied, with a strong, slightly acidic flavor. The island also has a dangerous volcano named Merapi, which makes up part of the Pacific “Ring of Fire.” In 1891, on the island, Eugene Dubois discovered fossils from Pithecanthropus erectus, better known as Java man (homo javanensis).

The Definitive Guide to Java Swing about java

(The Definitive Guide to Java Swing about java.)

Pretty funny way of writing an introduction. Since most people who is going to read a non-beginner Java book, there’s no need to include an introduction on Java anyway.

Unfortunately the book’s learning curve is too steep – I am a beginner.

No one needs to buy Tuesdays with Morrie

My friend wanted to get Tuesdays with Morrie because he hears it’s a good book. Well, you don’t need to buy it. This is the amount of Tuesdays with Morries you can find in the national library:

I took this is Jurong Regional Library by the way. Sometimes you don’t really have to buy books. Save a little, get them from the library. (And spend the money buying food.)