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 days(range) | |
Enumerator.new do |yielder| | |
now = range.begin | |
begin | |
yielder << now if now <= range.end | |
end while (now = now + 1.day) <= range.end | |
end | |
end | |
days((Time.now - 3.days)..(Time.now)).each { |day| puts day } |
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 WizardSkills | |
module InstanceMethods | |
def trick | |
super | |
puts "The #{self.class} turned a man into a rabbit" | |
end | |
end | |
end | |
module MagicianSkills |
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 Object | |
# list methods which aren't in superclass | |
def local_methods(obj = self) | |
(obj.methods - obj.class.superclass.instance_methods).sort | |
end | |
# print documentation | |
# | |
# ri 'Array#pop' | |
# Array.ri |
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
require 'saxerator' | |
# The parser takes any IO object (or String) - a File is a common choice | |
parser = Saxerator.parser(bookshelf_xml) | |
# Simplest usage, parses every <book></book> in the document | |
parser.for_tag(:book).each do |book| | |
# Your book hash might look something like | |
{ 'title' => 'Rails 3 In Action', 'author' => ['Ryan Bigg', 'Yehuda Katz'] } | |
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
describe Article do | |
subject(:article) { Article.new } | |
it "validates presence of :title" do | |
article.should validate_presence_of(:title) | |
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
➜ saxerator git:(master) ✗ ruby -v | |
jruby 1.7.0.preview2 (1.9.3p203) 2012-09-07 f4306fa on Java HotSpot(TM) 64-Bit Server VM 1.6.0_33-b03-424-11M3720 [darwin-x86_64] | |
➜ saxerator git:(master) rspec spec/lib/dsl/for_tag_spec.rb | |
/Users/soulcutter/.rvm/gems/jruby-head@saxerator/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:274 warning: singleton on non-persistent Java type Java::JavaLang::NullPointerException (http://wiki.jruby.org/Persistence) | |
F | |
Failures: | |
1) Saxerator::DSL#for_tag should only select the specified tag | |
Failure/Error: Unable to find matching line from backtrace |
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
SSH_ENV="$HOME/.ssh/environment" | |
function start_agent { | |
echo "Initializing new SSH agent..." | |
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" | |
echo succeeded | |
chmod 600 "${SSH_ENV}" | |
ssh_environment_init; | |
/usr/bin/ssh-add; | |
} |
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
#!/bin/zsh | |
for file in $(awk 'FNR == 1 && !/^#\!/ { print FILENAME; nextfile }' **/*.rb); do | |
echo $file | |
sed -i 1i'# encoding: utf-8' $file | |
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
// Question: Can you do something like this without using interface-based injection? | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ActiveProfiles("test") | |
public class FakeDownloadUtilTest extends BaseTest { | |
@Autowired | |
DownloadUtil downloadUtil; | |
@Test | |
public void testFaked() { |
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
➜ ~ rvm install jruby-1.6.3 | |
jruby-1.6.3 - #downloading jruby-bin-1.6.3, this may take a while depending on your connection... | |
% Total % Received % Xferd Average Speed Time Time Time Current | |
Dload Upload Total Spent Left Speed | |
100 14.7M 100 14.7M 0 0 459k 0 0:00:32 0:00:32 --:--:-- 410k | |
jruby-1.6.3 - #extracting jruby-bin-1.6.3 to /Users/brschaefer/.rvm/src/jruby-1.6.3 | |
jruby-1.6.3 - #extracted to /Users/brschaefer/.rvm/src/jruby-1.6.3 | |
Building Nailgun | |
jruby-1.6.3 - #installing to /Users/brschaefer/.rvm/rubies/jruby-1.6.3 | |
jruby-1.6.3 - adjusting #shebangs for (jrubyc jirb_swing jirb jgem rdoc ri spec autospec testrb ast generate_yaml_index.rb). |