-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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