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"] |
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
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
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
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
-- compiles with ghc(i) 7.4.1 | |
import Data.Map (Map, empty, insertWith, toList) | |
import Data.List(groupBy, group, sortBy, sort) | |
{- To recap from the main article, we want to define "group_on" via "groupBy", so that its | |
type is something like (b -> b -> Bool) -> (a -> b) -> [a] -> [(b, [a])] | |
The method here is to work with a concrete example and gradually massage it | |
into the form we want - using the REPL |
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
-- word list is at https://gist.github.com/3799331 | |
import Data.Set(Set, fromDistinctAscList, member) | |
import System.IO.Unsafe(unsafePerformIO) | |
import Data.Tree | |
import Data.List(inits,tails) | |
-------------------- | |
-- first step - generating valid next words |
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
aahs | |
abbe | |
abbr | |
abed | |
abet | |
able | |
ably | |
abut | |
acct | |
aced |
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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE NoImplicitPrelude #-} | |
{-# LANGUAGE NoMonomorphismRestriction #-} | |
-- Example for December 2012 Prag Pub Magazine | |
-- expects Fay 0.10 | |
-- | |
-- Fay doesn't support type classes yet (hopefully soon) so this code contains | |
-- various workarounds and so is a bit more complex than it should be! |
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
-- see below for commentary | |
makeUpTo :: Int -> [String] -> [String] | |
makeUpTo n = mlu [] | |
where | |
mlu pre [] = [pre] | |
mlu [] (w:ws) = mlu w ws | |
mlu pre (w:ws) | length pre + 1 + length w <= n = mlu (pre ++ ' ' : w) ws | |
| otherwise = pre : mlu [] (w:ws) |
OlderNewer