Skip to content

Instantly share code, notes, and snippets.

View PatrickTulskie's full-sized avatar

patrick tulskie PatrickTulskie

View GitHub Profile
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Welcome to the Ruby Enterprise Edition installer
This installer will help you install Ruby Enterprise Edition 1.8.7-2012.02.
Don't worry, none of your system files will be touched if you don't want them
to, so there is no risk that things will screw up.
You can expect this from the installation process:
1. Ruby Enterprise Edition will be compiled and optimized for speed for this
system.
@PatrickTulskie
PatrickTulskie / uniq_bench.rb
Created September 27, 2013 03:20
Performance testing Ruby's uniq
require 'rubygems'
require 'benchmark'
objects = ["string", %w(array), { :key => 'value' }, 9000] * 100
GC.disable
Benchmark.bm do |x|
x.report('map => uniq') do
10000.times { objects.map { |object| object.class }.uniq }
@PatrickTulskie
PatrickTulskie / redis_connector.rb
Created June 7, 2013 17:43
Waterfall connector for Redis in Ruby
class RedisConnector
def self.connection
return $redis if $redis
case Rails.env
when /production/
# Don't use waterfall connection here because we don't want
# production inconsistencies
connect_with_failover
require 'benchmark'
require 'pp'
require 'active_record'
require 'sequel'
require 'data_mapper'
@start = Date.parse("2012-12-01")
@end = Date.parse("2012-12-31")
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'escobar_development', cast: false, username: 'root', password: nil, pool: 5, timeout: 5000)
@PatrickTulskie
PatrickTulskie / resque_pool.rake
Created October 26, 2012 18:48
Working resque pool setup for NewRelic
require 'resque/pool/tasks'
# this task will get called before resque:pool:setup
# preload the rails environment in the pool master
task "resque:setup" => :environment do
# generic worker setup, e.g. Hoptoad for failed jobs
end
task "resque:pool:setup" do
# Close any sockets or files in pool master
@PatrickTulskie
PatrickTulskie / resque_pool.rake
Created October 25, 2012 20:15
Resque Pool and NewRelic
require 'resque/pool/tasks'
# this task will get called before resque:pool:setup
# preload the rails environment in the pool master
task "resque:setup" => :environment do
# generic worker setup, e.g. Hoptoad for failed jobs
end
task "resque:pool:setup" do
# close any sockets or files in pool master
@PatrickTulskie
PatrickTulskie / unicorn
Created October 19, 2012 13:54
Unicorn init.d Script
#!/bin/sh
set -e
# Setup current directory path
APP_ROOT=/path/to/your/app/current
# Unicorn needs to know to write the PID file here. Adjust this for your own setup.
PID=$APP_ROOT/tmp/pids/unicorn.pid
# 4 workers is enough for our app
worker_processes 4
# App location
@app = "/var/rails/myapp/current"
# Listen on fs socket for better performance
listen "#{@app}/tmp/sockets/unicorn.sock", :backlog => 64
# Nuke workers after 30 seconds instead of 60 seconds (the default)
@PatrickTulskie
PatrickTulskie / include_vs_regex.rb
Created October 5, 2012 18:12
String#include? vs String#match
require "benchmark"
n = 1000000
puts "Running include? vs regex 1 million times.\n"
Benchmark.bmbm do |results|
results.report("include? ") { n.times { "banana".include?('nana') } }
results.report("match w/ regex") { n.times { "banana".match(/nana/) } }
end
@PatrickTulskie
PatrickTulskie / generate_some_c.rb
Created April 12, 2012 17:23
Generate some C, compile it, and run it.
# Just because you can do something like this doesn't mean you should.
# Executing code via backticks using input from the user is a good way to wreck the host machine.
class GenerateSomeC
attr_accessor :program_name
def initialize(program_name)
@program_name = program_name
end