This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From : http://andrewjgrimm.wordpress.com/2011/10/03/in-ruby-method-passes-you/ | |
["1", "2", "3"].map(&method(:Integer)) | |
filenames = ["a.txt", "b.txt", "c.txt"] | |
texts = filenames.map(&File.method(:read)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem 'unicorn' | |
# Procfile | |
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb | |
# config/unicorn.rb | |
worker_processes 4 | |
timeout 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file mood.rb | |
Mood = Struc.new(:happy) | |
# file user.rb | |
class User | |
serialize mood, Mood | |
def mood=(attr={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Playing with classes and structs | |
MyClass = Class.new | |
p MyClass.class | |
# => Class | |
my_instance = MyClass.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://stackoverflow.com/a/647451 | |
git symbolic-ref HEAD refs/heads/newroot | |
git rm --cached -r . | |
git clean -f -d | |
# then you apply the same steps | |
git commit --allow-empty -m 'root commit' | |
git cherry-pick $(git rev-list --reverse master | head -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
element.addEventListener('touchstart', function(e) { | |
e.preventDefault(); | |
}, false); | |
element.addEventListener('touchmove', function(e) { | |
e.preventDefault(); | |
}, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"toto\ntiti".lines.map{|l| l.strip}.to_a.join(", ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://rubyquicktips.tumblr.com/post/4601358354/using-try-with-a-hash-to-check-existence-of-a-key | |
hsh = { :existing_key => | |
{ | |
:existing_sub_key => :value | |
} | |
} | |
hsh.try(:[], :existing_key).try(:[], :existing_sub_key) | |
# => :value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# following DOES match "foobar", "fooadmin", "adminbar", "fooadminbar" but not "admin" as a whole word : | |
/^((?!\badmin\b)[^\s]*)$/ | |
# more reserved keywords : | |
/^((?!\badmin\b|\bteam\b)[^\s]*)$/ | |
# http://www.regular-expressions.info/wordboundaries.html | |
# http://www.regular-expressions.info/lookaround.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } |