Category Archives: Computer Science

HTML5 Up and Running

HTML5 Up and RunningHTML5 Up and Running is Mark Pilgrim's book on HTML5. The entire text of the book is also available at Just like the other books written by Mark (Dive into Python, Greasemonkey Hacks), this book will serve as a very comprehensive introduction to the topic.

The book begins with history of HTML specification starting from conversations on www-talk mailing lists to formation of W3C and to WHAT Working Group. Then it moves on to Feature Detection, high level view of new features - canvas, video, Storage, Web Workers, Geolocation. The next chapter is a dive into details of the Document elements, new semantic elements. The next few chapters cover in detail each of the new features - Canvas, Video & Audio, Geolocation, Local Storage, Offline applications, Form semantics, Microdata. Each of these later chapters can be read stand-alone without depending on others.

There are some open source projects mentioned in the book - Modernizr for HTML5 feature detection, geo.js for smoothing out differences over gelolocation APIs. These pointers should be of great value to developers.

The book website is itself a great study in HTML5 with its very detailed attention to live examples, typography. Great work by Mark once again and kudos to O'Reilly for allowing full version (which is in fact more up-to-date than the printed book) online and also for selling the ebook in DRM free formats!

Disclaimer: I am writing this post as a part of Blogger Review program. I am not being paid to write this review. But I received the ebook free for doing this.

Ruby script to get a list of all mp3 files in a directory sorted durationwise.

Here is some ruby practice...

def mp3len(dirname)
require 'mp3info'
Dir[dirname].each do |f| do |info|

puts "Enter directory containing mp3 files"
dirname = File.expand_path(dirname)
puts "Searching #{dirname}"
dirname += "/**/*.mp3"

s=mp3len(dirname).sort {|a,b| a[1] < => b[1]}
s.each{|q| puts "#{q[0]} => #{q[1]} seconds"}

Update: Here is the link to the file on github (for updates) or the git repository

Unicode entry

This entry has some unicode characters (devanagari), let's see if they are visible correctly...

मराठीमद्ध्ये लिहिणे आता बरेच सोपे झाले आहे. यासाठी युनीकोडला धन्यवाद दिले पाहिजेत

Lateral Thinking…

How will you write a program to find jumbled words ?

The shotgun approach is the first one anyone is bound to follow at first. i.e. For all permutations of the letters, find if there is a match in the dictionary of words. You might do some optimizations to ignore repetitions etc. But this is O(n^2) complexity solution.

I read an elegant way to solve this here. The trick is to notice that the real answer and the jumbled word look the same when they the letters are sorted.
(Let's ignore the time to sort the words for now, which is O(n*log(n)) I believe for decent algorithms.)

Here is a python snippet to solve the jumble:

#!/bin/env python
def find_jumble(jumble, word_file='/usr/dict/words'):
sorted_jumble = sort_chars(jumble)
for dictword in open(word_file, 'r').xreadlines():
if sorted_jumble == sort_chars(dictword):
yield dictword
def sort_chars(word):
w = list(word.strip().lower())
return w
inp = raw_input("Enter word: ")
if not inp: break
for ans in find_jumble(inp):
print "Answer = ", ans