Skip to content

Instantly share code, notes, and snippets.

@vinbarnes
Created July 21, 2010 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vinbarnes/484817 to your computer and use it in GitHub Desktop.
Save vinbarnes/484817 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
require 'hpricot'
require 'net/http'
require 'net/https'
require 'uri'
require 'tempfile'
test_http = "http://gist.github.com/69452"
test_https = "https://gist.github.com/42af948558a3b3704bab"
uri = URI(ARGV[0])
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
result = http.start {|h| h.request(Net::HTTP::Get.new(uri.path))}
doc = Hpricot(result.body)
raw_path = doc.at("a[@href*=raw]")['href']
raw_file = http.start {|h| h.request(Net::HTTP::Get.new(raw_path))}
tempfile = Tempfile.new('gist')
tempfile.puts(raw_file.body)
tempfile.close
if system('which qlmanage')
system("qlmanage -c public.plain-text -p #{tempfile.path} >& /dev/null")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment