Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
View GitHub Profile
@brianjlandau
brianjlandau / 0_reuse_code.js
Created February 7, 2014 16:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@brianjlandau
brianjlandau / top_gifs.rb
Created January 2, 2013 17:07
This will go through all the gifs for the past year in one campfire room (back to the first of the current year) and calculate the most commonly posted gifs. It does this by grabbing the URL of the gif, getting the data and MD5ing it for comparison.
#!/usr/bin/env ruby
require 'rubygems'
require 'set'
require 'digest/md5'
require 'open-uri'
require 'tinder'
require 'active_support/all'
require 'awesome_print'
@brianjlandau
brianjlandau / gist:4162654
Created November 28, 2012 17:21
Setting up a Rails engine for MySQL, RSpec & Capybara

Setup RSpec and Capybara on a new Rails engine

  1. rails plugin new ENGINE_NAME --full --database=mysql

  2. Add to gemspec:

s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'shoulda-matchers'
s.add_development_dependency 'capybara'
s.add_development_dependency 'database_cleaner'
@brianjlandau
brianjlandau / spec_helper.rb
Created November 7, 2012 18:53
Visit a location in a Capybara rspec spec without following a redirect.
# ...
RSpec.configure do |config|
# ...
config.include VisitWithoutRedirectsHelper, :type => :request
# ...
end
class EmailCollection
include Enumerable
delegate :each, :to => :email_addresses
def initialize(raw_email_addresses)
@raw_email_addresses = raw_email_addresses
end
def valid_emails
select do |email|
@brianjlandau
brianjlandau / gist:3639233
Created September 5, 2012 16:15
Setting up for using JS driver in RSpec
config.before(:each, :type => :request) do
if example.metadata[:js]
self.class.use_transactional_fixtures = false
end
end
config.after(:each, :type => :request) do
if example.metadata[:js]
self.class.use_transactional_fixtures = true
DatabaseCleaner.clean # Truncate the database
Capybara.reset_sessions! # Forget the (simulated) browser state
@brianjlandau
brianjlandau / spec_helper.rb
Created August 29, 2012 15:35
RSpec spec_helper for Rails engine testing
$LOAD_PATH.unshift(File.dirname(__FILE__))
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'shoulda-matchers'
require 'capybara/rails'
require 'capybara/rspec'
require 'database_cleaner'
@brianjlandau
brianjlandau / gist:3124674
Created July 16, 2012 19:58
In ruby `+=` and `<<` behave slightly differently inside a `tap` block, because one modifies the object and the other reassigns a new object to the same named variable.
irb(main):001:0> my_text = ''
=> ""
irb(main):002:0> my_text += "this is a test"
=> "this is a test"
irb(main):003:0> my_text
=> "this is a test"
irb(main):004:0> my_text << " another test"
=> "this is a test another test"
irb(main):005:0> my_text
=> "this is a test another test"
module ActionView
module Helpers
module ActiveModelHelper
def error_messages_for(*params)
options = params.extract_options!.symbolize_keys
if object = options.delete(:object)
objects = Array.wrap(object)
else
objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
@brianjlandau
brianjlandau / heroku_deployer.rb
Created February 23, 2012 00:59
Heroku deploy plugin for cruise.rb
# Deploy To Heroku
#
class HerokuDeployer
attr_accessor :campfire_config
def initialize(project = nil)
@campfire_config = {}
end
def build_finished(build)