Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created December 1, 2008 23:36
Show Gist options
  • Save ryanfb/30903 to your computer and use it in GitHub Desktop.
Save ryanfb/30903 to your computer and use it in GitHub Desktop.
gisthead.cgi
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require "cgi"
gistbase = 'http://gist.github.com'
cgi = CGI.new
params = cgi.params
begin
doc = Hpricot(open(gistbase + "/" + params['id'].to_s))
rawhead = doc.at("/html/body/div/div[2]/div/div[2]/div/div/div[2]/a")['href']
cgi.out("text/plain") {
open(gistbase + rawhead).read
}
rescue OpenURI::HTTPError, NoMethodError, RuntimeError
cgi.out("text/plain") {
'return "Gist Gateway Error"'
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment