Skip to content

Instantly share code, notes, and snippets.

@tternes
Forked from jfahrenkrug/wwdc2013.rb
Last active December 12, 2015 12:19
Show Gist options
  • Save tternes/4770852 to your computer and use it in GitHub Desktop.
Save tternes/4770852 to your computer and use it in GitHub Desktop.
# in 2012 by Johannes Fahrenkrug, http://springenwerk.com
# See you at WWDC!
require 'rubygems'
require 'open-uri'
class WWDC2012
def self.announced?
begin
title = open('https://developer.apple.com/wwdc/') do |f|
f.detect { |line| line =~ /WWDC 2013/ }
end
rescue Exception => e
system("say -v \"Bad News\" \"Error: #{e.message}\"")
end
!!title && title !~ /2011/
end
def self.speak
line = "Rejoice, all you people: WWDC 2012 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 2012") do |app|
app.delegate = self
window(:frame => [100, 100, 300, 200], :title => "WWDC 2012 - springenwerk.com", :background_color => color(:name => :black)) do |win|
win << result_field
win << last_checked_field
win << label(:text => "Has WWDC 2012 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 WWDC2012.announced?
timer.invalidate if timer
result_field.text = 'YES!'
result_field.textColor = color(:name => :green)
last_checked_field.text = timestr
WWDC2012.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 2012 has...")
if WWDC2012.announced?
print " BEEN ANNOUNCED!!!\n"
WWDC2012.speak
break
else
print " not been announced yet :(\n"
end
sleep 60*3
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment