Skip to content

Instantly share code, notes, and snippets.

View bschwartz's full-sized avatar

Brendan Schwartz bschwartz

View GitHub Profile
@bschwartz
bschwartz / full-scrub.js
Created November 6, 2014 18:15
Scrub all query params with FreshURL
FreshUrl.waitsFor(function(){freshUrl.allReady()}).then(function(){
// This will fire once all analytics platforms are ready
// Scrub everything in the query string, not just utm_*
window.history.replaceState({}, '', window.location.pathname + window.location.hash);
});
# 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.
@bschwartz
bschwartz / multitopic.rb
Created November 11, 2014 13:52
Consume from multiple topics into a single queue
require 'nsq'
require 'thread'
queue = Queue.new
consumer_for_topic1 = Nsq::Consumer.new(
topic: 'topic1',
channel: 'multi-topic-consumer',
queue: queue
)
#
# Put this in a directory and create a `Gemfile` with this in it:
#
# source 'https://rubygems.org'
# gem 'nsq-cluster'
# gem 'nsq-ruby'
#
# Then run `bundle install` to install the require gems.
# Then run this like so: `ruby fin-failer.rb`
#