Skip to content

Instantly share code, notes, and snippets.

@blatyo
blatyo / failure.txt
Created April 27, 2014 21:27
example test failure
expected #<Nokogiri::XML::Document:0x3ff1a047c080 name=\"document\" children=[#<Nokogiri::XML::Element:0x3ff1a047baf4 name=\"message\" children=[#<Nokogiri::XML::Element:0x3ff1a047b874 name=\"name\" children=[#<Nokogiri::XML::Text:0x3ff1a047b4dc \"bob\">]>]>]> to equal #<Nokogiri::XML::Document:0x3ff1a0c1051c name=\"document\" children=[#<Nokogiri::XML::Element:0x3ff1a0c17268 name=\"message\" children=[#<Nokogiri::XML::Element:0x3ff1a0c16de0 name=\"name\" children=[#<Nokogiri::XML::Text:0x3ff1a0c16570 \"jake\">]>]>]>"
# Input
['a', 'a', 'a', 'b', 'b']
# Output
=> ['a']
class TallyBag
include Enumerable
def initialize
@tallys = Hash.new{0}
end
def each
if block_given?
@tallys.each(&Proc.new)
@blatyo
blatyo / example_usage.rb
Last active December 16, 2015 02:29
In order to avoid sleeping for long periods of time, switch to a frequent polling mechanism, so the success case is fast.
expect{current_path}.to eventually_eql('/')
expect{current_path}.to eventually_match(%r{/boxes/PS\d+/shipping_information/new})
expect{get_me_the_cookie('foo')[:value]}.to eventually_eql('bar')
@blatyo
blatyo / iteration.rake
Created February 27, 2013 12:50
Just creates a rake task that does the same as `db:migrate` for a different directory. Uses the same schema migrations table that migrations use. We don't migrate down for iterations.
namespace :iteration do
desc "Runs the tasks for the current iteration"
task :current => 'iteration:migrate'
desc 'Runs the unrun iteration tasks'
task :migrate => :environment do
mig = ActiveRecord::Migrator.new(:up, File.join(Rails.root, 'db', 'iterations'))
mig.migrate
end
require 'page_rankr'
class PageRankr::Ranks::GoogleHk < PageRankr::Ranks::Google
def url
"http://toolbarqueries.google.com.hk/tbr"
end
end
tracker = PageRankr::Ranks::GoogleHk.new('www.google.com')
puts "Rank #{tracker.run}"
puts tracker.body
tis = %w(SR123 SR234 SR5677)
MessageDispatcher.some_method(*tis)
class MessageDispatcher
def some_method(ti1, ti2, ti3, *other_tis)
#blah
end
end
@blatyo
blatyo / brice_spec.rb
Created August 28, 2011 00:59
My comments are prepended with ACM
# This is the method I am testing.
class Log
private
class Parse
@queue = :parse
# This is a resque job. perform will ultimately be called asynchronously.
# Therefore, must find the Log before performing the action because it
# may be dirty or have been deleted since.
def self.perform(log_id)
# ACM: I would change
@blatyo
blatyo / .bashrc
Created August 21, 2011 18:41
.bashrc
##### Aliases #####
#Shortcuts
alias mysql="mysql -u root"
#Processes and Ports
alias fp="ps -ef | grep -i "
alias fpp="lsof -i -P | grep -i listen"
#Git
@blatyo
blatyo / .bashrc
Created August 21, 2011 18:40
.bashrc
##### Aliases #####
#Shortcuts
alias mysql="mysql -u root"
#Processes and Ports
alias fp="ps -ef | grep -i "
alias fpp="lsof -i -P | grep -i listen"
#Git