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
odds_server = Proc.new do |env| | |
if env['PATH_INFO'] == '/odds' | |
[200, {'Content-Type'=>'application/json'}, '{claim_code:"123-sdfjhsdf"}'] | |
else | |
[404, {}, ''] | |
end | |
end | |
run Rack::Cascade.new([odds_server, Merb::Rack::Application.new]) | |
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
--- | |
development: &defaults | |
:url: http://0.0.0.0:5984/gathering | |
production: &production | |
<<: *defaults | |
:url: http://0.0.0.0:5984/gathering |
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 'timeout' | |
class RequestTimeout < Merb::Rack::Middleware | |
def initialize(app, seconds) | |
super(app) | |
@seconds = seconds | |
end | |
def deferred?(env) |
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 Array | |
def weighted_random(weight_method=:weight) | |
return nil if empty? # return nil if there's no elements | |
elements = sort_by { Kernel.rand } # shuffle the elements. | |
weights = elements.map(&weight_method) # get the weight for each element (e.g.: 5, 10, 2, 0, 1, 5). | |
point = Kernel.rand * weights.sum # pick a random point between zero and the sum of the weights. | |
elements.zip(weights).each do |e, weight| # walk through each element, | |
return e if weight >= point # and if its weight is >= the point, return it | |
point -= weight # otherwise subtract the element's weight from the point |
NewerOlder