Skip to content

Instantly share code, notes, and snippets.

@stan
Forked from peterc/xkcd_for_ipad.cgi
Created May 21, 2010 07:49
Show Gist options
  • Save stan/408598 to your computer and use it in GitHub Desktop.
Save stan/408598 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
%w(rubygems open-uri nokogiri).each { |lib| require lib}
doc = Nokogiri::HTML(open('http://xkcd.com/').read)
img = doc.at_css("#middleContent img")
puts %|Content-type: text/html
<html>
<head>
<title>XKCD for iPad</title>
<style type="text/css">BODY { font-family: helvetica; font-size: 16px; text-align: center}
.quip { font-style: italic }</style>
</head>
<body>
#{doc.css("h1")}
<p>#{img}</p>
<p class="quip">#{img[:title]}</p>
</body>
</html>|
# big thanks to selectorgadget.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment