Skip to content

Instantly share code, notes, and snippets.

View svdberg's full-sized avatar

Sander van den Berg svdberg

View GitHub Profile
-- | ToJSON and FromJSON instances for BSON Documents and Values
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, OverloadedStrings #-}
module Data.Bson.Json where
import qualified Data.Bson as B
import qualified Data.Aeson as J
import qualified Data.Attoparsec.Number as J (Number(..))
import qualified Data.Vector as V
@svdberg
svdberg / main.hs
Created June 26, 2012 13:49
Implementation of REST GET of feedings.
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules, NoMonomorphismRestriction #-}
import Database.MongoDB as M
import Control.Monad.Trans (liftIO)
import System.Locale
import Data.Time
import Data.Time.Format
import Data.Bson.Json
import Data.Aeson.Encode
import Data.Aeson
@svdberg
svdberg / 3nightclubs.scala
Created June 23, 2012 07:12 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
import Data.List.Split
import qualified Data.Map as Map
import Data.List.HT
buildCipher pw = Map.fromList $ zip [ (x,y) | x <- [0..4], y <- [0..4] ] (concat $ build pw)
where
build = chunk 5 . (`union` delete 'J' ['A'..'Z']) . nub . process --calculate the list of characters in the right order
process = replace "J" "I" . map toUpper . filter isLetter
import Data.List
import Data.List.Split
import Data.Char
import qualified Data.Map as Map
import Data.List.HT
type Password = String
type Direction = Int
--new implementation: change Cipher to Map
import Data.List
import Data.Char
import Data.List.HT
type Password = String
type Cipher = [String]
--this should take 5 letters at a time, removing earlier seen letters
--also we should add the remaining letters of the alphabet
createCipherSquare :: Password -> Cipher
(ns googlecodejam
[:use clojure.string])
(def example-input ["ejp mysljylc kd kxveddknmc re jsicpdrysi"
"rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"
"de kr kd eoya kw aej tysr re ujdr lkgc jv"])
(def google ["our language is impossible to understand"
"there are twenty six factorial possibilities"
"so it is okay if you want to just give up"])
@svdberg
svdberg / heapboom.clj
Created March 8, 2012 10:22
Blows the compiler heap, why?
(def pp
(λ [f xs]
(reduce ƒ(concat %1 (list (f %2))) '() xs)) )
@svdberg
svdberg / proptests.clj
Created March 1, 2012 16:10
Property resolver tests
(ns propertyresolver.test.core
(:use [propertyresolver.core])
(:use [clojure.test])
(:use midje.sweet))
;; "PropertyResolver resolve single reference"
(facts "replace should resolve a single reference"
(let [map-with-placeholder {:jndiname "${jndi.ref}" :jndi.ref "MyQueue"}]
(expand-placeholders map-with-placeholder map-with-placeholder) => {:jndi.ref "MyQueue" :jndiname "MyQueue"}))
@svdberg
svdberg / prop.clj
Created March 1, 2012 08:43
Clojure property resolver
(ns propertyresolver.core
(:refer-clojure :exclude [char])
( :require [ clojure.java.io])
( :use [the.parsatron]))
(defn load-properties [file-name]
(with-open [^java.io.Reader reader (clojure.java.io/reader file-name)]
(let [props (java.util.Properties.)]
(.load props reader)
(into {} (for [[k v] props] [(keyword k) v])))))