Skip to content

Instantly share code, notes, and snippets.

@satyr
Created March 30, 2010 20:16
Show Gist options
  • Save satyr/349539 to your computer and use it in GitHub Desktop.
Save satyr/349539 to your computer and use it in GitHub Desktop.
caddyr
GOLF_DIR = File.join(ENV['HOME'], '.golf')
require 'pstore'
require 'caddy/db'
require 'net/http/multipart'
Net::HTTP.version_1_2
@file = $*[0]
problem = $*[1] || file2problem(File.basename(@file, File.extname(@file)))
@data = {
'problem' => problem =~ /^http:\/\/golf.shinh.org\/p.rb\?/ && $',
'user' => get_user,
'reveal' => '1',
}
def submit
Net::HTTP.start('golf.shinh.org', 80) do |http|
req = Net::HTTP::Post.new('/submit.rb')
req.set_multipart_form_data({'file' => @file}, @data)
res = http.request(req)
if res.class.superclass != Net::HTTPSuccess
puts 'Failed to connect the golf server'
exit 1
end
body = res.read_body
body.gsub!(/<[^>]*>/, '')
body
end
end
i = 0
until /Success!.*?\n\n/m =~ r = submit
puts "#{i += 1}: #{r.scan(/(#\d)\nsuccess!/) * ' '}"
end
puts $&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment