Skip to content

Instantly share code, notes, and snippets.

View jelder's full-sized avatar

Jacob Elder jelder

View GitHub Profile
@jelder
jelder / tire_fail_fast.rb
Created March 5, 2014 20:13
Prevent ElasticSearch outages from bringing down the rest of your app
module Tire
module Search
class Search
alias :perform_without_fail_fast :perform
def perform
@options[:timeout] = '1900ms'
begin
Timeout::timeout 2 do
perform_without_fail_fast
@jelder
jelder / tire_squelch_load_errors.rb
Created March 5, 2014 20:14
Prevent deleted objects in ElasticSearch from causing problems
module Tire
module Results
class Collection
def __find_records_by_ids(klass, ids)
records = @options[:load] === true ? klass.where(klass.primary_key => ids) : klass.find(ids, @options[:load])
@response['hits']['hits'].keep_if { |hit| records.map(&:id).include? hit["_id"].to_i }
records
end
end
end
@jelder
jelder / amish_friendship_bread.md
Last active August 29, 2015 14:00
Amish Friendship Bread

Amish Friendship Bread

NOTES

  • Do not use any type of metal bowl or spoon for mixing
  • Do not refrigerate
  • If air forms in the bag, let it out. It is normal for batter to rise, bubble, and ferment.

Day 1

@jelder
jelder / store_by_path.rb
Last active August 29, 2015 14:01
Hash insertion by path
require 'ap'
class Hash
def store_by_path(path, value)
case path
when String
if path =~ %r{/}
store_by_path(path.split('/'), value)
else
self[path] = value
@jelder
jelder / deep_store.rb
Last active August 29, 2015 14:11
Extend Hash to allow insertion by path
require 'ap'
class Hash
def store_by_path(path, value)
case path
when String
if path =~ %r{/}
store_by_path(path.split('/'), value)
else
self[path] = value
end
@jelder
jelder / json.sql
Created March 25, 2015 22:38
Converting between types of arrays in PostgreSQL
BEGIN;
CREATE TABLE json_test (
id SERIAL PRIMARY KEY,
label text,
examples text[] DEFAULT '{}'::text[]
);
INSERT INTO json_test (label,examples) VALUES ('before','{}');
INSERT INTO json_test (label,examples) VALUES ('before','{"[{\"a\":1}]"}');
@jelder
jelder / passenger_throttle.sh
Created April 8, 2015 20:55
Dynamically configure Passenger based on current Dyno type
#!/bin/bash
# http://stackoverflow.com/questions/24634958/programmatically-detect-heroku-dyno-size-at-run-time/24634959#24634959
function dyno_size() {
case $(ulimit -u) in
256)
echo "1X"
;;
512)
echo "2X"
#!/bin/bash
# Update all repositories in ~/code
# Keep in ~/bin
trap "exit" INT
for dir in ~/code/* ; do
if [ -d $dir/.svn ] ; then
echo "Updating `basename $dir` (svn)"
svn update $dir
elif [ -d $dir/.git ] ; then
echo "Updating `basename $dir` (git)"
@jelder
jelder / logcrusher.pl
Created February 4, 2010 16:48
Delete inactive Tomcat log files.
#!/usr/bin/perl
# Delete inactive log files.
use strict;
use warnings;
my $dir = '/opt/tomcat6/logs';
# Files which are open
my %open;
@jelder
jelder / qsvn.rb
Created April 25, 2010 22:59
Take advantage of environments where /home is an NFS export from the server which also hosts Subversion.
#!/usr/bin/env ruby
# Take advantage of environments where Subversion server also NFS exports /home to make more efficient Subversion operations.
require 'net/ssh'
server = "admin01"
temporary_root = "file:///srv/svn"
pwd = ENV["PWD"]
user = ENV["USER"]
remote_command = "cd #{pwd} && svn " + ARGV.join(" ")
lock_file = ".qsvn_lock"