Skip to content

Instantly share code, notes, and snippets.

View CarstenKoenig's full-sized avatar

Carsten König CarstenKoenig

View GitHub Profile
### Keybase proof
I hereby claim:
* I am carstenkoenig on github.
* I am carstenkoenig (https://keybase.io/carstenkoenig) on keybase.
* I have a public key whose fingerprint is BB93 DA5D BF8A 3E50 2EF7 F595 E68E DE6B D673 43C5
To claim this, I am signing this object:
@CarstenKoenig
CarstenKoenig / transform.fs
Created June 11, 2014 04:27
incremental transform
let seqInnerJoin predicate seq1 seq2 =
let findPairs predicate seq2 element1 =
seq2
|> Seq.where (predicate element1)
|> Seq.map (fun element2 -> element1, element2)
seq1
|> Seq.map (findPairs predicate seq2)
|> Seq.collect (fun pair -> pair)
@CarstenKoenig
CarstenKoenig / WatMap.js
Last active August 29, 2015 14:02
WAT with .map and parseInt
// Die Frage war, warum
["1", "5"].map(parseInt);
// schief geht.
// Johannes hatte die Antwort, die ich nicht vertanden habe
// die Konsole hilft weiter:
var f = function() { console.log(arguments); }
["1", "5"].map(f)
> ["1", 0, Array[2]]
@CarstenKoenig
CarstenKoenig / Vigenere.hs
Last active August 29, 2015 14:02
simple Vigenere-cipher
module Vigenere where
import Data.Char
import Test.QuickCheck.Test (quickCheck)
encrypt :: String -> String -> String
encrypt key = zipWith (shiftChar (+)) (cycle key)
decrypt :: String -> String -> String
decrypt key = zipWith (shiftChar (flip (-))) (cycle key)
import Data.Maybe (fromJust)
import Data.List (sort)
rankList :: [Int] -> [Int]
rankList ns = map (fromJust . (flip lookup) ranks) ns
where ranks = zipWith (flip (,)) [1..] . sort $ ns
@CarstenKoenig
CarstenKoenig / Poker.hs
Created August 12, 2014 08:33
Poker hands kata
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import GHC.Exts (sortWith)
import Data.Function (on)
import Data.List (maximumBy, sortBy, nub, foldl')
import qualified Data.Map.Strict as M
@CarstenKoenig
CarstenKoenig / ApplicativeEventSourcing.fs
Last active August 29, 2015 14:05
applicative event-sourcing
namespace EventSourcing
module View =
/// the View's builder-type - includes bookkepping for intermediate types and should be hidden
/// from (poor) users view
type T<'e,'i,'a> = private { foldF : 'i -> 'e -> 'i; project : 'i -> 'a; init : 'i }
/// creates a view, based on a fold over intermediate values and a final projection
let createWithProjection (p : 'i -> 'a) (i : 'i) (f : 'i -> 'e -> 'i) =
@CarstenKoenig
CarstenKoenig / diag.hs
Last active August 29, 2015 14:05
diag indizes
diagInd :: [(Integer, Integer)]
diagInd = iterate f (1,1)
where f (lx,ly)
| ly == 1 = (1, lx+1)
| otherwise = (lx+1, ly-1)
@CarstenKoenig
CarstenKoenig / Notes.md
Created October 7, 2014 12:08
Markdown in Ubuntu installieren

Klonen von Github (inkl. Submodulen)

git clone https://github.com/mono/monodevelop.git
cd monodevelop
git submodule update --init --recursive

Das dauert eine Weile....

Konfigurieren

@CarstenKoenig
CarstenKoenig / asyncZip.fs
Created October 9, 2014 17:33
zip two asyncs
let zipAsync (a : Async<'a>) (b : Async<'b>) : Async<'a * 'b> =
async {
let! a' = Async.StartChild a
let! b' = Async.StartChild b
let! a'' = a'
let! b'' = b'
return (a'',b'')
}