lobster.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. require 'zlib'
  2. require 'rack/request'
  3. require 'rack/response'
  4. module Rack
  5. # Paste has a Pony, Rack has a Lobster!
  6. class Lobster
  7. LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
  8. P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
  9. t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
  10. I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
  11. LambdaLobster = lambda { |env|
  12. if env["QUERY_STRING"].include?("flip")
  13. lobster = LobsterString.split("\n").
  14. map { |line| line.ljust(42).reverse }.
  15. join("\n")
  16. href = "?"
  17. else
  18. lobster = LobsterString
  19. href = "?flip"
  20. end
  21. content = ["<title>Lobstericious!</title>",
  22. "<pre>", lobster, "</pre>",
  23. "<a href='#{href}'>flip!</a>"]
  24. length = content.inject(0) { |a,e| a+e.size }.to_s
  25. [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
  26. }
  27. def call(env)
  28. req = Request.new(env)
  29. if req.GET["flip"] == "left"
  30. lobster = LobsterString.split("\n").
  31. map { |line| line.ljust(42).reverse }.
  32. join("\n")
  33. href = "?flip=right"
  34. elsif req.GET["flip"] == "crash"
  35. raise "Lobster crashed"
  36. else
  37. lobster = LobsterString
  38. href = "?flip=left"
  39. end
  40. res = Response.new
  41. res.write "<title>Lobstericious!</title>"
  42. res.write "<pre>"
  43. res.write lobster
  44. res.write "</pre>"
  45. res.write "<p><a href='#{href}'>flip!</a></p>"
  46. res.write "<p><a href='?flip=crash'>crash!</a></p>"
  47. res.finish
  48. end
  49. end
  50. end
  51. if $0 == __FILE__
  52. require 'rack'
  53. require 'rack/showexceptions'
  54. Rack::Handler::WEBrick.run \
  55. Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
  56. :Port => 9292
  57. end