Skip to content

Instantly share code, notes, and snippets.

View mcmire's full-sized avatar
🎯
Not a lot of time for side projects these days, so ping me if I'm unresponsive!

Elliot Winkler mcmire

🎯
Not a lot of time for side projects these days, so ping me if I'm unresponsive!
View GitHub Profile
@mcmire
mcmire / gist:49602
Created January 20, 2009 18:58
Extending Prototype to retain order of form data when sending an Ajax request
Object.extend(Object, {
clone: function(object) {
return object.clone ? object.clone() : Object.extend({ }, object);
},
toQueryString: function(object) {
return object.toQueryString ? object.toQueryString() : $H(object).toQueryString()
}
});
var PseudoHash = Class.create(Hash, (function() {
@mcmire
mcmire / Improving not_a_mock.rb
Created February 28, 2009 23:12
Various ideas for improving not_a_mock so that we don't have to track methods manually
# Various ideas for improving not_a_mock so that we don't have to track methods manually
# Note that none of these work, so don't try them
class Object
def track_all_methods
ancestors = self.class.ancestors - [Object, Kernel, ...] # insert all of Ruby Core classes here
instance_methods = ancestors.map {|x| x.instance_methods(false) }
class_methods = ancestors.map {|x| x.singleton_methods(false) }
methods = (instance_methods + class_methods).flatten.map {|x| x.to_sym }
track_methods(*methods)
@mcmire
mcmire / YAML::Omap fix in Ruby 1.8.7
Created April 10, 2009 21:32
YAML::Omap fixes for Ruby 1.8.6
#!/usr/bin/env ruby
#
# In Ruby 1.8.6, there's a bug in YAML that is revealed when you
# serialize and then deserialize a large YAML::Omap. If you look
# at the generated YAML, it looks like every so often, instead
# of an object showing up in the YAML file, the object is skipped
# and another a reference to another object shows up. This does
# not seem to happen with an Array of values, or an Array of Arrays,
# or an Array of Hashes, or a Hash. This behavior was fixed in 1.8.7.
#
@mcmire
mcmire / actionmailer_layout_patch.rb
Created May 7, 2009 15:35
ActionMailer plain text layout fix
# Patch Rails so that a plain text mailer view won't be rendered with the layout
# Only tested in Rails 2.2 - I'm not sure how this works with 2.3
module ActionMailer
class Base
def candidate_for_layout?(options)
return false if ActionView::Template === options[:file] && options[:file].content_type == "text/plain"
!@template.send(:_exempt_from_layout?, default_template_name)
end
end
end
@mcmire
mcmire / powergrep.pl
Created May 14, 2009 15:34
powergrep -- improved rgrep with colors and the ability to omit directories
#!/usr/bin/perl
#================================================================================
# powergrep -- improved rgrep with colors and the ability to omit directories
#================================================================================
# Created: 6 Sep 2007
# Last modified: 2 Jun 2009
# (c) 2007-2009 Elliot Winkler
#================================================================================
# CHANGELOG:
# * 2 Jun 2009 - added --mate option to open matched files in TextMate
@mcmire
mcmire / delayed_observer.js
Created October 27, 2009 02:53
Maxime Haineault's jQuery delayed observer, with some improvements.
/*
jQuery delayed observer
(c) 2007 - Maxime Haineault (max@centdessin.com)
Special thanks to Stephen Goguen & Tane Piper.
Slight modifications by Elliot Winkler
*/
(function() {
@mcmire
mcmire / require_profiler.md
Created January 14, 2010 16:24
Record how long it takes to require files in your Ruby code and view a hierarchical report.

require_profiler

require_profiler in action

What is this?

This script of sorts overrides require and load to record the time it takes to require files within a section of your code, and then generates a report afterward. It's intelligent enough to figure out where files were required from and construct a hierarchy of the required files.

@mcmire
mcmire / SvnToGit.pm
Created February 1, 2010 04:10
Utilities for converting an SVN repository with an inconsistent layout to Git.
#!/usr/bin/env perl
#
# A reimplementation of James Coglan's svn2git Ruby script as a Perl
# module and accompanying executable, forked from
# http://github.com/schwern/svn2git by Elliot Winkler.
#
# Changes are as follows:
#
# * Update fix_tags and fix_trunk so they're closer to Ruby script
# * Change default behavior so that the directory for the git repo will
@mcmire
mcmire / single_attribute_validations.rb
Created March 27, 2010 07:08
Run a single validation on a single attribute
module ActiveRecord
class Base
VALIDATION_SYMBOLS = %w(
acceptance confirmation exclusion format inclusion length numericality presence size uniqueness
).inject({}) {|hash, name| hash["validates_#{name}_of"] = name; hash }
VALIDATION_METHODS = VALIDATION_SYMBOLS.invert
class << self
def validations
@validations ||= {}
@mcmire
mcmire / speeding_up_spork.rb
Created August 17, 2010 16:13
Patch to speed up Spork
# Don't reload views or routes
# This (along with setting cache_classes to false) brought running a
# single spec file down from 7.4s to 2.8s
# See discussion: http://github.com/timcharper/spork/issues#issue/13
#
# To install, put this in spec/support and then require it in your spec_helper like:
#
# require 'spork'
# require File.expand_path(File.dirname(__FILE__) + "/support/spork")
#