Yesterday I found a interesting ruby library —— blinkenlights, which enables you to control the LEDs on your keyboard. I thouhgt it could be a cheap replacement of lava light, so I wrote a ruby script called 'Poor Man's Lava'
#!/usr/local/bin/ruby
require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'
require 'rubygems'
require 'blinkenlights'
SUCCESS = 'success'
def read_rss source='http://cruisecontrolrb.thoughtworks.com/projects/CruiseControl.rss'
content = ''
open(source) do |s| content = s.read end
rss = RSS::Parser.parse content, false
rss.items[0].title.include?(SUCCESS) ? all_ok : alarm
end
def all_ok times = 50
BlinkenLights.open { |lights| times.times {lights.random} }
end
def alarm times = 50, invertal = 0.0
BlinkenLights.open { |lights| times.times {lights.flash invertal} }
end
while true
read_rss
sleep 5
end
make sure to have sufficient permissions to access the device, or you could simple run it as super user.