Skip to content

Instantly share code, notes, and snippets.

@fguillen
Last active January 19, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fguillen/cb7d5e6ee9be5a306e0e71f0284496e6 to your computer and use it in GitHub Desktop.
Save fguillen/cb7d5e6ee9be5a306e0e71f0284496e6 to your computer and use it in GitHub Desktop.
Announce the beer time
# Simple but necessary script (for Mac) to announce when the beer time is comming
# You can configure your crontab like this
# 0 17 * * 5 ruby $HOME/scripts/beer_time.rb >> /var/log/beer_time.log 2>&1
beer_hour = ARGV[0] || 18
def say(message)
`afplay /System/Library/Sounds/Hero.aiff`
`afplay /System/Library/Sounds/Hero.aiff`
`say "#{message}"`
end
while(true)
now = Time.new
beer_time = Time.local(now.year, now.month, now.day, beer_hour, 0)
seconds_to_beer_time = beer_time - now
if seconds_to_beer_time <= 0
say("We are officially now at beer time")
exit 0
else
say("We are at #{(seconds_to_beer_time / 60.to_f).round(1)} minutes to beer time")
end
seconds_to_sleep = rand(seconds_to_beer_time / 2) + 10 # minimum 10 seconds
seconds_to_sleep = seconds_to_beer_time if seconds_to_sleep > seconds_to_beer_time
puts "Next anouncement at #{Time.now + seconds_to_sleep}"
sleep(seconds_to_sleep)
end
@adaline
Copy link

adaline commented Jan 10, 2018

Some suggestions for modificaitons:

  • An easy way to test the result locally, eg ruby beer_time.rb --test => 📢 'It is 40 minutes to beer time'
  • A way to replace 'beer time' with a custom sound file, from the internet:
    curl -s http://x.com/x.mp3 > /tmp/x.mp3 && afplay /tmp/x.mp3
    Will this redownload the file if its already there? If not we get free caching ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment