Skip to content

Instantly share code, notes, and snippets.

@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'
class Ssh < Thor
desc "copy", "Copies the public key to a remote server"
def copy(server)
system %Q{cat ~/.ssh/id_dsa.pub | ssh #{server} "cat >> ~/.ssh/authorized_keys"}
end
end
module Slug
def to_param
"#{super}-#{slug}"
end
def slug
to_s.gsub("'", "").gsub(/\p{^Alnum}/u, " ").strip.gsub(/\s+/, "-").downcase
end
end
require "redis"
require "nest"
redis = Redis.new
users = Nest.new(:users, redis)
posts = Nest.new(:posts, redis)
user = users[users.incr]
user.hmset(:name, "Albert")
@soveran
soveran / go.rb
Created September 23, 2010 15:03
require "go/gtp/board"
require "cutest"
setup do
string = <<-EOS.gsub(/^ {2}/, "")
A B C D E F G H J
9 . . . . . . . . . 9
8 . . . . . . . . . 8
7 . . X . . . + . . 7
6 . . . . . . . . . 6
@soveran
soveran / userContent.css
Created June 10, 2011 14:31
Firefox tweak to hide plugin placeholders.
/*
* Hide the "Click here to download plugin" flash placeholders.
*/
embed[type="application/x-shockwave-flash"] {
display: none !important;
}
require "ohm"
require "pp"
class Foo < Ohm::Model
def my_strings
key[:my_strings]
end
end
f = Foo.create
@soveran
soveran / config.ru
Created April 7, 2012 17:29
Small Cuba App.
require "cuba"
run Cuba.new { on(root) { res.write "hello, world" } }
@soveran
soveran / gist:4198977
Created December 3, 2012 23:13
Hello proxy.openredis.com

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
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_"