Skip to content

Instantly share code, notes, and snippets.

@akahn
Forked from williamcotton/standup.rb
Created November 16, 2010 23:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akahn/702725 to your computer and use it in GitHub Desktop.
Save akahn/702725 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'highline/system_extensions'
include HighLine::SystemExtensions
module Standup
module Control
extend self
def play
`osascript -e 'tell application "iTunes" to play'`
end
def pause
`osascript -e 'tell application "iTunes" to pause'`
end
def set_volume(level)
`osascript -e 'tell application "iTunes" to set sound volume to #{level}'`
end
end
class Timer
def initialize(length = 50, initial_volume = 20)
@length, @initial_volume = length.to_i, initial_volume.to_i
Control.set_volume(@initial_volume)
Control.pause
start
end
def start
@countdown = Thread.new do
countdown
fade_in
end
end
def stop
@countdown.kill
Control.pause
end
def restart
stop; start
end
def countdown
@length.downto(1) do |i|
p i
sleep 1
end
Control.play
end
def fade_in
@initial_volume.upto 100 do |i|
Control.set_volume(i)
sleep 0.05
i += 1
end
end
end
def self.Timer(length, initial_volume)
timer = Standup::Timer.new(length, initial_volume)
begin
loop do
character = get_character
if [32, 13].include? character # Restart on space bar or enter
timer.restart
elsif character == 27 # Exit on escape
raise Interrupt
end
end
rescue Interrupt
Control.pause
exit
end
end
end
if $0 == __FILE__
length, initial_volume = ARGV
Standup::Timer(length, initial_volume)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment