Skip to content

Instantly share code, notes, and snippets.

View brentd's full-sized avatar

Brent Dillingham brentd

  • Asheville, NC
View GitHub Profile
# Adds a view for MongoMapper documents when using Hirb.
begin
require 'hirb'
class Hirb::Views::MongoMapper_Document
def self.default_options
{:ancestor => true}
end
def self.render(rows, options={})
rows = Array(rows)
@brentd
brentd / gist:349955
Created March 31, 2010 04:56
delay jQuery's trigger() to prevent queueing
// Like jQuery's trigger(), only the firing of the event can be delayed by the
// specified duration (in milliseconds). The timer is reset on consecutive
// triggers with the same event name, so only the most recent event will be
// triggered when the duration ends. Useful if you need to prevent events from
// queueing up.
//
// $('#foo').bind('myEventName', function() {alert('hai')});
// ...
// $('#foo').delayedTrigger(1000, 'myEventName', 'event1');
// $('#foo').delayedTrigger(1000, 'myEventName', 'event2');
# Allows you to build a Hash in a fashion very similar to Builder. Example:
#
# HashBuilder.build! do |h|
# h.name "Brent"
# h.skillz true
# h.location do
# h.planet "Earth"
# end
# end
#
@brentd
brentd / gist:366249
Created April 14, 2010 19:50
Temporarily redirect ActiveRecord query logging
# Semi-evil way to force ActiveRecord to temporarily redirect where it's
# logging SQL queries. Quick way to find out why the crap that query
# isn't working - helpful especially when debugging a failing test.
#
# Can't use `ActiveRecord::Base.logger = foo` because that'll only work for
# new DB connections. Can't just reset connections because doing so in the
# middle of a test would abort transactions.
#
# So we resort to evil...
#
// In an NSOperation subclass...
- (void)main {
@try
{
// Do some stuff that could be buggy...
}
@catch(NSException* ex)
{
// For debugging purposes, re-raise in the main thread any exceptions that are thrown in this thread.
# encoding: utf-8
module Mongoid #:nodoc:
module Associations #:nodoc:
module EmbeddedCallbacks
# bubble callbacks to embedded assocaitions
def run_callbacks(*args)
# now bubble callbacks down
self.associations.each_pair do |name, meta|
if meta.association == Mongoid::Associations::EmbedsMany
@brentd
brentd / parallel_asset_compiler.rb
Created July 31, 2012 23:11
Parallelize assets:precompile
require 'parallel' # gem install parallel (https://github.com/grosser/parallel)
# Monkey patch to Sprockets::StaticCompiler, a class provided by actionpack
# that's used by the assets:precompile task. This patch uses the Parallel gem
# to parallelize asset compilation in the simplest way possible.
#
# Parallel wraps Process.fork to handle things like inter-process communication
# via pipes and determining the maximum number of processes to run based on
# your system's total logical processors. So far only tested on MRI 1.9.3 on OS X.
module Sprockets
@brentd
brentd / spec_helper.rb
Created September 30, 2012 00:09
Useful for monitoring/debugging requests when using VCR
VCR.configure do |c|
c.after_http_request do |request, response|
puts "\n\n#{request.method.upcase} #{request.uri}"
puts
puts caller.grep(/^#{Rails.root}/)
puts
puts request.to_yaml
puts
puts response.to_yaml
end
@brentd
brentd / gist:4591959
Last active December 11, 2015 11:08
Sublime Text 2 performance on 13" Retina MBP

I love my new 13" rMBP, but there are performance issues here and there - Sublime is definitely one of them. However with a few tweaks I've been able to get performance up to what I would call acceptable.

Steps:

  1. Grab the latest build of Sublime (currently 2219); it has retina fixes. http://www.sublimetext.com/nightly
  2. Install HEAD of the Soda theme (instructions under "Download Manually"): https://github.com/buymeasoda/soda-theme/
  3. Make these tweaks to your User Preferences (cmd-,):
{
@brentd
brentd / _hidpi.scss
Last active December 12, 2015 08:58
SASS/SCSS mixin for hidpi/retina devices. Altered from work by @kaelig: https://github.com/kaelig/hidpi/blob/master/_hidpi.scss
@import 'compass/css3';
// Create a media query for hidpi (retina) devices. If `$image` is provided,
// generates CSS that sets the image as a background for both normal and hidpi
// screens, assuming that the hidpi version ends with `@2x` before the file
// extension. `$extension` must be supplied separately because Sass does not
// yet support string substitution (defaults to png).
//
// Note: assumes a Rails 3.1 environment using the asset pipeline with compass
// installed. Only minimal changes are needed for it to work elsewhere.