Skip to content

Instantly share code, notes, and snippets.

View mtodd's full-sized avatar
🔐
[redacted]

Matt Todd mtodd

🔐
[redacted]
View GitHub Profile
class Array
def recursive_reverse
return self if empty?
[pop, *reverse]
end
end
puts [1,2,3,4].recursive_reverse.inspect
# #to_json isn't populating the results correctly and a CircularReference error
# is getting raised. This makes sure that populate is called first and #to_json
# is called on the result array.
ThinkingSphinx::Search.class_eval do
def as_json(*args)
populate
@array.as_json(*args)
end
def to_json(*args)
populate
diff --git a/lib/thinking_sphinx.rb b/lib/thinking_sphinx.rb
index 5437116..b6dbff6 100644
--- a/lib/thinking_sphinx.rb
+++ b/lib/thinking_sphinx.rb
@@ -53,6 +53,16 @@ module ThinkingSphinx
end
end
+ # A SphinxError occurs when Sphinx responds with an error due to problematic
+ # queries or indexes.
module Enumerable
def each_with_context(&block)
block.call([nil, self[0], self[1]])
self.each_cons(3, &block)
block.call([self[self.size - 2], self[self.size - 1], nil])
self
end
def enum_with_context
Enumerable::Enumerator.new(self, :each_with_context)
end
def get_bread_crumb(request, separator = " » ", breadcrumb = [], so_far = '/')
url = request.respond_to?(:request_uri) ? request.request_uri : request
elements = url.split('/')
elements.each_with_index do |element, i|
is_last = i == elements.size - 1 # whether this is the last item or not
so_far += element + '/' # the URL for this element
breadcrumb << # append this element to the breadcrumb
case element
<item>...</item>
var Foo = exports.Foo = function (cb) {
this.foo = 0;
if(!!cb) cb(this);
}
Foo.prototype.toString = function () {
return "[object Foo foo:"+this.foo+"]";
}
FAIL
PASS
require 'benchmark'
N = 1_000_000
data = {:x => 1, :y => 2, :z => 3}
key = :usage
token = "asdf1234ghij5678klmn90op"
data_dump = Marshal.dump(data)