Upgrade to Pro — share decks privately, control downloads, hide ads and more …

eurucamp 2012: Almost Sinatra

eurucamp 2012: Almost Sinatra

A fun code analysis.

Konstantin Haase

August 18, 2012
Tweet

More Decks by Konstantin Haase

Other Decks in Technology

Transcript

  1. Sinatra in 8 Lines How to do crazy stuff with

    ruby %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{extend  Rack;a,D,S,$p,q,Applica)on=Builder.new,Object.method(:define_method),/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a %w[get  post  put  delete].map{|m|D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" Saturday, August 18, 12
  2. “second to K&R, the most lagom technical book I’ve read.”

    Peter  Cooper  (Ruby  Inside) discount code: AUTHD 50% off ebook ($6.50) 40% OFF PRINT Saturday, August 18, 12
  3. Until programmers stop acting like obfuscation is morally hazardous, they’re

    not artists, just kids who don’t want their food to touch. why  the  lucky  s(ff Saturday, August 18, 12
  4. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{extend  Rack;a,D,S,$p,q,Applica)on=Builder.new,Object.method(:define_method),/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a

    %w[get  post  put  delete].map{|m|D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" the code Saturday, August 18, 12
  5. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{extend  Rack;a,D,S,$p,q,Applica)on=Builder.new,Object.method(:define_method),/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a

    %w[get  post  put  delete].map{|m|D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" the code Saturday, August 18, 12
  6. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{ extend  Rack;

    a,D,S,$p,q,Applica)on =Builder.new, Object.method(:define_method),/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a %w[ get  post  put  delete].map{|m|D.(m){|u,&b| a.map(u){run-­‐>(e){ [200,{"Content-­‐Type"=>"text/html"}, [a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}}; a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" Saturday, August 18, 12
  7. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{extend  Rack;a, D,S,$p,q,Applica)on

    =Builder.new, Object.method(:define_method) ,/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a %w [get  post  put  delete].map{|m| D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v| D.(k){|n,*o| $t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[ set  enable  disable  configure  helpers  use  register]. map{|m| D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[ params  session].map{|m| D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b}; before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" Saturday, August 18, 12
  8. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new{extend  Rack;a,D, S,$p,q,Applica)on

    =Builder.new,Object.method(:define_method), /@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m,4567,a %w[get  post  put  delete].map{|m|D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o| $t||=(h={};File.read(caller[0][/^[^:]+/]) .scan(S){|a,b|h[a]=b};h); v[0].new(*o){n.to_s==n  ?n:$t[n.to_s]}. render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}};END{Handler.get("webrick").run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on  #$p  for  development  with  backup  from  Webrick" Saturday, August 18, 12
  9. %w.rack  )lt  backports  INT  TERM..map{|l|trap(l){$r.stop}rescue  require  l} $n=Sinatra=Module.new {extend  Rack;

    a,D,S, $p,q,Applica)on =Builder.new, Object.method(:define_method),/@@  *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m, 4567,a %w[get  post  put  delete].map{|m|D.(m){|u,&b|a.map(u){run-­‐>(e){[200,{"Content-­‐Type"=>"text/html"},[a.instance_eval(&b)]]}}}} Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h={};File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0]. new(*o){n.to_s==n  ?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}} %w[set  enable  disable  configure  helpers  use  register].map{|m|D.(m){|*_,&b|b.try  :[]}}; END{Handler.get("webrick"). run(a,Port:$p){|s|$r=s}} %w[params  session].map{|m|D.(m){q.send  m}};a.use  Session::Cookie;a.use  Lock D.(:before){|&b|a.use  Rack::Config,&b};before{|e|q=Request.new  e;q.params.dup.map{|k,v|params[k.to_sym]=v}}} puts  "==  almost  #$n/No  Version  has  taken  the  stage  on #$p  for  development  with  backup  from  Webrick" Saturday, August 18, 12
  10. “If your app does not run with Almost Sinatra, please

    open a Sinatra issue.” Konstan(n  Haase Saturday, August 18, 12
  11. “don't include tests. tests just bloat the code base. just

    commit, the users will complain if you break anything.” Konstan(n  Haase Saturday, August 18, 12