Skip to content

Instantly share code, notes, and snippets.

View brentd's full-sized avatar

Brent Dillingham brentd

  • Asheville, NC
View GitHub Profile
// 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.
@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...
#
# 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: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');
# 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)
class A
@foo = "bar"
def self.foo
@foo
end
def foo
self.class.foo
end
class Card
include Comparable
attr_reader :rank
FACE_CARDS = {
'ace' => 1,
'jack' => 11,
'queen' => 12,
'king' => 13
}
~ → mkdir project_with_bundled_json
~ → cd project_with_bundled_json
~/project_with_bundled_json → echo "gem 'json'" > Gemfile
~/project_with_bundled_json → gem bundle
Calculating dependencies...
Updating source: http://gems.rubyforge.org
Downloading json-1.1.9.gem
Installing json-1.1.9.gem
Building native extensions. This could take a while...
Done.
diff --git a/lib/culerity/celerity_server.rb b/lib/culerity/celerity_server.rb
index c89e2d7..d2eb5c7 100644
--- a/lib/culerity/celerity_server.rb
+++ b/lib/culerity/celerity_server.rb
@@ -69,7 +69,8 @@ module Culerity
def proxify(result, in_array = false)
if result.is_a?(Array)
- result.map {|x| proxify(x, true) }.inspect
+ values = result.map {|x| proxify(x, true) }
diff --git a/lib/searchlogic/named_scopes/conditions.rb b/lib/searchlogic/named_scopes/conditions.rb
index 8329957..52faa82 100644
--- a/lib/searchlogic/named_scopes/conditions.rb
+++ b/lib/searchlogic/named_scopes/conditions.rb
@@ -122,7 +122,7 @@ module Searchlogic
when "blank"
{:conditions => "#{table_name}.#{column} = '' OR #{table_name}.#{column} IS NULL"}
when "not_blank"
- {:conditions => "#{table_name}.#{column} != '' OR #{table_name}.#{column} IS NOT NULL"}
+ {:conditions => "#{table_name}.#{column} != '' AND #{table_name}.#{column} IS NOT NULL"}