Last active
August 29, 2015 14:11
-
-
Save prokizzle/44bc14ea026785a4180c to your computer and use it in GitHub Desktop.
Sit or Stand Timer
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
gem 'timers' | |
gem 'terminal-notifier' | |
gem 'daemons' |
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
# SitStand | |
require 'timers' | |
require 'daemons' | |
class Fixnum | |
def seconds | |
self | |
end | |
def minutes | |
self * 60 | |
end | |
def hours | |
self * 60 * 60 | |
end | |
end | |
class SitStand | |
def initialize | |
@timers = Timers::Group.new | |
@every_five_seconds = @timers.every(20.minutes) { notify } | |
@position = "sit" | |
notify | |
end | |
def sit_or_stand | |
@position = @position == "sit" ? "stand" : "sit" | |
end | |
def notify | |
%x{terminal-notifier -message "Time to #{sit_or_stand}!"} | |
end | |
def run | |
loop { @timers.wait } | |
end | |
end | |
Daemons.run_proc('SitStand') do | |
app = SitStand.new | |
app.run | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with ruby sit_stand.rb start