Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
  • 19:53 (UTC -07:00)
View GitHub Profile
@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 / soft_delete.rb
Created December 14, 2011 00:32
This is a soft delete mixin for ActiveRecord 3.x. All you need to do is add a `deleted_at` column to the ActiveRecord models you mix this into.
module SoftDelete
extend ActiveSupport::Concern
included do
define_model_callbacks :soft_delete
define_model_callbacks :recover
default_scope where(:deleted_at => nil)
class_eval do
class << self
alias_method :with_deleted, :unscoped
@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
require 'hoptoad_notifier'
require 'resque/failure/base'
module Resque
module Failure
# A Failure backend that sends exceptions raised by jobs to Hoptoad.
#
# To use it, put this code in an initializer, Rake task, or wherever:
#
# require 'resque/failure/simpler_hoptoad'
# run_test functional/users_controller
run_test() {
ruby -Itest test/$1_test.rb
}
# run_fun_test users
run_fun_test(){
run_test functional/$1_controller
}
if rails_env = ENV['RAILS_ENV']
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
IRB.conf[:IRB_RC] = Proc.new do
# Called after the irb session is initialized and Rails has
# been loaded (props: Mike Clark).
if defined? ActiveRecord::Base
ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
end