Skip to content

Instantly share code, notes, and snippets.

View pius's full-sized avatar

Pius Uzamere pius

View GitHub Profile
require 'pp'
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = 'testing'
class Site
include MongoMapper::Document
key :domain, String
key :authorizations, Array
module Rack
class AllYourBase
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
@request = Rack::Request.new(env)
def losses
(prompts_on_the_left.collect(&:votes_count).sum + prompts_on_the_right.collect(&:votes_count).sum)
end
def wins
votes_count
end
def score
(wins.to_f / (wins + losses) ) * 100
@pius
pius / db_eval.rb
Created November 10, 2009 15:15 — forked from jnunemaker/db_eval.rb
require 'pp'
require 'rubygems'
require 'mongo_mapper'
require 'benchmark'
MongoMapper.database = 'testing'
class Foo
include MongoMapper::Document
@pius
pius / rlsp.rb
Created November 8, 2009 21:31 — forked from h0rs3r4dish/rlsp.rb
#!/usr/bin/ruby
RLSP_VERSION = "1.4.1"
class Lambda
attr_accessor :args, :body
def initialize(args=[],body="")
@args = (args.class == Array) ? args : [args]
@body = body
end
> m = function() { emit(this.triples.rdf:type.value,1); }
Sun Nov 8 10:34:20 JS Error: SyntaxError: missing ) after argument list (shell):0
#!/usr/bin/perl
use POSIX;
if (ttyname(1)){
print "Shell\n";
}
else {
print "Cron\n";
}
#obligatory clever one-liner in response to http://rubyflow.com/items/2904
def sum_of_multiples_of_3_and_5_less_than(limit)
1.upto(limit-1).reject { |x| (x.modulo(3) != 0) and (x.modulo(5) != 0) }.inject(0) {|n,sum| n + sum}
end
def predicate_nominative_pronoun
case gender
when 'm', 'M'
'him'
when 'f', 'F'
'her'
else
last_name
end
end
def predicate_nominative_pronoun
case gender
when 'm', 'M'
return 'him'
when 'f', 'F'
return 'her'
else
return last_name
end
end