Posted: May 26th, 2008 | Author: Andy | Filed under: bbc, ruby | 2 Comments »
Following on from the XMPP stuff, I made a little site that just reads and output what’s playing on BBC radio. It is a toy app at the moment with no real point (and might well fall over), its worth putting on the DAB radio to see the sort of delay it might be experiencing.
mibly.com/radiofall
What is it using I hear you bellow?
- Ruby – well what else?
- xmpp4r gem – for connecting to the xmpp server and parsing the messages
- json gem – for outputting the messages in …. json
- jQuery – to make all those Ajax requests
The next steps are to add some intelligence into the script, interacting with some APIs or something. I have a few ideas, but it depends upon time and if I can get somebody to help with design.
Posted: May 15th, 2008 | Author: Andy | Filed under: bbc, ruby | No Comments »
God bless BBC Radio Labs. They get to build some cool little things including a fun little XMPP server. Its pushing out messages that usually only get seen on the front of DAB radios. I whipped this ruby script together pretty quick (you can tell), but shows how easy you can connect to it.
require 'rubygems'
require 'ruby-growl'
require 'xmpp4r-simple'
username = 'myusername'
password = 'password'
domain = 'hug.hellomatty.com'
im = Jabber::Simple.new("#{username}@#{domain}", password)
im.status(:chat, 'Hello world')
g = Growl.new "localhost", "ruby-growl", ["ruby-growl Notification"], nil, "growl"
i = 0
while true
i+=1
if im.connected? == true
im.presence_updates.each do |friend, old_presence, new_presence|
if new_presence != nil
puts "#{friend.gsub("@#{domain}", '')} #{new_presence}"
g.notify("ruby-growl Notification", friend.gsub("@#{domain}", ''), new_presence)
end
end
else
puts '**************************** disconnected *************************'
im = Jabber::Simple.new("#{username}@#{domain}", password)
im.status(:chat, 'Hello world')
end
sleep(2)
if i == 10
im.reconnect
i = 0
end
end
Here is some sample output.
radio3: Details from bbc.co.uk/radio3 or call 08700 100 300.
1xtra: 1Xtra Dancehall Show - Robbo Ranx. Txt 88111 [network rates apply].
radio4: The World Tonight. Web - bbc.co.uk/news
radio2: Mark Lamarr. Mark presents the Shake, Rattle and Roll Show.
5live: Richard Bacon: Lively and provocative discussion regarding the day's key stories
Now I have no idea what I can do with this (twitter posting is already done to death), so I might have a think about this sort of thing. Be fun if it makes it into production.
Posted: May 13th, 2008 | Author: Andy | Filed under: rails | No Comments »
In my rails apps I used to use attachment_fu for uploading files, but of late I have moved over to thoughtbots Paperclip plugin. Its perfect for most instances, and indeed simple to use. I required it to do a little more than it can do out of the box. In my case I needed to check that the uploaded document was a well formed XML document. The result was a nice little custom validation method levered into the plugin.
module Paperclip
module ClassMethods
def validates_attachment_valid_xml name
require 'xml/libxml'
@attachment_definitions[name][:validations] << lambda do |attachment, instance|
if attachment.file.nil? || !File.exist?(attachment.file.path)
"must be set"
else
begin
parser = XML::Parser.new
parser.string = File.open(attachment.file.path).read
parser.parse
return nil rescue
"must be a valid xml document"
end
end
end
end
end
end
Then initiallise this patch it in our initializers.
require 'paperclip_mixin'
Now we can just add this validation method to our model that is using paperclip
class Asset < ActiveRecord::Base
has_attached_file :config_file
validates_attachment_valid_xml :config_file
end
And that worked fine. yay.
Posted: May 5th, 2008 | Author: Andy | Filed under: bbc, iplayer, iplayerlist | No Comments »
Over a friday night I rebuilt iPlayerlist iPhone templates so that it uses Joe Hewitt’s iui. The result is quick to navigate, no silly pinch zooming to get what I want. Just point your iphone/ipod at iplayerlist.mibly.com.
There is a slight problem that is getting on my nerves a little. When you want to view an episode you are redirected to bbc.co.uk/iplayer. I had to do this as the iPlayer site uses mp4 embeds that are protected by a couple of layers of user agent strings and cookie validation. So, although I attempted a some rather hackey iframes, a link to iPlayer seemed to be the best option.
Building this version which emulates the iPhone system ui made me want to build a version using the Apple Touch SDK. I fear that getting my head around Objective-C might just take too much time. Would be damn cool though.
Anyhow give this a go and see what you think of it.