------art_1229_15181557.1146663609312
Content-Type: multipart/alternative; 
	boundary---art_1230_8536093.1146663609312"

------art_1230_8536093.1146663609312
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 4/28/06, Ruby Quiz <james / grayproductions.net> wrote:

> The three rules of Ruby Quiz:
>
> 1.  Please do not post any solutions or spoiler discussion for this quiz
> until
> 48 hours have passed from the time on this message.
>
> 2.  Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.rubyquiz.com/
>
> 3.  Enjoy!
>
> Suggestion:  A [QUIZ] in the subject of emails about the problem helps
> everyone
> on Ruby Talk follow the discussion.  Please reply to the original quiz
> message,
> if you can.
>
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> by Sean Carley
>
> The goal of cat2rafb is to implement a command line utility that will
> allow you
> to submit arbitrary text to http://rafb.net/paste/ and get the URL for the
> text
> back.  Bonus points for pushing the URL through http://rubyurl.com/ to
> make it
> more manageable.
>
> cat2rafb could work like cat, taking files as input or text until ^D after
> entering the command.


Here's my solution, It's not the best, the smallest, the fastest or the
anything-est, but Ie learned a lot from looking at other people's
solutions for ealier Quizes and this might help someone else in time.

Francisco

#!/usr/bin/ruby
require 'net/http'
require 'uri'

class NoPaste
  attr_reader :answer

  def initialize( params={"lang"=>"Ruby","nick"=>"Myself",
"desc"=>"test","cvt_tabs"=>"No","text"=>"fetch","submit"=>"Paste" },
                      uri='http://rafb.net/paste/paste.php',
                      base_uri='http://rafb.net'
                    )
    @uri=uri
    @base_uri=base_uri
    @params=params
    @answer=fetch_post_rafbe
  end

  def fetch_post_rafbe
    response=Net::HTTP.post_form(URI.parse(@uri),@params)
    begin
      raise "Something went wrong while posting" unless response['location']

    rescue
      puts $!,"\n"
      exit
    end
    @base_uri+response['location']
  end

  def rubyurl
    puts "Compressing at rubyurl"
    uri=" http://rubyurl.com/rubyurl/remote?website_url=#{@answer}<http://rubyurl.com/rubyurl/remote?website_url=#%7B@answer%7D>
"
    response=Net::HTTP.get_response(URI.parse(uri))
    begin
      raise "Something went wrong while posting" unless response['location']

    rescue
      puts $!,"\n"
      exit
    end
    response['location'].gsub("rubyurl/show/","")

  end
end

if __FILE__ == $0
  require 'optparse'
  options={'lang'=>"Ruby",'nick'=>"myself",'desc'=>"",
               'text'=>"", 'file'=>nil, 'r'=>nil,
               "cvt_tabs"=>"No","submit"=>"Paste"  }
  opts=OptionParser.new do |opts|
    opts.banner= "Posts a code snippet to rafb.net and returns the
address\n"\
                      "so you can show it to your friends on IRC\n\n"\
                      "Usage: posttorafb [OPTIONS]"
    opts.separator ""
    opts.separator "Options:"
    opts.on("-l","--lang LANGUAGE",
              "LANGUAGE category.","  Default:Ruby") do |lang|
      LANGS = %w{C89 C C++ C# Java Pascal Perl PHP PL/I Python Ruby Scheme
SQL VB Plain\ Text}
      begin
        raise "Invalid Argument. Language must be one of:\n#{LANGS.join("
")}" unless LANGS.include?(lang)
      rescue
        puts $!,"\n"
        exit
      end
      options['lang']=lang
    end
    opts.on("-n","--nick NAME",
              "NAME to post under.","  Default:myself") do |nick|
      options['nick']=nick
    end
    opts.on("-d","--desc DESCRIPTION",
              "DESCRIPTION of snippet.","  Default:blank") do |desc|
      options['desc']=desc
    end
    opts.on("-f","--file FILE",
              "FILE containing snippet.","  Default: enter from console") do
|file|
      options['file']=file
    end
    opts.on("-r","--rubyurl", "Send to rubyurl.com for url shortening") do
|r|
      options['r']=true
    end
    opts.on_tail("-v", "--version", "Version") do
      puts "0.0.1"
      exit
    end
    opts.on_tail("-h", "--help", "Shows this message") do
      puts opts
      exit
    end
  end

  begin
    opts.parse!
  rescue
    puts $!,"\n"
    puts opts
    exit
  end

  if options['file'] then
    begin
      options['text']=File.open(options['file'],"r").read
      puts "Pasting snippet from file #{options['file']}"
    rescue
      puts $!,"\n"
      exit
    end
  else
    puts "Reading snippet from console, finish by entering <CTRL-Z> in a new
line"
    options['text']=$stdin.read
  end

  x=NoPaste.new(options)
  puts "Stored at: #{x.answer}"
  puts x.rubyurl if options['r']
end

------art_1230_8536093.1146663609312
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div style="direction: ltr;"><div></div><div style="direction: ltr;"><span class="q"><span class="gmail_quote">On 4/28/06, <b class="gmail_sendername">Ruby Quiz</b> &lt;<a href="mailto:james / grayproductions.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
james / grayproductions.net</a>&gt; wrote:</span></span></div><div style="direction: ltr;"><span class="e" id="q_10af74e899c0c6f3_2"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

The three rules of Ruby Quiz:<br><br>1.&nbsp;&nbsp;Please do not post any solutions or spoiler discussion for this quiz until<br>48 hours have passed from the time on this message.<br><br>2.&nbsp;&nbsp;Support Ruby Quiz by submitting ideas as often as you can:
<br><br><a href="http://www.rubyquiz.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.rubyquiz.com/</a><br><br>3.&nbsp;&nbsp;Enjoy!<br><br>Suggestion:&nbsp;&nbsp;A [QUIZ] in the subject of emails about the problem helps everyone
<br>on Ruby Talk follow the discussion.&nbsp;&nbsp;Please reply to the original quiz message,
<br>if you can.<br><br>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<br><br>by Sean Carley<br><br>The goal of cat2rafb is to implement a command line utility that will allow you<br>toubmit arbitrary text to 
<a href="http://rafb.net/paste/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rafb.net/paste/</a> and get the URL for the text<br>back.&nbsp;&nbsp;Bonus points for pushing the URL through <a href="http://rubyurl.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://rubyurl.com/</a> to make it<br>more manageable.
<br><br>cat2rafb could work like cat, taking files as input or text until ^D after<br>entering the command.</blockquote></span></div><div style="direction: ltr;"><div><br>Here's my solution, It's not the best, the smallest,he fastest or the anything-est, but Iエve learned a lot from looking at other people's solutions for ealier Quizes and this might help someone elsen time.
<br><br>Francisco<br><br>#!/usr/bin/ruby<br>require 'net/http'<br>require 'uri'<br><br>class NoPaste<br>&nbsp; attr_reader :answer<br>&nbsp; <br>&nbsp; def initialize( params={&quot;lang&quot;=&gt;&quot;Ruby&quot;,&quot;nick&quot;=&gt;&quot;Myself&quot;, &quot;desc&quot;=&gt;&quot;test&quot;,&quot;cvt_tabs&quot;=&gt;&quot;No&quot;,&quot;text&quot;=&gt;&quot;fetch&quot;,&quot;submit&quot;=&gt;&quot;Paste&quot; },
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uri='<a href="http://rafb.net/paste/paste.php" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rafb.net/paste/paste.php</a>',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base_uri='<a href="http://rafb.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://rafb.net</a>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )
<br>&nbsp;&nbsp;&nbsp; @uri=uri<br>&nbsp;&nbsp;&nbsp; @base_uri=base_uri<br>&nbsp;&nbsp;&nbsp; @params=params<br>&nbsp;&nbsp;&nbsp; @answer=fetch_post_rafbe<br>&nbsp; end<br>&nbsp; <br>&nbsp; def fetch_post_rafbe<br>&nbsp;&nbsp;&nbsp; response=Net::HTTP.post_form(URI.parse(@uri),@params)<br>&nbsp;&nbsp;&nbsp; begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise &quot;Something went wrong while posting&quot; unless response['location']
<br>&nbsp;&nbsp;&nbsp; rescue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts $!,&quot;\n&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; @base_uri+response['location']<br>&nbsp; end<br>&nbsp; <br>&nbsp; def rubyurl<br>&nbsp;&nbsp;&nbsp; puts &quot;Compressing at rubyurl&quot;<br>&nbsp;&nbsp;&nbsp; uri=&quot;<a href="http://rubyurl.com/rubyurl/remote?website_url=#%7B@answer%7D" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

http://rubyurl.com/rubyurl/remote?website_url=#{@answer}</a>&quot;<br>&nbsp;&nbsp;&nbsp; response=Net::HTTP.get_response(URI.parse(uri))<br>&nbsp;&nbsp;&nbsp; begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise &quot;Something went wrong while posting&quot; unless response['location']
<br>&nbsp;&nbsp;&nbsp; rescue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts $!,&quot;\n&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; response['location'].gsub(&quot;rubyurl/show/&quot;,&quot;&quot;)</div><div style="direction: ltr;"><span class="q"><br>&nbsp; end<br>end<br><br>if __FILE__ == $0
<br></span></div><div style="direction: ltr;">&nbsp; require 'optparse'<br>&nbsp; options={'lang'=&gt;&quot;Ruby&quot;,'nick'=&gt;&quot;myself&quot;,'desc'=&gt;&quot;&quot;,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'text'=&gt;&quot;&quot;, 'file'=&gt;nil, 'r'=&gt;nil, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;cvt_tabs&quot;=&gt;&quot;No&quot;,&quot;submit&quot;=&gt;&quot;Paste&quot;&nbsp; }<br>&nbsp; opts=OptionParser.new do |opts|<br>&nbsp;&nbsp;&nbsp; 
opts.banner=
&quot;Posts a code snippet to <a href="http://rafb.net" target="_blank"nclick="return top.js.OpenExtLink(window,event,this)">rafb.net</a> and returns the address\n&quot;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;so you can show it to your friends on IRC\n\n&quot;\
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;Usage: posttorafb [OPTIONS]&quot;
<br>&nbsp;&nbsp;&nbsp; opts.separator &quot;&quot;<br>&nbsp;&nbsp;&nbsp; opts.separator &quot;Options:&quot;<br>&nbsp;&nbsp;&nbsp; opts.on(&quot;-l&quot;,&quot;--lang LANGUAGE&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;LANGUAGE category.&quot;,&quot;&nbsp; Default:Ruby&quot;) do |lang|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LANGS = %w{C89 C C++ C# Java Pascal Perl PHP PL/I Python Ruby Scheme SQL VB Plain\ Text}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise &quot;Invalid Argument. Language must be one of:\n#{LANGS.join(&quot; &quot;)}&quot; unless 
LANGS.include?(lang)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rescue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts $!,&quot;\n&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['lang']=lang<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; opts.on(&quot;-n&quot;,&quot;--nick NAME&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;NAME to post under.&quot;,&quot;&nbsp; Default:myself&quot;) do |nick|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['nick']=nick<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; opts.on(&quot;-d&quot;,&quot;--desc DESCRIPTION&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;DESCRIPTION of snippet.&quot;,&quot;&nbsp; Default:blank&quot;) do |desc|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['desc']=desc
<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; opts.on(&quot;-f&quot;,&quot;--file FILE&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;FILE containing snippet.&quot;,&quot;&nbsp; Default: enter from console&quot;) do |file|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['file']=file<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; 
opts.on(&quot;-r&quot;,&quot;--rubyurl&quot;, &quot;Send to <a href="http://rubyurl.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rubyurl.com</a> for url shortening&quot;) do |r|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['r']=true
<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; opts.on_tail(&quot;-v&quot;, &quot;--version&quot;, &quot;Version&quot;) do
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;0.0.1&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;Shows this message&quot;)o<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts opts<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; end<br><br>&nbsp; begin<br>
&nbsp;&nbsp;&nbsp; 
opts.parse!<br>&nbsp; rescue <br>&nbsp;&nbsp;&nbsp; puts $!,&quot;\n&quot;<br>&nbsp;&nbsp;&nbsp; puts opts<br>&nbsp;&nbsp;&nbsp; exit<br>&nbsp; end&nbsp; <br><br>&nbsp; if options['file'] then<br>&nbsp;&nbsp;&nbsp; begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options['text']=File.open(options['file'],&quot;r&quot;).read<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;Pasting snippet from file #{options['file']}&quot;
<br>&nbsp;&nbsp;&nbsp; rescue<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts $!,&quot;\n&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; puts &quot;Reading snippet from console, finish by entering &lt;CTRL-Z&gt; in a new line&quot;<br>&nbsp;&nbsp;&nbsp; options['text']=$stdin.read<br>

&nbsp; end<br><br>&nbsp; x=NoPaste.new(options)<br>&nbsp; puts &quot;Stored at: #{x.answer}&quot; <br>&nbsp; puts x.rubyurl if options['r'] <br>end<br></div><br></div><br>

</div><br clear="all">

------art_1230_8536093.1146663609312--

------art_1229_15181557.1146663609312
Content-Type: application/octet-stream; name=77.rb
Content-Transfer-Encoding: 7bit
X-Attachment-Id: f_emqu7g67
Content-Disposition: attachment; filename="77.rb"

#!/usr/bin/ruby
require 'net/http'
require 'uri'

class NoPaste
  attr_reader :answer
 
  def initialize( paramslang"Ruby","nick"Myself", "desc"test","cvt_tabs"No","text"fetch","submit"Paste" },
                      urittp://rafb.net/paste/paste.php',
                      base_urittp://rafb.net'                  
                    )
    @urii
    @base_uriコse_uri
    @params
rams
    @answerch_post_rafbe
  end
 
  def fetch_post_rafbe
    responseココネヤヤミョ゜ィユメノョィタゥャタゥ
    
       「モ    「  ロァァン
    
       、。ャ「ワ「
      
    
    タ゜ォロァァン
  
 
   
     「テ  「
    コッッョッッソ゜タ「
    ココネヤヤミョ゜ィユメノョィゥゥ
    
       「モ    「  ロァァン
    
       、。ャ「ワ「
      
    
    ロァァンョィ「ッッ「ャ「「ゥ
  


 ゜゜ニノフナ゜゜ 、ー
   ァァ
  ァメ「ャァァ「ャァァ「ャ
               ァァ「ャ ァァャ ァァャ
               「゜「ホ「ャ「「ミ「  
  ミョ  
    ョ     ョ    ワ「ワ
                      「         ノメテワワ「ワ
                      「ユコ  ロマミヤノマホモン「
    ョ 「「
    ョ 「マコ「
    ョィ「ュ「ャ「ュュ フチホヌユチヌナ「ャ
              「フチホヌユチヌナ ョ「ャ「  トコメ「ゥ  
      フチホヌモ  テクケ テ テォォ テ」 ハ ミ ミ ミネミ ミフッノ ミ メ モ モムフ ヨツ ミワ ヤ
      
         「ノ チョ フ    コワ」フチホヌモョィ「 「ゥ「  フチホヌモョソィゥ
      
         、。ャ「ワ「
        
      
      ロァァン

    
    ョィ「ュ「ャ「ュュ ホチヘナ「ャ
              「ホチヘナ   ョ「ャ「  トコ「ゥ  
      ロァァン
    
    ョィ「ュ「ャ「ュュ トナモテメノミヤノマホ「ャ
              「トナモテメノミヤノマホ  ョ「ャ「  トコ「ゥ  
      ロァァン枹
    
    ョィ「ュ「ャ「ュュ ニノフナ「ャ
              「ニノフナ  ョ「ャ「  トコ   「ゥ  
      ロァァン
    
    ョィ「ュ「ャ「ュュ「ャ 「モ  ョ   「ゥ  
      ロァァン
    
    ョ゜ィ「ュ「ャ 「ュュ「ャ 「ヨ「ゥ 
       「ーョーョア「
      
    
    ョ゜ィ「ュ「ャ 「ュュ「ャ 「モ  「ゥ 
       
      
    
  

  
    ョ。
  
     、。ャ「ワ「
     
    
   

   ロァァン 
    
      ロァァンョィロァァンャ「「ゥョ
       「ミ    」ロァァン「
    
       、。ャ「ワ「
      
    
  
     「メ   ャ    シテヤメフュレセ    「
    ロァァンョ
  

  ミョィゥ
   「モ コ 」ョ「
   ョ  ロァァン



ュュュュュュ゜アイイケ゜アオアクアオオキョアアエカカカウカーケウアイュュ