Skip to content

Instantly share code, notes, and snippets.

@l0gicpath
Forked from emad-elsaid/age.rb
Last active August 29, 2015 13:56
Show Gist options
  • Save l0gicpath/9187232 to your computer and use it in GitHub Desktop.
Save l0gicpath/9187232 to your computer and use it in GitHub Desktop.
An age ticker, forked to clean up, more ruby-like and properly styled
#! /usr/bin/env ruby
date_of_birth = Time.new(1988, 8, 31)
# Credit: http://stackoverflow.com/a/4136485
def humanize seconds
[[60, :seconds],
[60, :minutes],
[24, :hours],
[365, :days],
[100, :years]].map { |count, name|
if seconds > 0
seconds, mod = seconds.divmod(count)
"#{mod.to_i} #{name}"
end
}.compact.reverse.join(' ')
end
# Handle interrupts gracefully, should probably clear the screen too
trap("INT") {
exit 0
}
loop do
distance = Time.now - date_of_birth
print "#{humanize(distance)} \r"
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment