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://rubular.com/r/UMTb5KhY8A | |
DATE=/\d{4}-\d{2}-\d{2}/ | |
ZONE=/Z|[-+]\d{2}(?::\d{2})?/ | |
TIME=/\d{2}(?::\d{2}(?::\d{2}(?:\.\d+)?)?)?/ | |
TIME_WITH_ZONE=/#{TIME}(?:#{ZONE})?/ | |
ISO8601_FORMAT=/^(#{DATE})(?:T(#{TIME_WITH_ZONE}))?$/ | |
ISO8601_FORMAT.match('2008-08-30T01:45:36.100Z') # => #<MatchData "2008-08-30T01:45:36.100Z" 1:"2008-08-30" 2:"01:45:36.100Z"> |
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 scream(s) | |
s.upcase | |
end | |
s = scream(<<-TEXT.gsub('z', 's')).gsub('EE', 'I') | |
Theez eez a lot of text. | |
Not really, but eet could be. | |
TEXT |
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
$('tr.file-diff-line.gd').hide(); |
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
git branch --merged | grep -v "\*" | while read b; do git br -d $b; done | |
git branch | grep -v "\*" | while read b; do echo "Delete '$b'?"; read y < /dev/tty; [[ "$y" == "y" ]] && git br -D $b; done |
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 Human | |
def greet | |
"I am a #{species}" | |
end | |
def species | |
'human' | |
end | |
end | |
Human.new.greet # => "I am a human" |
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
module Utils; def r; yield rescue $!; end; end; include Utils | |
def i | |
:i | |
end | |
def I | |
:I | |
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 A # < Struct | |
def self.new(mod, *arguments, &block) | |
if arguments.length > 0 | |
# Why is the block required in order to access the members from a block? | |
# ... because the block is passed to the `super` | |
Struct.new(*arguments) # { } | |
else | |
Class.new | |
end.tap { |c| | |
c.send(:include, mod) |
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 A < Struct | |
def self.new(mod, *arguments, &block) | |
if arguments.length > 0 | |
super(*arguments) do | |
include mod | |
define_method :greet, &block | |
end | |
else | |
Class.new do | |
include mod |
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 tapp(o, &block) | |
o.tap { |m| p block.call(o) } | |
end | |
tapp("haha", &:size) | |
# => "haha" | |
# >> 4 |
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
touch /tmp/sandwich | |
sudo chown root:wheel /tmp/sandwich | |
echo "make me a sandwich" >> /tmp/sandwich | |
sudo sh -c 'echo "make me a sandwich" >> /tmp/sandwich' | |
cat /tmp/sandwich |