This file contains 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 Valid a where | |
valid :: a -> OkF Errors | |
class Valid a => Persist m a where | |
save :: a -> m (OkF a) -- or errors | |
data User = User {name :: String} | |
data Organisation = Organisation {name :: String, users :: [User]} |
This file contains 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 Configuration | |
attr_accessor :tail_logs, :max_connections, :admin_password | |
class AppServerConfig | |
attr_accessor :port, :admin_password | |
end | |
def app_server | |
yield(@app_server ||= AppServerConfig.new) if block_given? | |
@app_server |
This file contains 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
def counter(s = 0, i = 1) | |
c = s | |
lambda { o = c; c += i; o } | |
end | |
x = counter(10,2) | |
4.times { puts x.call } | |
y = counter(2,3) | |
6.times { puts y.call } |
This file contains 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
# by Paul Callaghan, Nov 2010. | |
# this uses method-missing to trigger generation and execution of the corresponding relation | |
# eg Product.name_equals("yay") | |
# TODO: M_S doesn't check for unexpected values, eg match failures in | |
# matches_attribute_method (so we trap exceptions) | |
module MetaSearchHacks | |
def self.build_rel(base_or_scope, method, *args) |
This file contains 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 "csv" | |
require 'action_controller/test_process' | |
file = `ls upload/*.csv | grep -v and-r`.chomp | |
info = CSV.read(ARGV.first || file) | |
info.shift | |
# TODO: set this list by eliminating the expected cols | |
properties = %w[Colour Material Size Weight Warranty] + ["Pole Diameter", "Fits Pole Size"] |
NewerOlder