Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
require 'geoloqi'
GEOLOQI_REDIRECT_URI = 'http://yourwebsite.net'
enable :sessions
configure do
Geoloqi.config :client_id => 'YOUR OAUTH CLIENT ID', :client_secret => 'YOUR CLIENT SECRET'
@kyledrake
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 [
200,
{'Content-Type' => 'text/html'},
['Hello #rbxday!']
]
end
@kyledrake
kyledrake / config.ru
Created August 23, 2011 21:08
Debugging Kirk $stderr issue
require 'rubygems'
require 'sinatra/base'
require 'kirk'
require 'ruby-debug'
run Sinatra.new {
get '/' do
# debugger
$stdout.puts 'Testing $stdout!'
$stderr.puts 'Testing $stderr!'
'hi'
@kyledrake
kyledrake / gist:1498932
Last active August 2, 2016 04:31
Neocities' Rainbows! config file - https://neocities.org
# 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
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"
end
class S3Handler
AWS::S3::Base.establish_connection!(
:access_key_id => 'ID',
@kyledrake
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)
base.extend(ClassMethods)
end
# Instead of actually deleting, we just set is_deleted to true,
# and look for it with our default dataset filter.
def delete
@kyledrake
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):
/var/log/yourcompany/website.log
{
daily
rotate 7
compress
missingok
notifempty
sharedscripts
size 5M
@kyledrake
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.
# NO, SERIOUSLY, STOP USING EVENTMACHINE.
Rainbows! do
name = 'yourappname'
use :EventMachine
client_max_body_size nil # This is set in nginx
# keepalive_timeout 1
@kyledrake
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
# (http://codahale.com/how-to-safely-store-a-password), 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
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 https://github.com/jruby/jruby-ossl/issues/8)