kAworu's avatar

to paste or not to paste

publié par kAworu
il y a plus d'un an

C'est triste, mais dans les ports on trouve plus de serveurs de paste que de clients.

Un temps, j'usais de pastebinit jusqu'à ce qu'il décide de plus-marche. Là j'étais tout *aigr*, car à part wgetpaste qui a le mauvais goût de dépendre de wget et *khof* bash, c'était désert.

Comme on dit par chez moi:

On est jamais mieux servi que par soi-même.

Donc voilà, je décide de prendre mon vim à deux mains et de coder un client pour (arbitrairement) pastebin.com, et mon mauvais goût à moi c'est ruby

here come a new challenger

spaste(1)

Tout ça pour dire que si toi aussi, t'es *aigr*, t'aimes paster comme un fou et tu trouves mon mauvais goût plus acceptable que d'installer wgetpaste (limite peut-être que t'aimes même ruby vu que t'as lu jusqu'ici), alors je te donne (gratuit) mon beau spaste.

mode pub ON

Si tout comme mon self tu codaz dans le langage de l'amour et que tu trouves aussi que REST c'est sexy comme tout alors profite de piquer le module REST::Connection de spaste:

# stolen and hacked REST module
#   from http://snipplr.com/view.php?codeview&id=2476
#
module REST
  require 'net/https'
  # all REST methods.
  Methods = {
      :GET    => Net::HTTP::Get,
      :POST   => Net::HTTP::Post,
      :PUT    => Net::HTTP::Put,
      :DELETE => Net::HTTP::Delete,
  }

  # HTTP connection handler class.
  # args can contains :username and :password key faut http basic auth.
  # args can contains :default_arg hash that will be sent for each request of
  #   this connection.
  # Example:
  #   REST::Connection.new 'http://my.sexy/url',
  #     :username => 'satan',
  #     :password => '666',
  #     :default_args => {:destination => 'Hell'}
  class Connection
    def initialize(base_url, args=Hash.new)
      @base_url = base_url
      @username = args[:username]
      @password = args[:password]
      @default_args = args[:default_args] || Hash.new
    end

    # send the HTTP request, method_sym should be a key of Methods.
    def request(method_sym, resource, args=nil)
      args = @default_args.merge(args || Hash.new)
      url  = URI.join(@base_url, resource)

      method = Methods[method_sym]
      if method::REQUEST_HAS_BODY
        req = method.new(url.request_uri)
        req.form_data = args
      else
        url.query = args.collect do |k,v|
          URI.encode(k.to_s) + (v.nil? ? '' : '=' + URI.encode(v.to_s))
        end.join('&')
        req = method.new(url.request_uri)
      end

      if @username and @password
        req.basic_auth(@username, @password)
      end

      http = Net::HTTP.new(url.host, url.port)
      http.use_ssl = (url.port == 443)

      $stderr.puts "#{method_sym} #{url}" if $DEBUG
      http.start { |conn| conn.request(req) }
    end
  end
end

Parenthèse bave, parce que vendredi c'est tout bientôt

pastebin.com niveau support des langages c'est la teuf, y a de tout et (beaucoup) de n'importe quoi. Par exemple (y'a bash, non ok j'arrête):

bf            -- BrainFuck
c_mac         -- C for Macs   # ???
lolcode       -- LOL Code
mirc          -- mIRC
whitespace    -- WhiteSpace

Mais bon, suffit de pas en user, pis y a aussi des trucs qui surprennent en bien:

bibtex        -- BibTeX
bnf           -- BNF
rails         -- Rails
scala         -- Scala
vim           -- VIM

Deux pour le prix d'un!

Et histoire d'être bon commerçant, voilà en cadeau bonus le --help des langages supportés par pastebin.com.

[alex@FriteBSD ~] % spaste --help
usage: spaste [options] [file]

  if `file' is not given as argument, stdin is read.

options:
    -h, --help                       show this help
    -m, --email EMAIL                for sending confirmation email with paste link.
    -s, --subdomain SUBDOMAIN        for using a certain subdomain.
    -p, --private                    for making it private.
    -l, --list                       output the accepted format argument
    -f, --format FMT                 for adding syntax highlighting. (see -l for accepted values)
    -e, --expire DATE                for adding expiration date. N = Never, 10M = 10 Minutes, 1H = 1 Hour, 1D = 1 Day, 1M = 1 Month.
[alex@FriteBSD ~] % spaste --list
abap          -- ABAP
actionscript  -- ActionScript
actionscript3 -- ActionScript 3
ada           -- Ada
apache        -- Apache Log
applescript   -- AppleScript
apt_sources   -- APT Sources
asm           -- ASM (NASM)
asp           -- ASP
autoit        -- AutoIt
avisynth      -- Avisynth
bash          -- Bash
basic4gl      -- Basic4GL
bf            -- BrainFuck
bibtex        -- BibTeX
blitzbasic    -- Blitz Basic
bnf           -- BNF
boo           -- BOO
c             -- C
c_mac         -- C for Macs
caddcl        -- CAD DCL
cadlisp       -- CAD Lisp
cfdg          -- CFDG
cfm           -- ColdFusion
cill          -- C Intermediate Language
cmake         -- CMake
cobol         -- COBOL
cpp           -- C++
csharp        -- C#
css           -- CSS
d             -- D
dcs           -- DCS
delphi        -- Delphi
dff           -- Diff
div           -- DIV
dos           -- DOS
dot           -- DOT
eiffel        -- Eiffel
email         -- Email
erlang        -- Erlang
fo            -- FO Language
fortran       -- Fortran
freebasic     -- FreeBasic
genero        -- Genero
gettext       -- GetText
glsl          -- OpenGL Shading
gml           -- Game Maker
gnuplot       -- Ruby Gnuplot
groovy        -- Groovy
haskell       -- Haskell
hq9plus       -- HQ9 Plus
html4strict   -- HTML
idl           -- IDL
ini           -- INI file
inno          -- Inno Script
intercal      -- INTERCAL
io            -- IO
java          -- Java
java5         -- Java 5
javascript    -- JavaScript
kixtart       -- KiXtart
klonec        -- Clone C
klonecpp      -- Clone C++
latex         -- Latex
lisp          -- Lisp
locobasic     -- Loco Basic
lolcode       -- LOL Code
lotusformulas -- Lotus Formulas
lotusscript   -- Lotus Script
lscript       -- LScript
lsl2          -- Linden Scripting
lua           -- Lua
m68k          -- M68000 Assembler
make          -- Make
matlab        -- MatLab
mirc          -- mIRC
modula3       -- Modula 3
mpasm         -- MPASM
mxml          -- MXML
mysql         -- MySQL
nsis          -- NullSoft Installer
oberon2       -- Oberon 2
objc          -- Objective C
ocaml         -- OCaml
ocaml-brief   -- OCalm Brief
oobas         -- Openoffice BASIC
oracle11      -- Oracle 11
oracle8       -- Oracle 8
pascal        -- Pascal
pawn          -- PAWN
per           -- Per
perl          -- Perl
php           -- PHP
php-brief     -- PHP Brief
pic16         -- Pic 16
pixelbender   -- Pixel Bender
plsql         -- PL/SQL
povray        -- POV-Ray
powershell    -- Power Shell
progress      -- Progress
prolog        -- Prolog
properties    -- Properties
providex      -- ProvideX
python        -- Python
qbasic        -- QBasic
rails         -- Rails
rebol         -- REBOL
reg           -- REG
robots        -- Robots
ruby          -- Ruby
sas           -- SAS
scala         -- Scala
scheme        -- Scheme
scilab        -- Scilab
sdlbasic      -- SdlBasic
smalltalk     -- Smalltalk
smarty        -- Smarty
sql           -- SQL
tcl           -- TCL
teraterm      -- Tera Term
text          -- None
thinbasic     -- thinBasic
tsql          -- T-SQL
typoscript    -- TypoScript
unreal        -- unrealScript
vb            -- VisualBasic
vbnet         -- VB.NET
verilog       -- VeriLog
vhdl          -- VHDL
vim           -- VIM
visualfoxpro  -- VisualFoxPro
visualprolog  -- Visual Pro Log
whitespace    -- WhiteSpace
whois         -- WHOIS
winbatch      -- Win Batch
xml           -- XML
xorg_conf     -- Xorg Config
xpp           -- XPP
z80           -- Z80 Assembler
[alex@FriteBSD ~] %
un commentaire

écrire un commentaire

  1. jadawin il y a plus d'un an jadawin's avatar

    Et le port freebsd arrive quand? :)

écrire un commentaire:


(utilisé pour gravatar, ne sera pas affiché)



tu peux utiliser la syntaxe markdown :)