Skip to content

Instantly share code, notes, and snippets.

@eiffelqiu
Created May 19, 2011 01:07
Show Gist options
  • Save eiffelqiu/979957 to your computer and use it in GitHub Desktop.
Save eiffelqiu/979957 to your computer and use it in GitHub Desktop.
ruby fetch gist snippet
#!/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