Skip to content

Instantly share code, notes, and snippets.

Harlow Ward harlow

View GitHub Profile
harlow / capybara_example.rb
Created Feb 26, 2012
Capybara Cheat Sheet
View capybara_example.rb
# Navigating
# Clicking links and buttons
click_link('Link Text')
click('Link Text') # Click either a link or a button
click('Button Value')
View gist:2510198
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'json'
class Repo
def initialize(name)
@name = name
harlow /
Created Oct 26, 2012
Steps to accepting pull requests from open source contributors

Add contributors pull requests to your origin remote

# .git/config
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
  url =[repo].git

Fetch and checkout the remote branch. Run bundle to make sure any new dependencies are installed.

harlow / factory_girl_example.rb
Created Dec 4, 2012
Factory Girl Cheat Sheet
View factory_girl_example.rb
# This will guess the User class
Factory.define :user do
first_name 'John'
last_name 'Doe'
admin false
# This will use the User class (Admin would have been guessed)
Factory.define :admin, :class => User do |u|
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done.

You can break these rules if you can talk your pair into agreeing with you.

View use_factory_method.rb
# app/models/customer.rb
class Customer
attr_reader :id, :country
def initialize(attrs = {})
@id = attrs[:id]
@country = attrs[:country]
def tax_code
View chat.rb
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
get '/stream', provides: 'text/event-stream' do
harlow / booking_payments_controller.rb
Last active Dec 15, 2015 — forked from jordelver/booking_payment_controller.rb
Use ActiveModel::Model for validations on non-AR objects
View booking_payments_controller.rb
class BookingPaymentsController < ApplicationController
def create
booking_payment =
respond_with payment, location: balance_trip_path
harlow / rspec_spies.rb
Created Apr 6, 2013
using spies with rspec-mocks
View rspec_spies.rb
require 'spec_helper'
describe Importer, '#import' do
it 'creates a record for each row' do
contact = double(create: true)
csv_parser = double(rows: [:row1, :row2]), csv_parser).import
expect(contact).to have_received(:create).with(:row1)
# ------------------------------------------------------------------
# Desigining "trending topics in 24 hours sliding window" with Redis
# ------------------------------------------------------------------
redis-cli del tophashes:2010-12-07-08-00
redis-cli del tophashes:2010-12-07-09-00
redis-cli del tophashes:current
echo '=== 8:00 AM ==='
You can’t perform that action at this time.