Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/k/app_name/current
PID=/var/run/unicorn/unicorn.pid
ENV=production
@geoffgarside
geoffgarside / gist:723410
Created December 1, 2010 12:19
Construction of a UK Postcode Regular Expression

First Half

Character sets for positions

  1. [A-PR-UWYZ]
  2. [A-HK-Y]
  3. [A-HJKS-UW]
  4. [ABEHMNPRV-Y]

Formats

@mikhailov
mikhailov / ruby_gc.sh
Created March 11, 2011 10:33
Ruby’s GC Configuration
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
@shapeshed
shapeshed / unicorn
Created September 16, 2011 10:12
Unicorn / Monit setup
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/path/to/your/app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENVIRONMENT=production
@geoffgarside
geoffgarside / ip_address_validator.rb
Created November 4, 2011 14:55
Rails 3.x IP Address validator class
# The IP Address Validator accepts the following options
#
# * allow_nil - allows nil values
# * allow_blank - allows blank values
# * allow_cidr - allows /prefixlen CIDR masks in values
#
# the validator will use regular expressions in an attempt to prevent
# malformed IP addresses from being passed to the IPAddr.new initializer
# as this method can be very slow to raise exceptions for malformed input.
class IpAddressValidator < ActiveModel::EachValidator
@bkimble
bkimble / gist:1365005
Last active May 2, 2024 01:27
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@geoffgarside
geoffgarside / README.md
Created December 18, 2011 23:12 — forked from bergie/README.md
Falsy Values tutorials
@technoweenie
technoweenie / gist:2155760
Created March 22, 2012 04:03
track meta data with resque jobs, like when it was queued.
module Resque
def push_with_meta(queue, item)
if item.respond_to?(:[]=)
item[:meta] = {:queued_at => Time.now.to_f}
end
push_without_meta(queue, item)
end
class Job
# Returns a Hash of the meta data related to this Job.
@geoffgarside
geoffgarside / gist:2593820
Created May 4, 2012 10:16
Makefile wrapper to help GNUMake related RubyGem extensions build properly on FreeBSD/Solaris.
#!/bin/sh
#
# Makefile wrapper to help GNUMake related RubyGem extensions
# build properly on FreeBSD/Solaris.
#
# Write this file to ~/bin/make
# $ chmod 755 ~/bin/make
# $ export PATH=$HOME/bin:$PATH
#
# Can now "gem install" or "bundle install" or whatever you need.
@mattetti
mattetti / gist:3473008
Created August 26, 2012 01:36
Redis instrumentation
::Redis::Client.class_eval do
# Support older versions of Redis::Client that used the method
# +raw_call_command+.
call_method = ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
def call_with_stats_trace(*args, &blk)
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
start = Time.now
begin