Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Created March 31, 2010 11:04
Show Gist options
  • Save jfahrenkrug/350198 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/350198 to your computer and use it in GitHub Desktop.
# in 2010 by Johannes Fahrenkrug, http://springenwerk.com
# See you at WWDC!
require 'rubygems'
require 'open-uri'
class WWDC2010
def self.announced?
title = open('http://developer.apple.com/wwdc') do |f|
f.detect { |line| line =~ /<title>/ }
end
!!title && title !~ /2009/
end
def self.speak
line = "Rejoice, all you people: WWDC 2010 has been announced!"
if defined? NSSpeechSynthesizer
ns = NSSpeechSynthesizer.new
ns.voice = "com.apple.speech.synthesis.voice.GoodNews"
ns.startSpeakingString(line)
else
system("say -v \"Good News\" \"#{line}\"")
end
end
end
if defined? NSObject
require 'hotcocoa'
class Application
include HotCocoa
def start
@firstrun = true
application(:name => "WWDC 2010") do |app|
app.delegate = self
window(:frame => [100, 100, 300, 200], :title => "WWDC 2010 - springenwerk.com", :background_color => color(:name => :black)) do |win|
win << result_field
win << last_checked_field
win << label(:text => "Has WWDC 2010 been announced yet?", :text_color => color(:name => :white))
win.will_close { exit }
end
start_polling(0.5, false)
end
end
private
def start_polling(seconds = 10, should_repeat = true)
# so MRI doesn't complain
eval("NSTimer.scheduledTimerWithTimeInterval(seconds, target:self, selector:'update:', userInfo:nil, repeats:should_repeat)")
end
def result_field
@result_field ||= label(:text => "Nope.", :font => font(:name => "Tahoma", :size => 90), :text_color => color(:name => :red), :text_align => :left)
end
def last_checked_field
@last_checkd_field ||= label(:text => "Checking... ", :font => font(:name => "Tahoma", :size => 10), :text_color => color(:name => :gray), :text_align => :left)
end
def update(timer = nil)
timestr = Time.now.localtime.strftime("at %I:%M:%S%p")
if WWDC2010.announced?
timer.invalidate if timer
result_field.text = 'YES!'
result_field.textColor = color(:name => :green)
last_checked_field.text = timestr
WWDC2010.speak
else
result_field.text = 'Nope.'
result_field.textColor = color(:name => :red)
last_checked_field.text = timestr
if @firstrun
@firstrun = false
timer.invalidate if timer
start_polling
end
end
end
end
Application.new.start
else
while true
print Time.now.localtime.strftime("At %I:%M:%S%p WWDC 2010 has...")
if WWDC2010.announced?
print " BEEN ANNOUNCED!!!\n"
WWDC2010.speak
break
else
print " not been announced yet :(\n"
end
sleep 10
end
end
@dennisreimann
Copy link

Nice!

@jfahrenkrug
Copy link
Author

Thank you, Tammo for making the announced? method more concise and ruby-esk :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment