Skip to content

Instantly share code, notes, and snippets.

View gist:1007336
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 Aug 5, 2011
Rubinius day web server parallelism benchmarking tests
View gist:1128433
### 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 Aug 23, 2011
Debugging Kirk $stderr issue
View config.ru
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 Aug 2, 2016
Neocities' Rainbows! config file - https://neocities.org
View gist:1498932
# 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 Jan 5, 2012
Fix for AWS::S3 thread safety issues
View gist:1566576
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 Feb 22, 2012
Quick and dirty "paranoid delete" for Sequel
View paranoid_delete.rb
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 Mar 19, 2012
How to rotate logs with Rainbows!
View gist:2119737
# 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 Mar 19, 2012
Rainbows! config file for use with EventMachine
View gist:2120107
# 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 Jun 6, 2012
Geoloqi's Password Encryption Code
View password.rb
# 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 Jul 9, 2012
Ruby code for doing P12 to PEM conversion via command line. Supports MRI/JRuby/Rubinius
View gist:3077989
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)