Instantly share code, notes, and snippets.

@soveran
soveran / benchmarks.rb
Created Apr 23, 2015
Initial benchmarks of Rack, Syro and Cuba.
View benchmarks.rb
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'
@soveran
soveran / textorama
Created Jul 24, 2013
Plain shell version of textorama, contributed by @djanowski
View textorama
#!/bin/sh
hi=$(expr $(tput lines) - 1)
cp $1 $1.ts
ed -s $1.ts <<-EOS
1i
.pl ${hi}v
.
@soveran
soveran / sc
Created Jun 7, 2013
Command line reference of HTTP status codes for rc shell.
View sc
#!/usr/bin/env rc
if (! ~ $#* 1) {
echo 'Usage: sc <pattern>'
} else {
grep $1: $0
}
# 100: Continue
# 101: Switching Protocols
@soveran
soveran / config.ru
Last active Dec 18, 2015
Basic structure for a Cuba application.
View config.ru
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 / paginate.rb
Last active Feb 26, 2018
Pagination helper for Ohm models.
View paginate.rb
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 / gist:4198977
Created Dec 3, 2012
Hello proxy.openredis.com
View gist:4198977

As some of you may know, traffic within AWS is free, and traffic going outside of AWS has a small cost. We had never restricted outgoing traffic because it makes sense for our customers to access their database from their local environments. Everyone needs to run administrative commands every now and then, and that's totally fair.

Recently, we noticed an increase in traffic going outside of AWS, to the point that we were operating at a loss. We tried to contact all our customers to let them know that we would restrict that kind of usage, and effectively did so today. After all, we thought,

@soveran
soveran / config.ru
Created Apr 7, 2012
Small Cuba App.
View config.ru
require "cuba"
run Cuba.new { on(root) { res.write "hello, world" } }
@soveran
soveran / elements.md
Created Nov 18, 2011
Excerpts from The Elements of Programming Style. The source of this compilation is unknown.
View elements.md

The Elements of Programming Style

The following rules of programming style are excerpted from the book "The Elements of Programming Style" by Kernighan and Plauger, published by McGraw Hill. Here is quote from the book: "To paraphrase an observation in The Elements of Style by Strunk and White, the rules of programming style, like those of English, are sometimes broken, even by the best writers. When a rule is broken, however, you will usually find in the program some compensating merit, attained at the cost of the violation. Unless you are certain of doing as well, you will probably do best to follow the rules."

View sample.rb
require "ohm"
require "pp"
class Foo < Ohm::Model
def my_strings
key[:my_strings]
end
end
f = Foo.create
@soveran
soveran / userContent.css
Created Jun 10, 2011
Firefox tweak to hide plugin placeholders.
View userContent.css
/*
* Hide the "Click here to download plugin" flash placeholders.
*/
embed[type="application/x-shockwave-flash"] {
display: none !important;
}