Skip to content

Instantly share code, notes, and snippets.

View sax's full-sized avatar

Eric Saxby sax

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / psql.rb
Last active February 24, 2016 22:13
Generate unique cross-shard ids in PostgreSQL
execute <<-EOSQL
CREATE SEQUENCE #{schema}.id_generator_seq;
CREATE OR REPLACE FUNCTION #{schema}.current_shard_id(OUT result int) AS $$
BEGIN
result := #{shard_id};
END;
$$ LANGUAGE PLPGSQL;
@sax
sax / load_data.sh
Last active February 16, 2017 11:18
Dump and reload data into PostgreSQL with massive concurrency
# interpolated load tables step
find . -type f -print0 | xargs -0 -n1 -P50 bash -c "psql -U <postgres_user> <mydatabase> < \$0"
@sax
sax / consumer.rb
Created April 26, 2016 00:38
Example sidekiq worker
class Worker
include Sidekiq::Worker
def perform(message)
puts message
end
end
@sax
sax / ffmpeg -- logo overlay
Last active May 21, 2017 22:52
ffmpeg: add overlay to video
ffmpeg -i video.mp4 -vf \
"movie=logo.png [overlay]; \
[overlay] scale=250:-1 [a]; \
[a] format=yuva420p,colorchannelmixer=aa=0.5 [b]; \
[in] curves=preset=lighter [vid]; \
[vid][b] overlay=50:50 [out]" \
-pix_fmt yuv420p \
output.mp4 \
&& terminal-notifier -message 'done'