Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / _example_output.txt
Last active August 29, 2015 14:07 — forked from tomafro/example output
Find ActiveRecord columns without indexes
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
@teeparham
teeparham / CSS-only-Custom-Radio-Buttons.markdown
Last active August 29, 2015 14:20
CSS only Custom Radio Buttons
@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"