Skip to content

Instantly share code, notes, and snippets.

@friggeri
Created November 25, 2011 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save friggeri/1393845 to your computer and use it in GitHub Desktop.
Save friggeri/1393845 to your computer and use it in GitHub Desktop.
Sparklines in CoffeeScript
#!/usr/bin/env coffee
ticks = ['▁','▂','▃','▄','▅','▆','▇','█']
exports.clark = (data) ->
m = Math.min data...
n = (Math.max(data...)-m)/(ticks.length - 1)
(ticks[(t-m)/n >> 0] for t in data).join('')
if require.main == module
data = process.argv
.map((a) -> parseInt(a, 10))
.filter((v) -> v==v)
process.stdout.write("#{exports.clark(data)}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment