This file contains hidden or 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 'set' | |
class ExceptionTester | |
class TestException < Exception | |
end | |
# Accepts a block containing the code you want to make exception safety | |
# assertions about. | |
def initialize(&exercise) | |
@exercise = exercise |
This file contains hidden or 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 foo() { | |
var a = []; | |
for(var i = 0; i < 10; ++i) { | |
a[i] = function() { | |
console.log("The number is: " + i); | |
}; | |
} | |
a[6](); | |
} |
This file contains hidden or 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
DataMapper::RepositoryNotSetupError: Adapter not set: default. Did you forget to setup? | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/repository.rb:72:in `adapter' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/model/property.rb:160:in `field_naming_convention' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/property.rb:494:in `field' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/model.rb:567:in `block in load' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/model.rb:567:in `map' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/model.rb:567:in `load' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/repository.rb:162:in `read' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/collection.rb:1117:in `lazy_load' | |
/home/avdi/.rvm/gems/ruby-1.9.2-p0@bench/gems/dm-core-1.1.0/lib/dm-core/support/lazy_array.rb:275:in `to_a' |
This file contains hidden or 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 ::Guard | |
class Redis < Guard | |
def start | |
puts "Starting Redis on port #{port}" | |
IO.popen("#{executable} -", 'w+') do |server| | |
server.write(config) | |
server.close_write | |
end | |
puts "Redis is running with PID #{pid}" | |
$?.success? |
This file contains hidden or 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
(setq pidfile "emacs-server.pid") | |
(add-hook 'emacs-startup-hook | |
(lambda () | |
(with-temp-file pidfile | |
(insert (number-to-string (emacs-pid)))))) | |
(add-hook 'kill-emacs-hook | |
(lambda () | |
(when (file-exists-p pidfile) | |
(delete-file pidfile)))) |
This file contains hidden or 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 'spec_helper' | |
describe Feeds::Drops::Rss::EntryDrop do | |
use_vcr_cassette | |
subject { | |
Feeds::Drops::Rss::EntryDrop.new(rss_app.feed_entries_to_display[1], context) | |
} | |
let(:context) { mock('context') } | |
let(:rss_app) { |
This file contains hidden or 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 DeepFetch | |
def deep_fetch(*keys, &fetch_default) | |
throw_fetch_default = fetch_default && lambda {|key, coll| | |
args = [key, coll] | |
# only provide extra block args if requested | |
args = args.slice(0, fetch_default.arity) if fetch_default.arity >= 0 | |
# If we need the default, we need to stop processing the loop immediately | |
throw :df_value, fetch_default.call(*args) | |
} | |
catch(:df_value){ |
This file contains hidden or 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 'rubygems' | |
require 'mechanize' | |
MAX_PAGES = 6 | |
def each_google_result_page(query, max_pages=MAX_PAGES) | |
i = 0 | |
a = Mechanize.new do |a| | |
a.get('http://google.com/') do |page| | |
search_result = page.form_with(:name => 'f') do |search| |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
warn "Checking truthiness" | |
if @foo | |
# ... | |
end | |
warn "Done\n" | |
warn "Checking definedness and then truthiness" | |
if defined?(@foo) && @foo | |
# ... |
This file contains hidden or 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 'delegate' | |
# A constrained integer class representing Page Numbers | |
class PageNumber < DelegateClass(Integer) | |
BIGINT = 9223372036854775807 | |
def initialize(value, name) | |
value = value.to_i | |
if 'offset' == name ? (value < 0 or value > BIGINT) : value < 1 | |
raise RangeError, "invalid #{name}: #{value.inspect}" |