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 / 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)
@brianjlandau
brianjlandau / gist:1831069
Created February 14, 2012 22:28
Start new git branch with no history.
git symbolic-ref HEAD refs/heads/my-branch-name
rm .git/index
git clean -fdx
touch README
git add .
git commit -m "Initial Commit"
@brianjlandau
brianjlandau / gist:1435109
Created December 5, 2011 20:00
Nokogiri what did you do to the text of this element!
(rdb:1) text = page.find('.my-class').base.native.content
"5000 ms"
(rdb:1) text.force_encoding("UTF-8")
"5000 ms"
(rdb:1) s = "5000 ms"
"5000 ms"
(rdb:1) s.force_encoding("UTF-8")
"5000 ms"
(rdb:1) text == s
false
# Other deploy stuff
begin
require 'tinder'
after "deploy", "campfire"
after "deploy:migrations", "campfire"
after "deploy:rollback", "campfire"
desc '[internal] Announces deployments a Campfire room.'
# Project-specific configuration for CruiseControl.rb
Project.configure do |project|
# ...
project.campfire.config = {
:domain => 'SUBDOMAIN',
:room => 'ROOM_NAME',
:token => 'API_KEY',
:ssl => true
#!/bin/bash
IFUP=/etc/network/if-up.d/iptables.sh
IFDOWN=/etc/network/if-down.d/iptables.sh
IPTABLES() {
echo iptables $@ >&1 2>&1
iptables $@
}
module Enumerable
def reject_blanks
reject do |i|
i.blank? || (i.respond_to?(:values) && i.values.all?(&:blank?))
end
end
end