Skip to content

Instantly share code, notes, and snippets.

View scottwb's full-sized avatar

Scott W. Bradley scottwb

View GitHub Profile
[scottwb@test]% rake gems:install
(in /home/scottwb/src/my_rails_app)
Missing these required gems:
sanitize = 1.2.1
You're running:
ruby 1.8.6.383 at /usr/bin/ruby
rubygems 1.3.5 at /home/scottwb/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
[scottwb@test]% rake gems:install
(in /home/scottwb/src/my_rails_app)
rake aborted!
no such file to load -- gdata
/home/scottwb/src/ranger_site/Rakefile:10
(See full trace by running task with --trace)
[scottwb@test]% rake gems:install
(in /home/scottwb/src/my_rails_app)
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
@scottwb
scottwb / gist:499673
Created July 30, 2010 01:35
Ruby mixin overriding instance methods.
#!/usr/bin/env ruby
#
# Example showing how to make including a mixin override instance methods.
#
module TalksLikeMrT
def self.included(klass)
(klass.instance_methods & self.instance_methods).each do |method|
klass.instance_eval{remove_method method.to_sym}
end
@scottwb
scottwb / gist:513051
Created August 7, 2010 18:32
Console output showing MemoryStore freezing cached obejcts
scottwb-mbp% ruby script/console test
Loading test environment (Rails 2.3.5)
>> x = "some object"
=> "some object"
>> x.frozen?
=> false
>> Rails.cache.write("foo", x)
=> "some object"
>> x.frozen?
=> true
@scottwb
scottwb / memorystore_monkeypatch.rb
Created August 7, 2010 19:21
Monkey patch to fix Rails.cache with MemoryStore on Rails 2.3.X
if Rails.version <= "2.3.8"
module ActiveRecord
class Base
def dup
obj = super
obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup)
obj
end
end
end
#!/usr/bin/env bash
# Run inside an SVN working copy to output to stdout a template file
# you can use with `git svn --authors-file` when converting an SVN repository
# to git.
#
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";
done
@scottwb
scottwb / Makefile
Created August 18, 2010 06:18
Makefile to update/build/install Strings gems from source.
# Simple Makefile to update installed Strings gems from source instead of
# via gems.strings.com.
ROOT = ~/src
APIROOT = $(ROOT)/strings-api
WTLIBROOT = $(ROOT)/strings-webtracker
WTDEVROOT = $(ROOT)/strings-webtrackerdev
SCDEVROOT = $(ROOT)/strings-scraperdev
all: clean update gems get uninstall install
#!/usr/bin/python
###########################################################################
# Code that manipulates the /Library/Receipts/db/a.receiptdb file in
# Mac OS X 10.5 Leopard. The only functionality that is implemented
# is clean up a particular package that is listed.
#
# MAKE SURE YOU BACKUP BEFORE DOING ANYTHING. This script will
# automatically make a backup (a.receiptdb.old.*), but I recommend doing
# one yourself just in case. I have not extensively tested or
# optimized this code; in fact, I hacked it together in a few hours and
@scottwb
scottwb / enum_models.rb
Created August 23, 2010 20:37
Enumerate all Rails ActiveRecord::Base model classes.
# Add AR::Base class methods for enumerating all the model
# classes in a Rails project.
module ActiveRecord
class Base
def self.all_model_classes
connection.tables.map do |table|
begin
klass = Class.const_get(table.classify)
klass.ancestors.include?(self) ? klass : nil