-
-
Save rociiu/351944 to your computer and use it in GitHub Desktop.
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
# in 2010 by Johannes Fahrenkrug, http://springenwerk.com | |
# See you at WWDC! | |
require 'rubygems' | |
require 'open-uri' | |
class WWDC2010 | |
def self.announced? | |
title = nil | |
open('http://developer.apple.com/wwdc') do |f| | |
f.each do |line| | |
if line =~ /<title>/ | |
title = line | |
break | |
end | |
end | |
end | |
if title | |
if title.strip =~ /2009/ | |
return false | |
else | |
return true | |
end | |
else | |
return false | |
end | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment