Useful Platitudes

Notes on programming by Daniel Mendel

Benchmarkers, Beware the Ephemeral Port Limit

If you’re benchmarking a web server using tools like ab, weighttp or siege you may encounter an issue that could skew your results – hanging the connection pool. To illustrate this point, let’s look at a couple of benchmarks using siege on OS X:

All of the Markups

I recently started taking steps to revive ENML.js, a library I wrote a few years ago for defining and parsing Domain Specfic Markup Languages. Since I wrote the first version of ENML in Ruby several years ago, some significant other ENML ‘s have popped up – most notably the Evernote Markup Language. Obviously, I need to find a new name for the project. After some cursory googling for other possible __ML names I came to the realization that there are a buttload of Markup Languages in the world.

I decided – as any sane programmer in my position would – to spend the next several hours writing a scraper to compile a list of them all. I sat down with Thomas Ballinger and did just that. Without futher ado, I am proud to present our findings:

Dumbwaiter v0.0.1

I’ve recently found myself doing a lot of experiments in HTML that are only composed of client-side code. The trick is that to properly test them, you have to serve the pages through a host of some kind – anything that you open directly using the file: protocol runs into security measures that prevent the page access to certain types of assets and requests.

In the past I’ve either launched Chrome with --allow-file-access-from-files and used the file: protocol, or served the files through a local Apache or Nginx server. Since I’m lazy, I decided these options were too much work and that instead I wanted a simple CLI to spin up small servers for any local directory.

This morning I wrote dumbwaiter, a tiny, 11 line npm module for doing just that by using the connect.static middleware.

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env node

var connect  = require('connect')
  , path    = require('path')
  , dirPath  = path.resolve( process.argv[2] )
  , PORT     = process.argv[3] || 3000
  , server   = connect()

server.use( connect.static( dirPath ) )
server.listen( PORT )
console.log('serving ' + dirPath + ' on port ' + PORT + ' ...')

Install with npm install -g dumbwaiter, then run as dumbwaiter [rootDir] [port].

New Compound Animations in glitz.js

glitz.js support for defining animations is pretty flexible, but it is designed for fairly simple interactive behaviors and has, until now, lacked a good method for building complex animations from component parts. I’ve wanted to add a good API for to do this for a while and this week I finally got a chance to do so, while pairing with Zach Allaun at Hacker School. I’m really excited about what we came up. First, I’ll explain the state of affairs before our changes.

Cool Stuff I Learned Doing Code Review

So a major staple of Hacker School is doing ( and getting ) lots and lots of code reviews. I think this is awesome, and I’ve been working on a lot of reviewing this week. The most rewarding thing about reviewing a language you are comfortable in is that you learn all kinds of things you might never come across when left to your own ingrained design patterns. This is a short round up of some neat things I learned about javascript this week.

Subclassing Javascript Arrays

When I started working on the animation framework glitz.js, I wanted an easy syntax for expressing and traversing a nested tree of Renderable objects. I thought, ”Why not implement it as an array?” Since the scene graph would need to be iterated over very quickly during the render loop, it would be great to just represent the whole thing as a multi-dimentional array – essentially a subclass of array that had some additional properties and methods like render and animate.

1
2
3
4
5
var box1 = new Box({ x: 100, y: 100 });
var box2 = new Box({ x: 110, y: 110 });
box1.push( box2 );
box1[0];       // box2
box1.render(); // draws a box