Skip to content

Instantly share code, notes, and snippets.

@we4tech
we4tech / _your_model.rb
Created June 20, 2012 03:49
Fix 1 error(s) on assignment of multiparameter attributes for dynamic column or encapsulated column accessor
# Put it on your model instance
def column_for_attribute(name)
# Put your accessor name, in my case :value
if :value == name.to_sym
self.class.columns_hash[self.field.value_column.to_s]
else
self.class.columns_hash[name.to_s]
end
end
@matthewmccullough
matthewmccullough / gist:988077
Created May 24, 2011 03:02
Visualize Git Orphans via gitk and log
# Put this in your .gitconfig file under the alias section
orphank = !gitk --all `git reflog | cut -c1-7`&
# Then run it by typing 'git orphank' on the command line.
# A text version of the same is
orphanl = !git --pretty=oneline --abbrev-commit --graph --decorate `git reflog | cut -c1-7`
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@pdswan
pdswan / patch_through_belongs_to.rb
Created November 12, 2010 15:39
swaps the foreign key and primary key to fix has_many and has_one through belongs_to in Rails 2.3.x
class ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
# has_many and has_one through belongs_to are broken becuase the order of the primary key
# and foreign table key need to be reversed. this detects and fixes it.
def association_join_with_through_belongs_to_fix
join = association_join_without_through_belongs_to_fix
if [:has_many, :has_one].include?(reflection.macro) && reflection.options[:through] && source_reflection.macro == :belongs_to
connection = reflection.active_record.connection
parent_table_name = connection.quote_table_name(parent.aliased_table_name)
parent_key = connection.quote_column_name(parent.primary_key)
@zachhale
zachhale / payflow_recurring.rb
Created March 10, 2010 20:45
Class extension for ActiveMerchant's PayPalGateway to add recurring billing code.
# http://blog.vuzit.com/2008/08/01/paypal-website-payments-pro-us-with-recurring-billing-and-activemerchant/
# The MIT License
#
# Copyright (c) 2008 Vuzit.com, Chris Cera, Tobias Luetke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell