Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
@d11wtq
d11wtq / oedipus-distributed.rb
Created May 14, 2012 14:48
Brainstorming an interface for distributed indexes with oedipus and oedipus-dm
# normally
idx = conn[:posts_rt]
idx.insert( ... )
idx.search( ... )
# distributed
idx = conn[:posts_dist, ->(id){ "posts_rt_#{id % 4}" }]
idx.insert( ... )
idx.search( ... )
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)
/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.
@d11wtq
d11wtq / gist:2215235
Created March 27, 2012 11:45
Brainstorming Sphinx 2 gem
##
# Using an index defined in code for model abstraction.
##
class PostsIndex
include Oedipus::RTIndex
connection 'sphinx.site.com:3312'
index_name :posts_rt
; 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:
class QueryParser < Whittle::Parser
rule(:wsp => /\s+/).skip!
rule("(")
rule(")")
rule("AND") % :left ^ 1
rule("OR") % :left ^ 1
rule(">") % :left ^ 2
class QueryParser < Whittle::Parser
rule(:wsp => /\s+/).skip!
rule("(")
rule(")")
rule("AND") % :left
rule("OR") % :left
rule(">") % :left ^ 1
@d11wtq
d11wtq / gist:1413222
Created December 1, 2011 03:19
Complex number representation of a decimal should be considered a real number, but is not.
[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
require 'whittle'
class Parser < Whittle::Parser
class StringParser < Whittle::Parser
rule('"')
rule(:esc => /\\./).as { |esc| eval('"' + esc + '"') }
rule(:chars => /[^\\"]+/)
require 'whittle'
class Parser < Whittle::Parser
rule("class")
rule("(")
rule(")")
rule("{")
rule("}")