01.14.08
Xkcd Titles
I’ve just noticed the geekily hilarious xkcd comic and one of the funniest aspects is that each comic has a ‘title’ attribute (the text that pops up when you hover your mouse over the image) that is often as funny as the comic itself. However, the length of the title often causes it to be truncated in my browser (Firefox 2.x, which probably has an obscure show-entire-title setting). Rather than arduously do a ‘view source’ on each one (or figure out the Firefox setting), I have Ruby do it for me. And for you if you want:
# xkcd.rb
# extract all the titles from xkcd comics since they
# tend to be too long to fully show in the browser
# USAGE: ruby -rubygems -rxkcd.rb -e 'Xkcd.new.show_all'
require 'open-uri'
require 'hpricot'
class Xkcd
DOMAIN = 'http://xkcd.com/'
def show id = 343 # 343 is the NSA/RSA one
begin
@hp = Hpricot.parse( open( "%s/%d/" % [DOMAIN,id.to_i] ) )
(@hp / :img).each do |el|
puts "%4d: %s" % [id.to_i, el[:title]] if el[:title]
end
rescue
end
end
def show_all
0.upto(400) do |i|
show i
end
end
end
Rocky Offner said,
January 25, 2008 at 1:08 pm
While coding Ruby is surely more fun, you can download the Long Titles add-on for Firefox to fix the problem: https://addons.mozilla.org/en-US/firefox/addon/1715/
-Rocky
Bob said,
April 15, 2008 at 9:46 am
Gee, I hadn’t noticed the title attribute on xkcd. Thanks, John. And thanks Rocky for the firefox addon. Hmmmm, ruby. maybe later.
Bob
still stuck in the land of C