added gist from @tmcw via @brunosan