Skip to content

Instantly share code, notes, and snippets.

@dan
Forked from davetron5000/dantimer.rb
Created June 22, 2012 13:31
Show Gist options
  • Save dan/2972751 to your computer and use it in GitHub Desktop.
Save dan/2972751 to your computer and use it in GitHub Desktop.
DanTimer
#!/usr/bin/ruby
require 'time'
def format_time(seconds)
hours = (seconds / 3600).to_i
minutes = ((seconds % 3600) / 60).to_i
seconds = (seconds % 60).to_i
minutes = "0#{minutes}" if minutes < 10
seconds = "0#{seconds}" if seconds < 10
"#{hours}:#{minutes}:#{seconds}"
end
start = Time.now
ARGF.each do |line|
time = Time.now
puts "#{format_time(time - start)}: #{line}"
end
puts "#{format_time(Time.now - start)}: DONE!"
$ ./dantimer.rb > notes.txt
Start of show
Merlin talks about agency
Construction at Marco's house
Some cool new mac thing
Siracusa insists he hasn't listend to Build & Analyze
Merlin still talking about agency
^D
$ cat notes.txt
0:00:02: Start of show
0:00:10: Merlin talks about agency
0:00:18: Construction at Marco's house
0:00:27: Some cool new mac thing
0:00:40: Siracusa insists he hasn't listend to Build & Analyze
0:00:50: Merlin still talking about agency
0:00:51: DONE!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment