Skip to content

Instantly share code, notes, and snippets.

@cyberfox
Created January 5, 2011 01:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cyberfox/765800 to your computer and use it in GitHub Desktop.
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.
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!
@cyberfox
Copy link
Author

cyberfox commented Jan 5, 2011

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.:

#!/home/cyberfox/.rvm/rubies/jruby-1.5.1/bin/jruby

as the first line.

@enebo
Copy link

enebo commented Jan 5, 2011

This seems to work fine on Windows XP with JRuby 1.5.6 as well (jruby whazzaup.rb). Fun!

A Couple of notes too:

  1. require "java" is now preferred over import Java
  2. 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.

@cyberfox
Copy link
Author

cyberfox commented Jan 6, 2011

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