Recently I built a little utility project for the fine people at UserTesting.com to help them get some insights into project lifecycle and “cycle time,” the time it takes any given project to move through pre-determined phases of the lifecycle. Hence, “Trello Cycles."
Seeing as how Trello‘s API is damn robust and they have a sweet piece of JS to help with authentication and some basic API requests I decided to do the whole thing client side and give Yeoman a try at the same time.
The webapp generator for Yeoman is pretty sweet: it scaffolds out some basic JS, CSS, and HTML; sets up Grunt tasks for local testing with live reload and building to a destination folder; and has support for CoffeeScript, HTML5 Boilerplate, Twitter Bootstrap, and RequireJS.
Grunt the Fuck?
Maybe I'm just not hip to the new JS jazz, but Gruntfiles make no fucking sense to me. Check out the auto-generated Gruntfile.js for Trello Cycles and the Rakefile for my Sinatra Boilerplate project. Both will build assets and run a development server (I realize there isn't perfect feature parity so an apples-to-apples comparison is impossible, what I'm digging at here isn't a functionality comparison) but I find the former damn near inscrutable and the latter generally more legible. It's a minor thing. Sort of.
Turns out doing basic statistical work in
sum and mean (average) of an array of numbers isn't as easy as just calling
[1, 2, 3].sum() or
[1, 2, 3].mean(). Instead, you'd have to do something
absolutely goofy looking like pass the array into a dedicated function like
arraySum([1, 2, 3]) and just looking at that makes my blood boil. Because I've
been using Ruby so much I'm used to calling methods directly on objects and
monkey patching core classes to do what I want so I decided I'd better get to
it. (Sidenote: I think there's probably a discussion of encapsulation and API
consistency in here along the lines of Underscore
vs. core extension, but I'm not ready for that one yet).
This script adds some basic mathematical methods to the Array prototype chain including:
sumwhich depends on
meanwhich depends on
variancewhich gives you the variance of the set
stddevwhich gives you the standard deviation, or more simply the square root of the variance
With all of that, you can call
[1, 2, 3].sum() and
[1, 2, 3].mean() to your