Created
May 19, 2011 01:07
-
-
Save eiffelqiu/979957 to your computer and use it in GitHub Desktop.
ruby fetch gist snippet
This file contains 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 'rubygems' | |
require 'hpricot' | |
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
require 'tempfile' | |
test_http = "https://gist.github.com/69457.txt" | |
uri = URI(test_http) | |
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))} | |
tempfile = Tempfile.new('gist') | |
tempfile.puts(result) | |
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