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
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://github.com/railscasts/#{repo.name}"
end
end
View chef_solo_bootstrap.sh
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
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
comment.name.should eq(user.name)
end
end
View 0_the_explanation.md

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
ryanb / index.js.erb
Created Dec 16, 2011
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
View index.js.erb
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@ryanb
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
sign_in
assert_raise CanCan::AccessDenied do
post :create, :employee => { :name => 'Feed Store' }
end
@ryanb
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
example.call
end
end
end
@ryanb
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
end
# 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