Skip to content

Instantly share code, notes, and snippets.

View simplyb's full-sized avatar

Pete Broderick simplyb

View GitHub Profile
system:
system:
uname: "Darwin petes-macbook.home 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386"
bash: "/bin/bash => GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)"
zsh: "/bin/zsh => zsh 4.3.4 (i386-apple-darwin9.0)"
rvm:
version: "rvm 1.0.9 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"
Rabl.render(Event.first, 'events/event')
@simplyb
simplyb / scrubbin.rb
Created September 7, 2012 14:28
rake task to scrub tables
namespace :data do
desc "scrubs all strings in every table"
task :scrub => :environment do
unless Rails.env.development?
raise "This should only ever be run in development!"
end
tables = ActiveRecord::Base.connection.tables - ["schema_migrations"]
@simplyb
simplyb / rake_data.rb
Created September 7, 2012 14:39
data for a rake task
module MyApp
module RakeData
extend Self
HILARIOUS_STRING = 'Gangster lorem ipsum from http://lorizzle.nl/'
def tables
["list", "of", "table", "names"]
end
@simplyb
simplyb / multiscrub.rb
Created September 7, 2012 14:43
multi-threaded scrubbin
namespace :data do
MyApp::RakeData.tables.each do |table|
desc "scrubs #{table} table data"
task "scrub_#{table}" do
string_attributes = table.classify.constantize.columns.map {|c| c.name if [:string, :text].include?(c.type) }.compact
setters = []
update_string = "UPDATE #{table} SET "
string_attributes.each do |attribute|
development:
adapter: mysql2
encoding: utf8
database: my_db
pool: 20
username:
password:
module PreviouslyDirty
extend ActiveSupport::Concern
included do
attribute_method_suffix '_previously_changed?'
end
private
# Handle <tt>*_previously_changed?</tt> for +method_missing+.
> user = User.first
> user.name
=> "Frank"
> user.name = "John"
> user.name_changed?
=> true
> user.name_change
=> ["Frank", "John"]
> user.name = "John"
> user.save
> user.previous_changes
=> {"name"=>["Frank", "John"]}