Skip to content

Instantly share code, notes, and snippets.

View jelder's full-sized avatar

Jacob Elder jelder

View GitHub Profile
@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 / 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 / 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 / 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 / iteration.rb
Last active November 28, 2020 19:24
The difference between `for` and `each` in Ruby: scope.

for should only be used when you actually want the iteratee to be accessible after you leave the block. for pollutes the parent scope with old iteratees. For this reason, each should be your default.

@jelder
jelder / README.md
Last active December 27, 2015 19:29
Bookmarklet to toggle between Pow and Production

Pow Toggle Bookmarklet

Ever come across something funky in production and want to see it in your development environment? Use Pow? This is for you. Make a new bookmark for this location:

javascript:(function()%7Bif%20(%2Fhttp%3A.*%5C.dev%2F.test(window.location.origin))%20%7Burl%20%3D%20window.location.href.replace(%2F%5Ehttp%3A%2F%2C%20'https%3A').replace(%2F.dev%2F%2C'.com')%3Bwindow.open(url)%3B%7D%20else%20%7Burl%20%3D%20window.location.href.replace(%2F%5Ehttps%3A%2F%2C%20'http%3A').replace(%2F.com%2F%2C'.dev')%3B%3Bwindow.open(url)%3B%7D%7D)()

If you want to edit this, first copy and paste the JavaScript below into a bookmarklet creator. I used http://mrcoles.com/bookmarklet/ but others might be nice, too.

// Generate a set of 128x128 png icons for notifications from our color palette.
// Order must match .status-box:nth-of-type() declarations.
var color_data = {
"#1564f9": "UVZPl4Z7ha",
"#3fc41b": "U/xButvkTR",
"#fa8e1f": "X6jh83IXPs",
"#4ca8ea": "VMqOr4+3T5",
"#f71347": "X3E0eeps0u",
"#fcc124": "X8wST1RrWw"
};
@jelder
jelder / .irbrc.rb
Created May 14, 2013 21:26
My ~/.irbrc
require 'rubygems'
require 'irb/completion'
require 'irb/ext/save-history'
# interactive editor: use vim from within irb
#begin
# require 'interactive_editor'
#rescue LoadError => err
# warn "Couldn't load interactive_editor: #{err}"
#end
@jelder
jelder / parse_bench.rb
Created April 27, 2013 00:00
( while :; do date ; /usr/bin/time heroku run false ; sleep 1; done ) 2>&1 | ruby parse_bench.rb
#!/usr/bin/env ruby
samples = []
STDIN.lines.each do |line|
next if line =~ /^stty/
next if line =~ /^Running/
if line =~ /real.*user.*sys/
real,_,user,_,sys = line.strip.split(/\s+/)
samples << [Float(real),Float(user),Float(sys)]
@jelder
jelder / Preferences.sublime-settings.json
Created February 12, 2013 18:48
My Sublime Test 2 config
{
"caret_style": "wide",
"color_scheme": "Packages/Tomorrow Color Schemes/Tomorrow.tmTheme",
"detect_indentation": true,
"draw_indent_guides": true,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.pyc",