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
# Demonstration showing that | |
# | |
# alias_method :bar, :foo | |
# | |
# is not equivalent to | |
# | |
# def bar | |
# foo | |
# end |
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
# Collect _spec.rb and .feature files under spec/ that are relevant to current work, one per line. Good for pipes. | |
# | |
# 1. Modified, staged git files. | |
# 2. Modified, unstaged git files. | |
# 3. Changes in any commits since master. | |
# 4. New, untracked files. | |
# | |
# $ specs | xargs rspec | |
cat <(git diff --name-only) <(git diff --staged --name-only) <(git diff master..@ --name-only) <(git ls-files --others --exclude-standard) | uniq | grep -e "^spec/" | grep -E "_spec\.rb$|\.feature$" |
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
# Delay Foo#method by 1 second before | |
# executing its original implementation. | |
def delay_method(klass, method) | |
sleeping_giant = Module.new do | |
define_method(method) do |*args, &block| | |
sleep 1 | |
super(*args, &block) | |
end | |
end |
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
class Symbol | |
def |(other) | |
self.to_proc | other | |
end | |
end | |
class Proc | |
def |(other) | |
proc { |arg| other.to_proc.call(self.call(arg)) } | |
end |
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
function prodssh { osascript -e 'tell application "Terminal" to set current settings of selected tab of window 1 to settings set "Red Sands"' && ssh "$@"; } | |
# prodssh yourserver |
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
# | |
# 1.8.7 docs: http://ruby-doc.org/core-1.8.7/classes/Proc.html#M000463 | |
# | |
# Return true if prc is the same object as other_proc, or if they are both procs with the same body. | |
# | |
RUBY_DESCRIPTION #=> ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux] | |
proc { 1 } == proc { 1 } # => false | |
proc { 1 + 1 } == proc { 1 + 1 } # => 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
>> local_variables | |
=> ["_"] | |
>> a = "" | |
=> "" | |
>> local_variables | |
=> ["_", "a"] | |
>> b = binding; local_variables.select { |var| b.eval(var).object_id == a.object_id } | |
=> ["a"] | |
>> x = a | |
=> "" |
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
<!-- See it in action: http://jsfiddle.net/eVAg4/1/ --> | |
<!doctype html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>PDF link file sizes in CSS</title> | |
<style type="text/css"> | |
a[href$=".pdf"]::after { content: " (PDF)"; } | |
a[href$=".pdf"][data-size]::after { content: " (PDF, " attr(data-size) ")"; } | |
</style> |
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
def foo(n, m) | |
return n if n % m == 0 | |
n + m - (n % m) | |
end | |
foo(25, 7) #=> 28 | |
foo(28, 7) #=> 28 | |
foo(29, 7) #=> 35 | |
# No branching. |
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
# it turns out that "A".ord - "A".ord is constant when you replace the two characters | |
# with, say "B" and "B", so ("B".ord + DIFFERENCE).to_s(16) == "ff22" and "\uff22" | |
# is "B". (Thanks, Unicode consortium.) | |
# | |
# an exception is U+0020 space, which has IDEOGRAPHIC SPACE U+3000, but the two don't | |
# differ by DIFFERENCE == 65248 == 0xfee0, so you have to replace 20+65248 == 0xff00 | |
# with 0x3000. | |
DIFFERENCE = 65248 |
OlderNewer