Skip to content

Instantly share code, notes, and snippets.

Harlow Ward harlow

Block or report user

Report or block harlow

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@harlow
harlow / capybara_example.rb
Created Feb 26, 2012
Capybara Cheat Sheet
View capybara_example.rb
# Navigating
visit('/projects')
visit(post_comments_path(post))
# Clicking links and buttons
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
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
end
@harlow
harlow / merge_pull_requests.md
Created Oct 26, 2012
Steps to accepting pull requests from open source contributors
View merge_pull_requests.md

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 = git@github.com:thoughtbot/[repo].git

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

@harlow
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
end
# This will use the User class (Admin would have been guessed)
Factory.define :admin, :class => User do |u|
View rules.md
  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]
end
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/, '') }
end
get '/stream', provides: 'text/event-stream' do
@harlow
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 = BookingPayment.new(booking_payment_params)
booking_payment.pay
respond_with payment, location: balance_trip_path
end
private
@harlow
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])
Importer.new(contact, csv_parser).import
expect(contact).to have_received(:create).with(:row1)
View tophashes-sliding-window-redis.sh
# ------------------------------------------------------------------
# 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.