Skip to content

Instantly share code, notes, and snippets.

@soveran
soveran / paginate.rb
Last active February 26, 2018 07:32
Pagination helper for Ohm models.
def paginate(collection, options = {})
start = options[:start] || 0
limit = options[:limit] || 0
order = options[:order]
rest = collection.size > (start + limit)
page = collection.sort(order: order, start: start, limit: limit)
[rest, page]
end
@soveran
soveran / config.ru
Last active December 18, 2015 00:49
Basic structure for a Cuba application.
require "cuba"
# Here you can add helpers, models, filters, services, etc.
Dir["./routes/**/*.rb"].each { |rb| require rb }
Cuba.use Rack::MethodOverride
Cuba.use Rack::Session::Cookie,
key: "_app_name_",
secret: "_app_secret_"
@soveran
soveran / sc
Created June 7, 2013 22:56
Command line reference of HTTP status codes for rc shell.
#!/usr/bin/env rc
if (! ~ $#* 1) {
echo 'Usage: sc <pattern>'
} else {
grep $1: $0
}
# 100: Continue
# 101: Switching Protocols
@soveran
soveran / textorama
Created July 24, 2013 00:59
Plain shell version of textorama, contributed by @djanowski
#!/bin/sh
hi=$(expr $(tput lines) - 1)
cp $1 $1.ts
ed -s $1.ts <<-EOS
1i
.pl ${hi}v
.
@soveran
soveran / benchmarks.rb
Created April 23, 2015 14:39
Initial benchmarks of Rack, Syro and Cuba.
require "benchmark"
require "cuba"
require "syro"
class HelloWorld
def call(env)
if env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/foo/bar'
[200, {"Content-Type" => "text/html"}, ["hello world"]]
elsif env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/admin'