Created
February 24, 2009 07:15
-
-
Save vinbarnes/69457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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