Skip to content

Instantly share code, notes, and snippets.

View pda's full-sized avatar
💾
Formatting…

Paul Annesley pda

💾
Formatting…
View GitHub Profile
@pda
pda / README.md
Last active November 12, 2018 13:25
Demonstrate that queue time is not included in Unicorn's request timeout

Unicorn timeout test

Demonstrate that queue time is not included in Unicorn's timeout

Output

$ ruby unicorn_timeout_test.rb
starting unicorn {:worker_processes=>2, :timeout=>3}
[client] concurrently requesting /sleep/6, /sleep/4, /sleep/2, /sleep/0
@pda
pda / unicorn.rake
Created September 12, 2011 07:39
Rake tasks for Unicorn: start stop restart increment decrement pstree
namespace :unicorn do
##
# Tasks
desc "Start unicorn"
task(:start) {
config = rails_root + "config/unicorn.rb"
sh "bundle exec unicorn --daemonize --config-file #{config}"
}
@pda
pda / keybase.md
Last active March 15, 2017 01:59
keybase.md

Keybase proof

I hereby claim:

  • I am pda on github.
  • I am pda (https://keybase.io/pda) on keybase.
  • I have a public key whose fingerprint is C01A 62C6 7093 CE6A 2C34 299A C902 25CE B876 8E7B

To claim this, I am signing this object:

@pda
pda / spec_helper.rb
Created March 14, 2012 06:23
Fast RSpec with a tiered environment: SPEC=(unit|model|full) rspec …
mode = ENV["SPEC"] || "full"
require_relative "spec_helper_#{mode}"
@pda
pda / rack_header_renamer.rb
Created May 25, 2016 06:44
RackHeaderRenamer middleware for Rack; copy a request header to a different name before Rails etc sees it. e.g. config.middleware.insert(0, RackHeaderRenamer, "X-Varnish-Proto" => "X-Forwarded-Proto")
class RackHeaderRenamer
# mapping example, sets/overwrites second header with first:
# {"X-Varnish-Proto" => "X-Forwarded-Proto"}
def initialize(app, mapping)
@app = app
@mapping = mapping
end
def call(env)
require "bcrypt"
module GoTipping
class UserAuthenticator
def initialize(organisation, username, finder)
@organisation = organisation
@username = username
@finder = finder
end
@pda
pda / 0_cause.rb
Created January 3, 2014 23:19
Recursively inspect Exception#cause to trace where the error condition originated.
name = ->(i){ "method_#{i}" }
methods = 10.times.map do |i|
define_method(name[i]) do
if i == 0
raise "Top level error from #{name[i]}"
else
begin
send name[i - 1]
rescue
raise "Error from rescue in #{name[i]}"
@pda
pda / heroku-postgres-migrate.sh
Last active December 25, 2015 01:39
Shell script to migrate between Heroku Postgres databases via pgbackups.
#!/usr/bin/env zsh
# Migrate data between Heroku Postgres databases via pgbackups.
# This involves downtime via `heroku maintenance:on`.
#
# To migrate example-app to HEROKU_POSTGRESQL_COLOR:
# heroku-postgres-migrate.sh <example-app> <HEROKU_POSTGRESQL_COLOR>
#
# To exit maintenance mode (in case something dies half-way):
# heroku-postgres-migrate.sh --wake
@pda
pda / timediff.rb
Created October 6, 2013 00:40
Report which methods differentiate two fractionally different times.
# Whether a method called on two objects gives two results that are
# equal when compared as strings.
def same_to_s?(a, b, method)
a.send(method).to_s == b.send(method).to_s rescue true
end
Result = Struct.new(:method, :class_name, :a, :b) do
def to_s
"Time#%-10s %-10s '%s' vs '%s'" % [method, class_name, a, b]
end
@pda
pda / bundle_list.md
Created July 1, 2013 00:47
`bundle list` for a Rails 4 / Ruby 2.0 app I'm working on.
  • actionmailer (4.0.0)
  • actionpack (4.0.0)
  • active_attr (0.8.2)
  • activemodel (4.0.0)
  • activerecord (4.0.0)
  • activerecord-deprecated_finders (1.0.3)
  • activesupport (4.0.0)
  • addressable (2.3.5)
  • airbrake (3.1.12)
  • arel (4.0.0)