Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / gist:329698
Created March 11, 2010 21:40
deserialize an array of ActiveRecord objects from xml
module ActiveRecord
class Base
# extends the patch here: http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/
def self.array_from_xml(xml)
hash_array = Hash.from_xml(xml).values.first
hash_array.nil? ? [] : hash_array.collect {|attributes_hash| from_hash(attributes_hash)}
end
@teeparham
teeparham / yoursite.rake
Created April 28, 2010 03:19
Rake task to configure Spree Authorize.net gateway
# rake yoursite:setup_gateway
namespace :yoursite
desc "Set up gateway"
task :setup_gateway => :environment do
Gateway.transaction do
auth_net = "Authorize.net"
gateway = Gateway.find_by_name_and_environment(auth_net, RAILS_ENV)
gateway.destroy unless gateway.nil?
@teeparham
teeparham / migration_helper.rb
Created May 20, 2010 20:54 — forked from scottjacobsen/migration_helper.rb
Migrations Helper for foreign keys
module MigrationHelper
#options are:
# :pk_table_name
# :pk_column_name
# :cascade_delete
# :cascade_update
def add_fk(fk_table_name, fk_column_name, options={})
fk_table_name = fk_table_name.to_s
fk_column_name = fk_column_name.to_s
pk_table_name = options[:pk_table_name] || fk_column_name[0, fk_column_name.index("_id") || fk_column_name.length].pluralize
@teeparham
teeparham / .gitconfig
Created June 22, 2010 19:40
git config
[color]
diff = auto
branch = auto
status = auto
ui = auto
[alias]
co = checkout
ci = commit -am
st = status
br = branch
# Samples for formatting additional Product fields in Spree Admin
# SelectField: adds a select box with values 1..20
# WideField: adds a standard text box, but with a specified size
# HugeField: adds a text area with a specified number of columns
Variant.additional_fields += [
{ :name => 'SelectField',
:only => [:product],
:use => 'select',
:value => Proc.new{ (1..20).collect{|i| [i,i]} }
@teeparham
teeparham / application_helper.rb
Created August 6, 2010 05:24
hack around rackspace CDN SSL limitation
def cloud_image_path(source)
if %w{development test}.include?(Rails.env) || request.ssl?
image_path(source)
else
"http://yourpath.cdn.rackspacecloud.com/" + source.split("/").last
end
end
def cloud_image_tag(source, options={})
image_tag(cloud_image_path(source), options)
@teeparham
teeparham / update_to_ruby_192_osx.sh
Created August 29, 2010 03:13
Update ruby to 1.9.2 (osx)
rvm update
rvm reload
rvm install 1.9.2
rvm gemset copy 1.9.1 1.9.2
rvm 1.9.2
sudo port install sqlite3
gem update sqlite3-ruby
gem uninstall ruby-debug19 ruby-debug-base19 columnize linecache19
@teeparham
teeparham / index.haml
Created September 16, 2010 20:22
Serve Pingdom uptime image from an https site
%h1 Uptime
= image_tag uptime_image_path, :height => "165", :width => "300"
@teeparham
teeparham / ruby64.sh
Created September 30, 2010 03:43
64-bit upgrade: rebuild ruby 1.9.2, mysql, and gems that need a rebuild
rvm uninstall 1.9.2
rvm remove 1.9.2
rvm install 1.9.2 -C --with-readline-dir=/opt/local,--build=x86_64-apple-darwin10
gem uninstall mysql
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
gem pristine --all
@teeparham
teeparham / monkey_sort.rb
Created November 10, 2010 06:13
sqlite sorts null values differently than postgres
# say we have a Monkey with a boolean column
create_table :monkeys do |t|
t.boolean :is_nice
end
Monkey.create()
Monkey.create(:is_nice => true)
Monkey.create(:is_nice => false)