On 5/5/06, Ed Howland <ed.howland / gmail.com> wrote:
> On 5/5/06, Dave Burt <dave / burt.id.au> wrote:
> > I suppose Sean Carley's solution came in too late for the summary, but I
> > think it's definitely worth looking at for its terseness. Here's a bonus
> > summary.
> >
> > >   #!/usr/bin/ruby
> > >   require 'uri'
> > >   require 'net/http'
> >
> > So Sean's using a couple of libraries like the other solutions.
> > Actually, just one, really: net/http. You don't need to explicitly
> > require 'uri'; net/http requires it. No command-line switches here.
> >
> > Watch as a complete solution unfolds in just three lines. You can
> > probably read it just as well without my commentary.
> >
> > > result = Net::HTTP.post_form(URI.parse('http://rafb.net/paste/paste.php'),
> > >                             {:text => ARGF.readlines,
> > >                              :nick => 'paste user',
> > >                              :lang => 'Ruby'})
> >
> > Line one uses Net::HTTP.post_form to send a form-style POST request and
> > get back the result. post_form takes two parameters, the target URI, and
> > a hash of form data.
> >
> > The value of the form variable "text" comes from ARGF (like Stefano
> > Taschini's solution and others) which will get input from filenames
> > given as command-line arguments or from standard input.
>
> Yes, Sean's RubyGolf implementation is very good, and plus. it showed
> the essence of problem space in about 1 line of code. A lot of the
> other solutions (even mine!) went to some expense setting up variable
> options, error handing, well factored code, etc. But the goal of the
> quiz was to paste the input to rafb.net and get the URL back. Which
> his does elegantly.
>
> Not that the other solutions were not good. They showed how to write
> idiomatic ruby to solve this general class of problems, and I learned
> a lot from reading them, which is the goal of the quiz in general.
>
> Sean freely admits his approach was "slash and burn farming," and it
> wouldn't work if you wanted to paste "Plain Text" or some other
> language. I say, however, that the nopaste website and using it with
> IRC indicates a simple solution. If you were pairing or collaborating
> over the net and wanted something like this and you didn't have it,
> you could code it in Ruby in a very few minutes.
>
> BTW, we (Sean, Craig Bucheck and I,) worked on this as this week's
> StL.rb (St. Louis Ruby group) weekly hacking night project. Ruby group
> members across the land are meeting on the same weeknight as the
> regular meeting to participate in Ruby code pair-programming or
> working on common problems for general edification. The RubyQuiz which
> comes out about once a week makes for a good topic. Try it out in your
> own HackNight.
>
> >
> > Cheers,
> > Dave
>
> Till later,
> Ed
>

I forgot to link to the code for my solution, actually. Doh!
Running site: http://rpaste.com/
Code: http://svn.supremetyrant.com/paste/
Code LOC: 66     Test LOC: 75     Code to Test Ratio: 1:1.1