-
-
Save Schwad/11192129f5d74c8e5aa8dde1be375c2f to your computer and use it in GitHub Desktop.
Pomodoro Ruby Executable
This file contains 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
#!/usr/bin/env ruby | |
require 'bloops' | |
require 'io/console' | |
TOTAL_TIME = 25 * 60 # 25 minutes in seconds | |
CHIRP_TIME = 5 * 60 # 5 minutes in seconds | |
def format_time(seconds) | |
minutes = seconds / 60 | |
seconds = seconds % 60 | |
format("%02d:%02d", minutes, seconds) | |
end | |
def play_chirp | |
b = Bloops.new | |
b.tempo = 120 | |
sound = b.sound Bloops::SQUARE | |
sound.volume = 0.3 | |
sound.sustain = 0.1 | |
b.tune sound, "C6 8" | |
b.play | |
sleep 0.5 | |
end | |
def play_wild_song | |
b = Bloops.new | |
b.tempo = 360 | |
sound = b.sound Bloops::SAWTOOTH | |
sound.volume = 0.5 | |
sound.sustain = 0.1 | |
sound.attack = 0.1 | |
sound.decay = 0.1 | |
b.tune sound, "C5 8 E5 8 G5 8 C6 8 G5 8 E5 8 C6 4 B5 4 A5 4 G5 4 F5 8 A5 8 C6 8 F6 8 C6 8 A5 8 F6 4 E6 4 D6 4 C6 4" | |
b.play | |
sleep 8 while !b.stopped? | |
end | |
start_time = Time.now | |
end_time = start_time + TOTAL_TIME | |
chirp_played = false | |
system('clear') || system('cls') | |
loop do | |
remaining = (end_time - Time.now).to_i | |
break if remaining <= 0 | |
print "\rPomodoro: #{format_time(remaining)} remaining" | |
$stdout.flush | |
if remaining <= CHIRP_TIME && !chirp_played | |
play_chirp | |
chirp_played = true | |
end | |
sleep 1 | |
end | |
puts "\nPomodoro finished! Time for a break, valiant Rubyist!" | |
play_wild_song |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment