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
== overview: | |
builtin: rake, rubygems, json, securerandom, HMAC digests | |
removed: base64 (unpack("m*")) | |
== nye ting: | |
Hash syntax ( {foo: "bar"} #=> {:foo => "bar"}) | |
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
# Hitting Memcached while running tests is a _really_ bad idea. This class is basically a glorified hash, keeping track of what's given to it, | |
# seems to work acceptably in test env. | |
# The way the Cache module works, it assumes a constant named CACHE to keep the actual holder for cached data - this class provides what seems to be needed for the | |
# engine not to complain | |
class MockCached | |
class Value | |
attr_reader :value | |
def initialize(value, expiry=nil) | |
@value = value | |
@expiry = expiry |
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 Location: | |
def __init__(self): | |
pass | |
def degreesPerHour(self): | |
return self.degreesAtNoon / ((self.sunSetsAt - self.sunRisesAt) / 2) | |
class Forecast: | |
def __init__(self, startsAt): |
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
# A small script that collects details about matches in the Norwegian eliteserien and returns these as Ruby objects | |
# If you run this file itself, will return a list with details for the teams | |
require 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
class Team | |
include Comparable | |
attr_accessor :team_name, :matches, :wins, :losses, :draws, :plus, :minus, :points |
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 Modulus11 | |
def modulus_11_ok? | |
sum = 0 | |
weights = [5,4,3,2,7,6,5,4,3,2] | |
digits = cdv_string.split(//) | |
10.times do |n| | |
num = digits[n].to_i | |
sum += num.to_i * weights[n].to_i | |
end | |
rest = sum % 11 |
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 FalseClass | |
def ifTrue(blk, options) | |
options[:ifFalse].call | |
end | |
end | |
class TrueClass | |
def ifTrue(blk, options) | |
blk.call | |
end |
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="active" | |
<% | |
else | |
end | |
%> | |
> |
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
end | |
end | |
end | |
end | |
end | |
items << item | |
end | |
end | |
end | |
end |
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
# encoding: utf-8 | |
alias :"✎" :puts | |
class Person | |
attr_accessor :name | |
def initialize(a_name) | |
self.name = a_name | |
end | |
def ☺(someone) | |
✎ "#{self} loves #{someone}" | |
end |
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 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
class Gist | |
attr_accessor :gist_id, :title, :author | |
def self.find_all(author="zmalltalker") | |
result = [] | |
doc = Hpricot(open("http://gist.github.com/#{author}")) | |
(doc/"div.file").each do |file| | |
link = (file/"div.info/span/a").first |