Skip to content

Instantly share code, notes, and snippets.

def with_var(variable, value, &block)
old_value = eval variable
eval "#{variable} = #{value.inspect}"
ret = block.call
eval "#{variable} = #{old_value.inspect}"
ret
end
# Usage
# =====
@iangreenleaf
iangreenleaf / a_b_helper.rb
Created November 27, 2012 19:59
Helper to provide alternate configuration syntax for Split, the A/B testing tool.
module ABHelper
def split_test(name)
experiment = YAML.load_file("config/experiments.yml")[name]
given_probability, num_with_probability = experiment[:variants].inject([0,0]) do |a,v|
p, n = a
if v.kind_of?(Hash) && v[:percent]
[p + v[:percent], n + 1]
else
a
@iangreenleaf
iangreenleaf / Makefile
Last active December 15, 2015 10:58
Ruby-style mixins in JavaScript.
test:
for f in test-*.coffee; do coffee "$$f"; done
.PHONY: test
Here are the version numbers available for Handlebars.js
+--------------+------------------+------------------+--------------+
| npm versions | Official website | GitHub downloads | Git tags |
+--------------+------------------+------------------+--------------+
| 1.0.2beta | 1.0.0-rc.3 | 0.9.0.pre.2 | 0.9.0.pre.4 |
| 1.0.4beta | | 0.9.0.pre.3 | 1.0.0.beta.1 |
| 1.0.5beta | | 0.9.0.pre.4 | 1.0.0-rc.3 |
| 1.0.6 | | 0.9.0.pre.5 | 1.0.rc.1 |
| 1.0.6-2 | | 0.9.0.pre.js | 1.0.rc.2 |
@iangreenleaf
iangreenleaf / gist:984bc6765d2a4dc49862
Created May 12, 2014 18:18
Import seperate git repo as subdirectory
export target=my_dir
git remote add "$target" file:////path/to/original/repo
git fetch "$target"
git co -b "$target" "$target/master"
# Probably breaks on whitespace, sorry dawg.
git filter-branch -f --tree-filter "mkdir -p \"$target\"; git ls-tree \$GIT_COMMIT --name-only | xargs --no-run-if-empty mv -t $target" "$target"
git co master
git merge "$target"
git remote remove "$target"
git br -d "$target"
@iangreenleaf
iangreenleaf / keybase.md
Created January 14, 2015 18:01
Keybase identity proof

Keybase proof

I hereby claim:

  • I am iangreenleaf on github.
  • I am iangreenleaf (https://keybase.io/iangreenleaf) on keybase.
  • I have a public key whose fingerprint is 3820 459D 1ADA C0D3 6F33 988E 0D31 6FB4 774E 9147

To claim this, I am signing this object:

@iangreenleaf
iangreenleaf / gist:6dfb4d0847ebda0cc3dd
Last active August 29, 2015 14:15
Bulk-save files in Vim
ack -f --print0 | xargs -0 -n1 vim +wq
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active July 31, 2025 07:46
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

#
#= dump database to yaml for fixtures
#
# originated by elm200 <http://d.hatena.ne.jp/elm200/20070928/1190947947>
#
#== install
#
# move this file to RAILS_ROOT/lib/tasks/extract_fixtures.rake
#
namespace :db do
<ruleset name="Grinnellplans.com">
<target host="grinnellplans.com" />
<target host="www.grinnellplans.com" />
<rule from="^http:" to="https:" />
</ruleset>