Skip to content

Instantly share code, notes, and snippets.

@jamuc
jamuc / Monkey Patch Object
Created April 10, 2014 08:40
Monkey Patch the Ruby Object
# Monkey patch ruby Object with try method.
# Inspiration Rails.
# http://api.rubyonrails.org/classes/Object.html#method-i-try
class Object
def try(*a, &b)
if a.empty? && block_given?
yield self
else
publice_send(*a, &b) if respond_to?(a.first)
end
### Keybase proof
I hereby claim:
* I am jamuc on github.
* I am jamuc (https://keybase.io/jamuc) on keybase.
* I have a public key whose fingerprint is 8905 1D0D 7154 35C9 5620 8A66 C025 90C2 3A46 1BDD
To claim this, I am signing this object:
@jamuc
jamuc / git theirs
Created June 4, 2013 12:58
Workaround how to perform a git -s theirs merge
git checkout MINE
git merge --no-commit -s ours HERS
git rm -rf .
git checkout HERS -- .
@jamuc
jamuc / gist:3604224
Created September 2, 2012 20:22
Run sed substitution on multiple files
find . -name "*.html.erb" -print0 | xargs -0 -n 1 sed -i -e 's/@controller.is_in_demo_mode/@demo/g'