Skip to content

Instantly share code, notes, and snippets.

@thegoleffect
Forked from friggeri/clark.coffee
Created April 11, 2012 21:19
Show Gist options
  • Save thegoleffect/2362718 to your computer and use it in GitHub Desktop.
Save thegoleffect/2362718 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