Skip to content

Instantly share code, notes, and snippets.

@syntacticsugar
Created December 15, 2014 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syntacticsugar/12bfecc8c7b1877e0f8d to your computer and use it in GitHub Desktop.
Save syntacticsugar/12bfecc8c7b1877e0f8d to your computer and use it in GitHub Desktop.
module Sinatra
module Kittens
module Helpers
def kittens_page(x = 200..500, factor = 0.2)
sample_method = RUBY_VERSION >= '1.9' ? :sample : :choice
x = x.to_a.send(sample_method)
y = ((x - factor*x).floor..(x + factor*x).ceil).to_a.send(sample_method)
<<-HTML
<!DOCTYPE html>
<html>
<head>
<title>Not found</title>
</head>
<body>
<center>
<h1>Page not found</h2>
<img src="http://placekitten.com/#{x}/#{y}" alt="Kitten!" height="#{x}" width="#{y}">
</center>
</body>
</html>
HTML
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment