This file contains hidden or 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
# normally | |
idx = conn[:posts_rt] | |
idx.insert( ... ) | |
idx.search( ... ) | |
# distributed | |
idx = conn[:posts_dist, ->(id){ "posts_rt_#{id % 4}" }] | |
idx.insert( ... ) | |
idx.search( ... ) |
This file contains hidden or 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 Flippa | |
module Job | |
# Allow Resque jobs to be instantiated and performed, instead of singleton classes. | |
module Instance | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# Default .perform creates an instance and calls perform on that. | |
def perform(*args) | |
new(*args).perform(*args) |
This file contains hidden or 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
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model/relationship.rb:372:in `method_missing' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model/property.rb:249:in `method_missing' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:514:in `load_missing_constant' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in `block in const_missing' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `each' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model.rb:728:in `const_missing' | |
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1. |
This file contains hidden or 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
## | |
# Using an index defined in code for model abstraction. | |
## | |
class PostsIndex | |
include Oedipus::RTIndex | |
connection 'sphinx.site.com:3312' | |
index_name :posts_rt |
This file contains hidden or 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
; Returns a lambda, which for each invocation gives the next Fibbonnaci number | |
fib := { a := 0 | |
b := 1 | |
{ n := a | |
c := a + b | |
a = b | |
b = c | |
n } } | |
seq := fib: |
This file contains hidden or 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 QueryParser < Whittle::Parser | |
rule(:wsp => /\s+/).skip! | |
rule("(") | |
rule(")") | |
rule("AND") % :left ^ 1 | |
rule("OR") % :left ^ 1 | |
rule(">") % :left ^ 2 |
This file contains hidden or 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 QueryParser < Whittle::Parser | |
rule(:wsp => /\s+/).skip! | |
rule("(") | |
rule(")") | |
rule("AND") % :left | |
rule("OR") % :left | |
rule(">") % :left ^ 1 |
This file contains hidden or 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
[1] pry(main)> Complex("2.5") | |
=> (2.5+0i) | |
[2] pry(main)> Rational("2.5") | |
=> (5/2) | |
[3] pry(main)> Complex("2.5") == Rational("2.5") | |
=> true | |
[4] pry(main)> Complex("2.5").real? | |
=> false | |
[5] pry(main)> Rational("2.5").real? | |
=> true |
This file contains hidden or 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 'whittle' | |
class Parser < Whittle::Parser | |
class StringParser < Whittle::Parser | |
rule('"') | |
rule(:esc => /\\./).as { |esc| eval('"' + esc + '"') } | |
rule(:chars => /[^\\"]+/) |
This file contains hidden or 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 'whittle' | |
class Parser < Whittle::Parser | |
rule("class") | |
rule("(") | |
rule(")") | |
rule("{") | |
rule("}") |