Skip to content

Instantly share code, notes, and snippets.

View Default.sublime-keymap
{ "keys": ["ctrl+shift+."], "command": "erb" },
{ "keys": ["ctrl+shift+,"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } },
{ "keys": ["ctrl+super+r"], "command": "reveal_in_side_bar" }
ryanb / railscasts_episodes.rb
Created Jun 4, 2012
Download source code for all RailsCasts episodes. You may want to cd into an empty directory first.
View railscasts_episodes.rb
require "rubygems"
require "octokit" # gem install octokit
1.upto(5) do |page|
Octokit.repositories("railscasts", page: page, per_page: 100).each do |repo|
system "git clone git://{}"
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make install
View 1_let.rb
desc "A user's comment" do
let(:user) { User.create! name: "John" }
let(:comment) { user.comments.create! }
it "delegates to user's name" do eq(

This example is not my real app, but it's modeled pretty closely to it.

My mom schedules a couple hundred employees at a local warehouse. In their system, a worker can earn "points" for being late or missing shifts. Here we have a sort of summary screen for my mom, who may need to follow up with new employees or discipline employees with concerning levels of points.

Questions that arise as I code something like this:

  • Which objects deserve presenters?
ryanb / index.js.erb
Created Dec 16, 2011
Infinite scrolling solution covered in revised episode #114:
View index.js.erb
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
<% end %>
ryanb / employees_controller_test.rb
Created Sep 30, 2011 — forked from noahhendrix/employees_controller_test.rb
Testing a regular user can not create a user
View employees_controller_test.rb
require 'test_helper'
require 'clearance/testing'
class EmployeesControllerTest < ActionController::TestCase
test "an ASM can not create a user" do
assert_raise CanCan::AccessDenied do
post :create, :employee => { :name => 'Feed Store' }
ryanb / spec_helper.rb
Created Sep 12, 2011
Use RSpec tags to add behavior around specs.
View spec_helper.rb
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
ryanb / spec_helper.rb
Created Sep 12, 2011
Focus on specific specs in RSpec
View spec_helper.rb
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
# and then use the :focus tag in your specs
it "does something awesome", :focus do
View gist:1120754
$ rvm_archflags="-arch i386 -arch x86_64" ARCHFLAGS="-arch i386 -arch x86_64" CFLAGS='-arch i386 -arch x86_64' LDFLAGS='-arch i386 -arch x86_64' rvm pkg install zlib
Fetching zlib-1.2.5.tar.gz to /Users/rbates/.rvm/archives
Extracting zlib-1.2.5.tar.gz to /Users/rbates/.rvm/src
Configuring zlib in /Users/rbates/.rvm/src/zlib-1.2.5.
Compiling zlib in /Users/rbates/.rvm/src/zlib-1.2.5.
ERROR: Error running '/usr/bin/make ', please read /Users/rbates/.rvm/log/zlib/make.log
Installing zlib to /Users/rbates/.rvm/usr
ERROR: Error running '/usr/bin/make install', please read /Users/rbates/.rvm/log/zlib/make.install.log
$ cat /Users/rbates/.rvm/log/zlib/make.log