Skip to content

Instantly share code, notes, and snippets.

@vmoravec
Forked from jcromartie/spark.rb
Created September 4, 2013 21:44
Show Gist options
  • Save vmoravec/6443282 to your computer and use it in GitHub Desktop.
Save vmoravec/6443282 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }
min, range, scale = values.min, values.max - values.min, @ticks.length - 1
puts values.map { |x| @ticks[(((x - min) / range) * scale).round] }.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment