My first Ruby script
Yesterday I wrote my first Ruby script, it’s just a little script that lets you paste easily the contents of your clipboard in RAFB Nopaste.
It justs takes the content of your clipboard, posts it to rafb.net and replaces your clipboard content with the URL received from rafb.net.
It interacts with the clipboard using DCOP and Klipper, so it only works
in KDE, although it should be easily modifiable, in fact, dato has already modified the script to be able to paste from standard input.
Here is the code:
#!/usr/bin/ruby
require 'Korundum'
require 'net/http'
about = KDE::AboutData.new("paster", "RAFB paster", "0.1")
KDE::CmdLineArgs.init(ARGV, about)
a = KDE::Application.new()
klipper = KDE::DCOPRef.new("klipper", "klipper")
text = klipper.getClipboardContents
text.gsub!(/[^A-Za-z0-9]/) { sprintf("%%%02X", $&[0])}
Net::HTTP.start('rafb.net', 80) { |http|
response = http.post('/paste/paste.php',
"nick=#{ENV['LOGNAME']}&desc=&cvt_tabs=no&text=#{text}")
klipper.clipboardContents = "http://rafb.net#{response['Location']}"
}