Created
January 5, 2011 01:43
-
-
Save cyberfox/765800 to your computer and use it in GitHub Desktop.
Asks for status every 15-25 minutes to track where time goes. Traps USR2 to wake and prompt for status. Designed for Linux, works on OS X, needs tweaks for Windows. Uses JRuby, since it's the only easy-to-get cross-platform UI toolkit for Ruby.
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
require "java" | |
java_import javax.swing.JOptionPane | |
class Whazzup | |
def initialize(file = "#{ENV['HOME']}/snippets.txt") | |
@snippets ||= open(file, 'ab') | |
log('[Starting up (ruby)]') | |
thread_loop = Thread.current | |
# Use the USR2 signal as a 'wake up'. | |
Signal.trap("USR2") do | |
thread_loop.run | |
end | |
end | |
PROMPTS = ["What're you working on?", | |
"What'cha up to?", | |
"What's going on?", | |
"How goes it?", | |
"What's the plan?", | |
"Where are you at?", | |
"What's next?", | |
"What've you been up to?", | |
"Status:", | |
"Anything I can help with?", | |
"What's happening?", | |
"What's on your mind?"] | |
def log(msg) | |
@snippets << Time.now.to_s << ': ' << msg << "\n" | |
@snippets.flush | |
end | |
def ask | |
picked = PROMPTS[rand*PROMPTS.length] | |
answer = JOptionPane.showInputDialog(nil, picked) | |
answer = '...' if answer.nil? || answer.empty? | |
log(answer) | |
end | |
def run! | |
while true | |
ask | |
# Sleep between 15 and 25 minutes | |
sleep (((rand*10).to_i-5)+20)*60 | |
end | |
end | |
end | |
whatsup = Whazzup.new | |
whatsup.run! |
This seems to work fine on Windows XP with JRuby 1.5.6 as well (jruby whazzaup.rb). Fun!
A Couple of notes too:
- require "java" is now preferred over import Java
- If you ever want to load this with Rake for testing then you need to change to 'import' to 'java_import' to avoid method naming collision.
Done and done; thanks for the info! Glad to know it works on Windows, too...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's missing the hash-bang line at the top, because that confuses GitHub's 'gist' system. You'd want to point it to the JRuby path on your system, e.g.:
as the first line.