Skip to content

Instantly share code, notes, and snippets.

View bschwartz's full-sized avatar

Brendan Schwartz bschwartz

View GitHub Profile
# if this is for a Rails app, drop it in /config/initializers
class Module
if defined?(:rake_original_const_missing)
def const_missing(const)
rake_original_const_missing(const)
end
end
// This is a jQuery monkey-patch that changes all PUT and DELETE requests
// into POST requests and sets a "_method" param to the original request method.
//
// This is a workaround for the fact that some corporate networks and
// environments don't allow PUT and DELETE requests.
//
// This whole thing works because Rails implements the _method hack.
(function(){
var ajaxWithoutMethodHack = jQuery.ajax;
jQuery.ajax = function( s ) {
<!-- Begin MailChimp Signup Form -->
<!--[if IE]>
<style type="text/css" media="screen">
#mc_embed_signup fieldset {
position: relative;
}
#mc_embed_signup legend {
position: absolute;
top: -1em;
left: .2em;
# Adjust sessions so they work across subdomains
# This also will work if your app runs on different TLDs
# from: http://szeryf.wordpress.com/2008/01/21/cookie-handling-in-multi-domain-applications-in-ruby-on-rails/
# modified to work with Rails 2.3.0
module ActionControllerExtensions
def self.included(base)
base::Dispatcher.send :include, DispatcherExtensions
end
@bschwartz
bschwartz / gist:63920
Created February 13, 2009 14:17
Easily loop through AR database records in chunks. Great for migrations.
# If you're doing migrations or work on large datasets,
# you don't want to do a Record.find(:all).each.
#
# Why you ask? Well, unless you have gobs of system memory, your system
# will be paging like gangbusters when it starts loading the entire db table
# into memory as AR objects.
#
# To use this just drop this file into the /lib dir of your Rails project and
# you'll be able to use it in any migration
#
# If you've ever worked with file uploads in Rails, you've probably realized that Rails
# handles uploads with a filesize under 10K differently than files over 10K.
# I prefer things to be as similar as possible so I wrote this quick monkey patch.
# Drop it in your config/initializers directory and you're off to the races.
#
# You should also check out Paperclip, acts_as_attachment, file_column, etc. because
# they take care of all this business for you.