Posts by Toby

Homework Schedule


Posted by Toby 10 days ago (0 comments)

MOG vs Thumbplay

I just learned about these two new-ish online streaming music services. This post will be a comparison of the two, in much the style of my old e-music vs rhapsody post

First a word about my experience with Rhapsody. The verdict is: I tried it for a few months, and then cancelled. Ultimately not being about to play on my iPod(the iPod Classic, that is - actually this was before it was branded Classic), was the deal breaker. 

The landscape has changed, on-demand streaming is the new model - it's just a matter of time. Why streaming? Well, downloading music and managing your own music library introduces several problems:
  1. the overhand of managing the library
  2. the overhead of syncing the music to and between different devices(mobile devices, home media center)
  3. finite disk space - although harddrives are pretty cheap nowadays, the space on mobile phones are still very limited, this makes syncing even more problematic because now you need to decide on what subset of your library you want to put on your phone

On-demand streaming services promise to deliver huge music collections to you anywhere you go for a flat monthly subscription fee. You are always just a search and click away from listening to music you've never heard before - music discovery is going to blossom like never before.

Pricing

Anyways, enough philosophizing. What is the bottom line? Both of the services cost $9.99 a month with unlimited streaming and downloading. MOG also has a $4.99 PC-only plan.

Selection

I made a list of several lesser known artists whom I love, and used them as the benchmark for testing the breath of the two services' music library. Here are the results:



The table tallies the number of albums that were listed under each artist on each of the music services. The result in terms of total albums was a tie: 86 to 86. However, MOG faired better in the number of artists with at least one album: 16 to 13.

iPhone App

Thumbplay's iPhone app is more polished, but MOG's was just released a couple of days ago, and they are actively working on it.

Intangibles

The race is tight so far, but how does each service stand out and how do they differ? Short answer: MOG is focus on the web experience while Thumbplay is more focused on the desktop experience. MOG has a web-based UI, and social features such as sharable playlists, and blog posts. Thumbplay has a native UI, which should integrate better with the Apple Remote, but seems to lag behind in social features. I personally like the social features in MOG, and am thinking about doing a music listening blog within it.

Sound

I did a side-by-side comparison of "Let's Do It Again" by The Brand New Heavies on both services. To my ears, MOG has the better sound quality - both the bass and tremble sound crisper than Thumbplay with my Bose headphones.

Streaming Limit

Both services do not seem to limit the number of computers or devices you use with it, however, both of them allow you to stream to only one of them at a time.

Verdict

As of now, MOG is my favorite. However, it's still early days. There are big players waiting to get into the game(Apple, Spotify), and it's anyone's game. 
Posted by Toby about 1 month ago about music and tech (0 comments)

UI Round Up: Too Many Tabs

The UI paradigm of layout out things horizontally - such as tabs or the toolbars - is by now commonplace. But with this design there is a painful drawback: what do you do when you run out of horizontal space? Since, I am about to have to implement something like this for work, I did a little research on how this problem is handled. The representative sample I chose are Firefox, Safari, IE 7
, Chrome, and TextMate. 

Firefox

Firefox Tabs

In Firefox, there's a minimum width beyond which the tabs will not shrink. Tabs that cannot fit into the real estate are hidden, but can be gotten to via the left and right scroll arrows(on the left and right of the tabs) or via the tab drop-down icon on the far right.

Safari

Safari Tabs

Safari works similar to Firefox, except that it does not have the left and right arrows.

IE 7

IE 7 Tabs

IE 7 has everything Firefox has, plus a thumbnail view button on the far left, which when clicked will show you all your tabs as thumbnails in the content area.

Chrome

Chrome Tabs

Chrome is the most curious of all. It will display all of your tabs, regardless of how many of them you have opened, or whether or not you can read the title of the tabs.

TextMate

TextMate Tabs

TextMate - the only non-browser in my sample set - handles this much like Safari, except that in the "extra tabs" drop-down, checkmarks next to an item indicates that the file is the one currently displayed in the editor, whereas in all the browser UIs we've seen, the currently displayed tab is always made visible on top.
Posted by Toby 2 months ago about design, tech and ui (0 comments)

Reading On the iPad

First up, iBooks didn't work for me. Most of the books on my reading list were not available there. However, most of them were available on Kindle, and you can read any Kindle book on the iPad by downloading the free Kindle app. Does Amazon care that you are not reading them on a Kindle? No at all, since you are still paying for every book that you read.

So I tried reading a Kindle book: Emotional Design by Donald A. Norman. What I found is that reading on the iPad is the best reading experience there has ever been: far better than physical books of any form factor. Molly Wood did not do it any justice.

Why I Disagree With Molly

Molly's main complaint was that the iPad is too heavy to hold like a book - with two hands holding in front of your face. 

Holding Up-Right

My answer to this is simple: don't hold it like that! What I have found to work best for me is to set the display at a larger font size, so you don't have to hold the device close to your face in order to read it comfortably. I usually put the iPad on my lap flat:

Lap Flat

or slightly till it toward me by crossing my legs:

Crossed Legs

or propping up my legs:

Crouched Legs

This works so nice because one of the nicest features of the iPad is it's cool operational temperature - I would never do this with my Macbook Air. If I feel real lazy, sometimes I lie all the way down on my side and hold it up side ways with one hand.

Lying Down

Why it's Better Than a Book

The reading experience of the iPad is decidedly better than a real book. With a book, well, you usually have to hold it up with two hands, which puts strain on your arms and your palm. If you decide to hold it with one hand, you will contort your fingers in a strange way to try to hold the pages down which will strain your palm even more, to turn a page you'd most likely still require two hands. If you hold the iPad the way I prescribed, you are not really holding it with your hands at all, so no strain, but even better than that, turning a page is a matter of a tap or a flick of a thumb! In fact, when you are sitting comfortably reading with an iPad, the only thing you'll ever have to move is one finger.

Another advantage that the iPad - and eReaders in general - have over books that is rarely mentioned is their accessibility for the visually impaired. In short: old people don't read so good. My mom returned a paperback book because the print was too small for her to read. With an eReader you can set the font size to what's the most comfortable for you.

It's All eBooks From Here

That's it. I've decided. I will never buy a book again unless I absolutely have to.
Posted by Toby 2 months ago about eReaders, gadgets, ipad and tech (0 comments)

Your Tests' Worth

What I don't like about the TDD(Test-Driven Development) movement is how fervently religious its practitioners can sometimes be. I like TDD just fine, but like anything else - it's just a tool. I write tests for some situations, for others, I don't - and I've spoken to many who are like me in this respect. I've also seen TDD done badly - which if persisted - is counter-productive. What I'd like, is to have some way to evaluate how well or poorly you are doing TDD and whether it makes sense at all for the given situation. Put succinctly: when is TDD worth it? If you are already writing tests, this is a small set of criteria that keeps you focused on what should be the desired outcome. If you are thinking about writing tests, these should help you decide whether you want to start getting serious.

The criteria I've come up with are cost, test-time, and regression-fail-rate.

Cost

Obviously, the cost of writing the tests is a big factor and must be minimised. How much are you investing into writing and maintaining the tests? How easy is it to add a new test? How often do existing tests have to be modified? To minimise these costs, you often make use of or build frameworks and tools to make testing easier, but there is a trade-off: how much are you investing into building or integrating testing frameworks and tools?

Test-Time

Test-time is the amount of time it takes for your test suite to run. This is a number you want to minimise because a large test-time slows down a developer's development cycle and will be a large on-going tax to the cost of writing/maintaining tests. This is the reason seasoned TDD'ers will prefer unit tests to functional tests, and also the reason they like to use mock frameworks - these are techniques that can reduce test-time.

Regression-Fail-Rate

The core benefit of TDD is that it gives you the safety to make big changes in your software little time, so how well are you making use of it? Regression-fail-rate is the rate at which your previous testcases fail. Previous meaning all but the testcase you just added and are working on passing. A high number means you are making large changes in your code consistently. If your regression-fail-rate is very low, it means you may not be using the full benefit of TDD. 

Conclusion

To get the most out of TDD, you need to keep its maintenance cost to a minimum while changing your software at a rapid rate.
Posted by Toby 2 months ago (0 comments)

Python-Style OO in Javascript

A while a go I wrote a post on Prototype Inheritence in Python. This time, I am somewhat going the opposite direction. That's right: Python-Style OO in Javascript.

Now, I don't think I am the first one who thought of this. In fact, Prototype.js does something like this for their method extensions to DOM objects. The main idea is this: if you specify self as the first argument to a method explicitly, you will be able to use self inside of nested closures within the method without having to create a self variable manually, i.e.:
var self = this
or doing something like Prototype's bind, or pass the context explicitly around like the Array methods forEach, map, every, etc.

This is but a small proof-of-concept. The result is you can write a class like this:
var Man = Class(Object)({
  __init__: function(self, name){
    self.name = name
  },
  greeting: function(self, other){
    setTimeout(function(){
      self.say("Hello, " + other.name + ", my name is " + self.name)
    }, 100)
  },
  say: function(self, msg){
    sys.puts(msg)
  }
})
Take it for a spin:
var dan = new Man('Dan')
var john = new Man('John')
dan.greeting(john)
john.say('How do?')
Output:
How do?
Hello, John, my name is Dan
The implementation of Class looks like this:
function toArray(args){
  var ret = []
  for (var i = 0; i < args.length; i++)
    ret.push(args[i])
  return ret
}

function Class(parent){
  function bind(func, obj){
    var ret = function(){
      var args = toArray(arguments)
      args.splice(0, 0, obj)
      return func.apply(undefined, args)
    }
    return ret
  }
  
  return function(attrs){
    return function(){
      for (var name in attrs){
        var value = attrs[name]
        if (typeof(value) == 'function'){
          this[name] = bind(value, this)
          this[name].name = name
        }else{
          this[name] = value
        }
      }
      this.__init__.apply(this, arguments)
    }
  }
}
Full source can be found here. I ran it in node. This could be an interesting approach to avoiding "this-hell".

Posted by Toby 2 months ago about javascript, programming and python (0 comments)

Quick And Dirty JSONP

I needed JSONP for WordyClouds, and since I am trying not to have to use jQuery, I just rolled my own. JSONP is a simple hack, so this is but a short little snippet:
var JSONP = {}
JSONP.get = function(url, callback){
    var scriptTag = document.createElement('script')
    var callbackName = '_' + new Date().getTime()
    JSONP[callbackName] = function(){
        callback.apply(null, arguments)
        delete JSONP[callbackName]
        document.head.removeChild(scriptTag)
    }
    if (url.indexOf('?') != -1)
        url += '&callback=JSONP.' + callbackName
    else
        url += '?callback=JSONP.' + callbackName
    scriptTag.src = url
    document.head.appendChild(scriptTag)
}
Example usage:
JSONP.get('http://feeds.delicious.com/feeds/json/tags/your_username', function(data){
    // Woohoo! You got data!
})

Posted by Toby 2 months ago about javascript and programming (0 comments)

WordyClouds - I am Coming After Wordle

After playing around a bit with create word clouds I've decided to write an HTML 5 version of Wordle.net. I am calling it WordyClouds. I've started the beginnings of the code on github.

Also, here's the updated bookmarklet <-- drag to toolbar to install. It does a uniformly randomized algorithm rather than Wordle's advanced packing algorithm.

As for that algorithm, I've done some research to how I might implement something close to Wordle's algorithm. I need to be able to make the best use of space - e.g. allowing tiny words to go inside of the holes inside larger letters. To do that I need the actual shape representation of all of the characters for a given font. After looking at the Canvas api, typeface.js and some cursory research into SVG, I've settled - for now - on using Canvas's bitmap feature: I would render each character required for the word cloud on a temporary scratch-pad-canvas, and then read its bitmap representation via the Canvas interface. A prove-of-concept was done and the code is here: glyphshapes.js.

Obviously, still big challenges lie ahead. How will the algorithm work? I am not exactly sure.

Update: I have written a naive non-overlapping algorithm. Here's the new bookmarklet <-- drag to toolbar to install.

Update 2: Added vertical word placement: new bookmarklet <-- drag to toolbar to install.

Posted by Toby 2 months ago about javascript and programming (0 comments)

Word Cloud Bookmarklet

Inspired by Wordle.net, I wrote a bookmarklet that generates a word cloud based on the text of the page you are on. Here it is: WordCloud <- (drag to your toolbar to install). The uncompressed source is as follows:

function getText(elm, excludeTags){
	if (elm.nodeType == 3) return elm.nodeValue;
	if (excludeTags && elm.tagName && excludeTags.indexOf(elm.tagName.toLowerCase()) != -1) return '';
	var ret = '';
	for (var i = 0; i < elm.childNodes.length; i++){
		ret += getText(elm.childNodes[i], excludeTags);
	}
	return ret;
}

function keys(obj){
    var ret = [];
    for (var key in obj) ret.push(key);
    return ret;
}

var text = getText(document.body, ['script']);
var commonWords = ['a', 'the', 'and', 'of', 'is', 'in', 'this', 'it', 'to'];
var words = text.replace(/[^a-zA-Z]/g, ' ').split(' ').filter(function(p){return p != ''});
words = words.filter(function(word){
	return commonWords.indexOf(word) == -1;
});
var freq = {};
words.forEach(function(word){ 
    freq[word] = (freq[word] || 0) + 1;
});

var markup = keys(freq).map(function(word){
	return '<span style="font-size: ' + (freq[word] / 4) + 'em">' + word + '</span>';
}).join(' ');
document.body.innerHTML = markup;

Enjoy! As a next step, I plan to use Canvas and implement more advanced layouts like the ones on Wordle.
Posted by Toby 3 months ago about javascript, programming and wordcloud (0 comments)

Bach Minute - Lapband

Lapband, I have been abandoning you! I am sorry. But I am excited about this week's release because I've actually been practicing for it. This is a beginner Bach piece I hear all the time around my house. Enjoy.

Minuet - J.S.Bach

Posted by Toby 3 months ago about lapband and music (0 comments)

Continuation-Passing Style: Don't Overdo it

Continuation-Passing Style(CPS) is a style of programming that's useful for a number of use-cases, but you shouldn't get carried away and start writing all your programs in this style. Here, I am going to list 3 disadvantages of programming in this style.

Code Size

Unless your language has specific language support for writing in Continuations(e.g. Haskell), your code will have more bloat.
Example, here's a sqrt function in direct style:
function sqrt(a, b){
    return a * 2 + b * 2;
}
Here it is in CPS:
function sqrt(a, b, callback){
    multiply(a, 2, function(a2){
        multiply(b, 2, function(b2){
            add(a2, b2, callback);
        });
    });
}

Readability

The direct style is generally easier to read/understand. Take the previous sqrt example, the CPS version introduces 2 extra variable names: a2 and b2, which increases the mental load of somebody trying to read the program.

Code is Coupled to Ordering of Operations

With CPS-Style code, the order of your operation affects the structure of your code. Again, taking the sqrt example. This time, let's rewrite the direct-style version to:
function sqrt(a, b){
    var a2 = a * 2;
    var b2 = b * 2;
    return a2 * b2;
}
Here, the statements var a2 = a * 2; and var b2 = b * 2; are completely separate and independent. I could swap their order without changing the code's behavior. In the CPS-Style, the whole thing is one big statement, and therefore, to reorder the sequence of operations, it is necessary to mentally unwrap the layers of closure functions and pull out just the right ones and then put them back together. In this simple example, it wasn't actually that hard, but imagine if the code was more like this:
function sqrt(a, b, callback){
    multiply(a, 2, function(a2){
        /* code */
        multiply(b, 2, function(b2){
            /* code */
        });
        /* more code here */
    });
}
Basically, code in this style is much harder to decouple into smaller independent parts. Libraries like Do and node-promise exist to compensate for this problem, but they IMO are still a far cry from the plain ol' direct style.

The point here is that there are definite disadvantages to writing code in the Continuation-Passing Style. I am not saying that you should not use CPS, but that you should have good reasons for using it - good enough to offset its disadvantages.
Posted by Toby 3 months ago about javascript and programming (0 comments)

Convert a Function to Continuation-Passing Style

Here's a snippet that converts a normal Javascript function to its Continuation-Passing style equivalent:
function asCPS(f){
  var _f = function(){
    var callback = arguments[arguments.length - 1];
    var args = Array
      .prototype.slice
      .call(arguments, 0, arguments.length - 1)
    var retVal = f.apply(this, args)
    if (callback) callback(retVal)
  }
  _f.name = f.name
  return _f
}
So you have a normal function, say add():
function add(one, other){
  return one + other;
}
Convert it:
add = asCPS(add)
Now you can call it and get the result inside a callback, like so:
add(1, 2, function(sum){
  console.log('sum: ' + sum)
})
Posted by Toby 3 months ago about javascript and programming (0 comments)