A commenter rightly complained that despite my claims of “playing around” with node.js, all I could come up was with the example in the man page. I replied saying that I did intend to post something that I wrote from scratch, and as promised, here is my first toy node.js program:
var sys = require('sys');
var http = require('http');
var url = require('url');
var path = require('path');
function search() {
stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function(term) {
term = term.substring(0, term.length - 1);
var google = http.createClient(80, 'ajax.googleapis.com');
var search_url = "/ajax/services/search/web?v=1.0&q=" + term;
var request = google.request('GET', search_url, {
'host': 'ajax.googleapis.com',
'Referer': 'http://floatingsun.net',
'User-Agent': 'NodeJS HTTP client',
'Accept': '*/*'});
request.on('response', function(response) {
response.setEncoding('utf8');
var body = ""
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
var searchResults = JSON.parse(body);
var results = searchResults["responseData"]["results"];
for (var i = 0; i < results.length; i++) {
console.log(results[i]["url"]);
}
});
});
request.end();
});
}
search();
This program (also available as a gist) reads in search terms on standard input, and does a Google search on those terms, printing the URLs of the search results.
I was quite surprised (and a bit embarrassed) at how long it took me to get this simple program working. For instance, it took me the better part of an hour to realize that when I read something from stdin, it includes the trailing newline (as the user hits ‘Enter’). Earlier, I was using the input as-is for the search term, and that was leading to a 404 error, because the resulting URL was malformed.
Debugging was also harder, as expected. Syntax errors are easily caught by V8, but everything else is still obscure. I’m sure some of the difficulty is because of my lack of expertise with Javascript. But at one point, I got this error:
events:12
throw arguments[1];
^
Error: Parse Error
at Client.ondata (http:881:22)
at IOWatcher.callback (net:517:29)
at node.js:270:9
I still haven’t figured out exactly where that error was coming from. Nonetheless, it was an interesting exercise. I’m looking forward to writing some non-trivial code with node.js now.






The San Francisco Taiko Dojo
My wife and I had been thinking about learning Taiko, so after some quick Googling, one fine Tuesday we dropped in at the San Francisco Taiko Dojo to “observe” the adult beginners class. We only stayed the first hour or so, and it was interesting to say the least. First, there was the intimidating workout: everyone was counting in Japanese; the workout included sets of 60 pushup, situps, scissor kicks and tricep dips! And then there was the class itself — there seemed to be no “orientation” for beginners or a structured way to learn the ropes; everyone there just seemed to know what they were doing; there seemed to be a lot of understood etiquettes — there was an expected way of doing pretty much everything. Suffice to say that we decided to start classes the following week.
BTW, if don’t know what Taiko is or have never heard Taiko, I refer you to the mighty Wikipedia and the mightier YouTube:
I’m on a temporary hiatus from Taiko right now, but I had an amazing experience the few months I spent with SF Taiko Dojo.
Yes, there are rules and etiquettes. But in a society where anything goes and freedom rules and any kind of “discipline” is often frowned upon, SFTD was almost refreshing. In many ways, it was reminiscent of the Gurukul system in ancient India.
Taiko itself is a wonderful art form. There is something powerful about a Taiko performance. A single drum is an excellent percussion device, but in a group, Taiko takes a life of its own. Like most art forms, you can pick up the basics real quick. But to go deep into Taiko, you need time, patience and a lot of hard work. The veterans at SFTD have been playing for 10-15 years and still learning.
Needless to add, Taiko is also a fantastic full body workout. It is a combination of dance, drumming, music and more. The classes are fun, but you do need serious commitment if you want to become an advanced Taiko player. The folks in the adult beginners class are a merry bunch. Before our first class, I was extremely anxious, trying to memory numerals in Japanese from Wikipedia and worried whether I’ll be able to keep up with everyone. There was help every step of the way. The class won’t stop for you, but it will not leave you behind either :)
But the best part of SFTD is the opportunity to learn from Sensei Tanaka. His accomplishments in the world of Taiko are well known, so I won’t enlist them here. What surprised me was the humility and generosity and the energy he brings with him, even after doing this for more than four decades. He could easily delegate the adult beginners class to one of his many advanced students; yet he still routinely teaches the class himself, ever so patient and understanding. Better yet, his expertise in Taiko is matched only by his wistful humor.
So if you are in the Bay Area and are looking for some inspiration, do checkout San Francisco Taiko Dojo.