Code samples from http://book.mixu.net/