Skip to content

Instantly share code, notes, and snippets.

@JoelQ
JoelQ / month.rb
Last active November 10, 2023 04:17
require "date"
class Month
include Comparable
MONTHS_PER_YEAR = 12
def self.from_date(date)
self.from_parts(date.year, date.month)
end
@jessieay
jessieay / google_hangouts_audio_restart.sh
Last active April 19, 2017 19:34
Command to reset system sound for Google Hangouts
sudo kill -9 `ps ax|grep 'coreaudio[a-z]' |awk '{print $1}'`
@masonforest
masonforest / deliver_email_matcher.rb
Created May 17, 2013 22:00
rspec matcher for ActionMailer rails email delivery
# Usage
# order = create(:order)
#
# expect {
# order.pay!
# }.to deliver_email(OrderMailer, :paid, order.id)
#
#
@theotherzach
theotherzach / 20130310141955_add_hstore_extension.rb
Last active May 29, 2020 17:30
Rails 4 and Postgres: Getting HStore and Array
class AddHstoreExtension < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION hstore'
end
def down
execute 'DROP EXTENSION hstore'
end
end
@harlow
harlow / merge_pull_requests.md
Created October 26, 2012 19:10
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 = git@github.com:thoughtbot/[repo].git

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

@jessieay
jessieay / git
Created October 3, 2012 18:55
thoughtbot Git Process
BEFORE: start trajectory story
* run specific tests wrote (eg: rspec spec/decorators/event_decorator_spec.rb:5)
rake
git status
git diff
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)

Fixnum

Concepts
  • Numbers in Ruby are Objects
    • We can call methods on numbers
    • We can define methods on numbers
  • Tricks with Numbers
    • Integer with Integer gives Integer
    • Integer with Float gives Float
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=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')