Skip to content

Instantly share code, notes, and snippets.

View sax's full-sized avatar

Eric Saxby sax

View GitHub Profile
@sax
sax / connection_adapters.rb
Last active March 2, 2016 04:00
Monkey patch ActiveRecord to use bigints for ids and references
require 'active_record/connection_adapters/postgresql_adapter'
module ActiveRecord
module ConnectionAdapters
class TableDefinition
def references(*args)
options = args.extract_options!
polymorphic = options.delete(:polymorphic)
index_options = options.delete(:index)
args.each do |col|
@sax
sax / database.yml
Last active February 24, 2016 22:03
Multidb migration support
common: &common
adapter: postgresql
host: 127.0.0.1
port: 5432
username: *******
password: *******
encoding: unicode
pool: 20
min_messages: WARNING
schema_search_path: public
@sax
sax / postgresql.conf
Created December 9, 2015 19:37
PostgreSQL configuration
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
@sax
sax / databases.rake
Last active March 5, 2022 17:27
Overwrite Rails 3 databases rake task to remove method pollution on Object
# The built-in Rails database rake task is completely crazy, and defines methods on Object. This causes
# problems with Makara, which uses a delegator pattern along with method_missing.
require 'active_support/core_ext/object/inclusion'
require 'active_record'
class Object
remove_method :configs_for_environment
remove_method :create_database
remove_method :current_config
@sax
sax / fork arguments
Last active August 29, 2015 14:09
Postgres slow forking
> sudo dtrace -n '::forksys:entry / pid == $target / { printf("%d %d", arg0, arg1); }' -p 7580
CPU ID FUNCTION:NAME
5 13517 forksys:entry 0 0
5 13517 forksys:entry 0 0
5 13517 forksys:entry 0 0
5 13517 forksys:entry 0 0
7 13517 forksys:entry 0 0
0 13517 forksys:entry 0 0
0 13517 forksys:entry 0 0
@sax
sax / gist:99ae1591340be381f868
Last active August 29, 2015 14:05
Elasticsearch cross-index query spike
DELETE joininess-product
DELETE joininess-save
DELETE joininess-user
PUT joininess-product
PUT joininess-save
PUT joininess-user
DELETE joininess-product/_mapping/product
GET joininess-product/_mapping/product
@sax
sax / gist:061f95d3c159b1a7a315
Created July 19, 2014 01:35
Add nictag to SmartOS global zone and use it to add interface to local zone#
# global zone
MAC_ADDRESS=$(dladm show-phys -m e1000g1 | tail +2 | awk '{ print $3 }')
ZONENAME=$(zoneadm list | grep -v global)
nictagadm add external "${MAC_ADDRESS}"
echo '{"add_nics":[{"nic_tag":"external","ip":"dhcp"}]}' | vmadm update ${ZONENAME}
@sax
sax / forking_off_cpu.d
Last active August 29, 2015 14:03
Slow forking analysis
#!/usr/bin/dtrace
syscall::forksys:entry
/pid == $target/
{
self->tracing = 1;
}
syscall::forksys:return
/pid == $target/
@sax
sax / smartos_vagrant.md
Last active February 23, 2016 20:53
Smartos / Vagrant
  1. Install Vagrant

  2. Install SmartOS guest detection

vagrant plugin install vagrant-smartos-guest
  1. Install zones support
@sax
sax / omnifuss.sh
Last active January 11, 2017 20:47
Create omnibus chef on SmartOS
pkgin -y install ruby193 gmake build-essential ;
gem install bundler --no-ri --no-rdoc
pushd /root
git clone https://github.com/opscode/omnibus-ruby
git clone https://github.com/opscode/omnibus-software
git clone https://github.com/opscode/omnibus-chef
pushd omnibus-chef
bundle install --binstubs
/root/omnibus-chef/bin/omnibus build project chef