Skip to content

Instantly share code, notes, and snippets.

@rawburt
Created January 3, 2016 07:57
Show Gist options
  • Save rawburt/9c06a2f1c441927f1f2a to your computer and use it in GitHub Desktop.
Save rawburt/9c06a2f1c441927f1f2a to your computer and use it in GitHub Desktop.
track your daily water intake
#!/usr/bin/env ruby
# Track your daily water intake.
#
# usage: ./water [+|-]
require "yaml"
WATER_FILE = File.expand_path("~/.water")
def dump(d); File.open(WATER_FILE, "w+") {|f| f.write YAML.dump(d) }; end
dump({}) unless File.exists?(WATER_FILE)
now = Time.now.strftime("%Y:%m:%d")
days = YAML.load(File.read(WATER_FILE))
days[now] ||= 0
if %w{+ -}.include?(ARGV[0])
ARGV[0] == "+" ? days[now] += 1 : days[now] -= 1
dump(days)
end
puts days[now]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment