utility_belt tweak 2 - passing a string directly to pastie

Posted by Tim Connor Wed, 12 Dec 2007 00:57:00 GMT

Instead of having to run it through the clipboard first:

def pastie(string=nil)
  pastie_url = Net::HTTP.post_form(URI.parse("http://pastie.caboo.se/pastes/create"),
                                   {"paste_parser" => "ruby",
                                    "paste[authorization]" => "burger",
                                    "paste[body]" => (string || MacClipboard.read)}).body.match(/href="([^\"]+)"/)[1]
  MacClipboard.write(pastie_url)
  system("open #{pastie_url}")
  pastie_url
end

If you are wondering WTF is going on, read the previous post

Comment form

(leave url/email »)

Help with Textile (code)