This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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... | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
@foo = "bar" | |
def self.foo | |
@foo | |
end | |
def foo | |
self.class.foo | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Card | |
include Comparable | |
attr_reader :rank | |
FACE_CARDS = { | |
'ace' => 1, | |
'jack' => 11, | |
'queen' => 12, | |
'king' => 13 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ → 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |