Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
require 'geoloqi'
enable :sessions
configure do
Geoloqi.config :client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET'
kyledrake / gist:1128433
Created August 5, 2011 20:25
Rubinius day web server parallelism benchmarking tests
### TEST 1: Simple Rack app RAW AND DUMB
class HelloRubinius
def call(env)
return [
{'Content-Type' => 'text/html'},
['Hello #rbxday!']
kyledrake /
Created August 23, 2011 21:08
Debugging Kirk $stderr issue
require 'rubygems'
require 'sinatra/base'
require 'kirk'
require 'ruby-debug'
run {
get '/' do
# debugger
$stdout.puts 'Testing $stdout!'
$stderr.puts 'Testing $stderr!'
kyledrake / gist:1498932
Last active August 2, 2016 04:31
Neocities' Rainbows! config file -
# This is Neocities' Rainbows! config file. We are using this in production to run all our web apps.
# It works really well for us and has been heavily load tested, so I wanted to share it with the community.
# In my opinion, this is the best way to deploy a ruby web application. Unlike EventMachine based solutions,
# it uses real ruby threads, which allows it to take advantage of the internal non-blocking IO pattern
# in MRI.
# Contrary to popular belief, MRI doesn't block execution to wait on IO when you are using threads, even
# with the GIL. The requests are done concurrently for anything that is based on the IO class. This
# includes things like Net::HTTP and even `system commands`. Grep the MRI Ruby source code for
kyledrake / gist:1566576
Created January 5, 2012 18:40
Fix for AWS::S3 thread safety issues
require 'aws/s3'
class D7Obj < AWS::S3::S3Object
set_current_bucket_to "kd-test"
class S3Handler
:access_key_id => 'ID',
kyledrake / paranoid_delete.rb
Created February 22, 2012 18:32
Quick and dirty "paranoid delete" for Sequel
module Sequel
module ParanoidDelete
def self.included(base)
# Instead of actually deleting, we just set is_deleted to true,
# and look for it with our default dataset filter.
def delete
kyledrake / gist:2119737
Created March 19, 2012 17:13
How to rotate logs with Rainbows!
# Put this in a logrotate file (like /etc/logrotate.d/yourcompany):
rotate 7
size 5M
kyledrake / gist:2120107
Created March 19, 2012 17:24
Rainbows! config file for use with EventMachine
# This is a configuration script for using Rainbows with EventMachine. I'm providing it incase somebody finds it useful. But honestly, you
# should stop using EventMachine and use threads instead. The ThreadPool version of this is also in my gist list, and I recommend taking a look at that instead.
Rainbows! do
name = 'yourappname'
use :EventMachine
client_max_body_size nil # This is set in nginx
# keepalive_timeout 1
kyledrake / password.rb
Created June 6, 2012 18:55
Geoloqi's Password Encryption Code
# Due to recent concerns regarding password safety, Geoloqi has decided to publicly release the code
# that we use to do password hashing. After consulting with the community, this code now uses BCrypt for hashing
# (, which is based on blowfish, uses an integrated
# salting mechanism, and makes brute forcing expensive for attackers. It is widely used in the industry for
# production environments.
# Improvement suggestions are always welcome. Geoloqi takes security very seriously, and designs our systems to
# be as security-oriented as practically possible. We also believe in security transparency, because it leads to
# better security than obscurity, and is a more honest interaction with our customers.
kyledrake / gist:3077989
Created July 9, 2012 18:14
Ruby code for doing P12 to PEM conversion via command line. Supports MRI/JRuby/Rubinius
require 'tempfile'
require 'openssl'
require 'escape' # gem install escape
class CommandFailError < StandardError; end
def p12_to_pem_text(p12, pass='')
pass = '' if pass.nil?
# Use shell command for JRuby (see