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 Array | |
def recursive_reverse | |
return self if empty? | |
[pop, *reverse] | |
end | |
end | |
puts [1,2,3,4].recursive_reverse.inspect |
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
# #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 |
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/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. |
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
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 |
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
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 | |
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
<item>...</item> |
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
var Foo = exports.Foo = function (cb) { | |
this.foo = 0; | |
if(!!cb) cb(this); | |
} | |
Foo.prototype.toString = function () { | |
return "[object Foo foo:"+this.foo+"]"; | |
} |
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
FAIL |
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
PASS |
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
require 'benchmark' | |
N = 1_000_000 | |
data = {:x => 1, :y => 2, :z => 3} | |
key = :usage | |
token = "asdf1234ghij5678klmn90op" | |
data_dump = Marshal.dump(data) |