Skip to content

Instantly share code, notes, and snippets.

@jumanjiman
Created March 5, 2013 22:53
Show Gist options
  • Save jumanjiman/5095103 to your computer and use it in GitHub Desktop.
Save jumanjiman/5095103 to your computer and use it in GitHub Desktop.
trivial demo to save timestamp in a file
#!/usr/bin/env ruby
require 'date'
require 'yaml'
now = DateTime.now
puts 'time is now %s' % now
my_hash = Hash.new
my_hash['last_update'] = now.iso8601
path = '/tmp/boogabooga.yaml'
# save my time
File.open(path, 'w') do |f|
f.puts my_hash.to_yaml
end
# sleep 5 seconds
5.times {print '.'; sleep 1}
puts ''
# read it back
y = YAML.load_file(path)
puts 'time is now %s' % DateTime.now.iso8601
puts 'but last update was %s' % y['last_update']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment