I hereby claim:
- I am psychocandy on github.
- I am amirf (https://keybase.io/amirf) on keybase.
- I have a public key ASAZbAd4OFmWD8QsDVNMaMI_vcpJh79LpJpjeZyu8gkW_wo
To claim this, I am signing this object:
| # The following should prevent an ArgumentError "invalid %-encoding (...%)" exception from being raised for malformed URLs. | |
| # To use this code simply drop this in your rails app initializers. | |
| # See: https://github.com/rack/rack/issues/337 | |
| # Taken from: http://stackoverflow.com/a/11162317/1075006 | |
| module URI | |
| major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i } |
I hereby claim:
To claim this, I am signing this object:
| # /etc/bash/bashrc | |
| # | |
| # This file is sourced by all *interactive* bash shells on startup, | |
| # including some apparently interactive shells such as scp and rcp | |
| # that can't tolerate any output. So make sure this doesn't display | |
| # anything or bad things will happen ! | |
| # Test for an interactive shell. There is no need to set anything | |
| # past this point for scp and rcp, and it's important to refrain from |
| # name: RobbyRussel | |
| function _git_branch_name | |
| echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') | |
| end | |
| function _is_git_dirty | |
| echo (command git status -s --ignore-submodules=dirty ^/dev/null) | |
| end | |
| function fish_prompt |
| # one way: | |
| FactoryGirl.create_list(:monetization_campaign, 10) | |
| # another way: | |
| 10.times { FactoryGirl.create(:monetization_campaign) } | |
| # guarentee ids: | |
| 10.times { |n| FactoryGirl.create(:monetization_campaign, id: n) } |
| hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) } | |
| hash[:foo]["bar"][:baz] = 13 | |
| # => {:foo=>{"bar"=>{:baz=>13}}} |
| # [1,2,3].map_hash { |x| [x, x*2] } | |
| # => {1=>2, 2=>4, 3=>6} | |
| # { foo: "bar", fiz: "baz" }.map_hash { |k,v| [v,k] } | |
| # => {"bar"=>:foo, "baz"=>:fiz} | |
| module Enumerable | |
| def map_hash | |
| Hash[*self.inject([]) { |arr, a| arr += yield(a) }] | |
| end | |
| end |
| # usage: | |
| # FRUITS = Enum.new(:apples, :oranges) | |
| # FRUITS[:apples] # => 0 | |
| # FRUITS[0] # => :apples | |
| class Enum < Hash | |
| def initialize(*members) | |
| super() | |
| @reverse = {} |
| #!/usr/bin/tclsh8.5 | |
| # | |
| # Install: clone and copy to somewhere in your $PATH, e.g: | |
| # git clone https://gist.github.com/4681074.git git-unmerged && cd git-unmerged && chmod +x git-unmerged && sudo mv git-unmerged /usr/bin && cd .. && rm -rf git-unmerged | |
| # Usage: git-unmerged branch1 branch2 | |
| # | |
| # Shows all the non-common commits in the two branches, where non-common | |
| # commits means simply commits with a unique commit *message*. | |
| proc getlog branch { |
| def generate(n) | |
| return [] if n == 1 | |
| factor = (2..n).find { |x| n % x == 0 } | |
| [factor] + generate(n / factor) | |
| end |