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
infinity = 1.0/0 | |
savingsIncomeTax200910 = [(0, 6475), (0.1, 8915), (0.2, 43875), (0.4, infinity)] | |
incomeTax200910 = [(0, 6475), (0.2, 43875), (0.4, infinity)] | |
taxWithBands bands income | |
= if income <= threshold then | |
rate * income | |
else | |
rate * threshold + taxWithBands loweredRemainingBands remainingIncome | |
where |
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
# Drop me a line if you wanna see this as a proper merb plugin. | |
class Merb::Controller | |
ITEM_RANGE = /^items=(\d+)-(\d+)$/ | |
RANGE = /^(\d+)-(\d+)$/ | |
# Displays a collection resource (using Merb's display method) while supporting requests for sub-ranges of items in a RESTful fashion. | |
# This supports a subset of the HTTP/1.1 spec for content ranges, using a custom range unit 'items'. eg: | |
# GET /collection HTTP/1.1 | |
# Range: items 10-20 |
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
# This is a mixin for Test::Unit::TestCase, for providing tests with a simple facility to load fixtures from | |
# YAML files. It aims to do as much as possible in a generic way with the YAML library rather than couple | |
# tightly to a database library. | |
# | |
# Fixtures can use arbitrary YAML to represent ruby objects, using !ruby/object:Some::ClassName where needed. | |
# you will typically need to implement yaml_initialize on the relevant class, in order for this to | |
# work in the way you desire (we do so here for Sequel::Model; others including ActiveRecord shouldn't be hard) | |
# | |
# Data within one fixture can refer to other fixtures by file and name, using the syntax: !fixture file/name. | |
# this is achieved by adding a special YAML domain type. |
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 'set' | |
class EquivalenceRelation | |
def initialize | |
@equivalence_class_by_member = {} | |
end | |
def declare_equivalent(*items) | |
combined_equivalence_class = items.map {|item| equivalence_class_of(item)}.inject(Set.new) {|accum,set| accum.union(set)} | |
combined_equivalence_class.each {|member| @equivalence_class_by_member[member] = combined_equivalence_class} | |
end |
NewerOlder