Skip to content

Instantly share code, notes, and snippets.

View CarstenKoenig's full-sized avatar

Carsten König CarstenKoenig

View GitHub Profile
@CarstenKoenig
CarstenKoenig / DisOpt_ColoringSkeleton.hs
Created March 10, 2014 12:52
Skeleton file for the graph coloring assignment
module Main where
import Data.List (intercalate)
import Control.Applicative((<$>))
import Control.Monad(forM)
import System.Environment(getArgs)
import System.IO (withFile, hGetLine, IOMode(ReadMode))
newtype Edge = Edge (Int, Int)
deriving Show
@CarstenKoenig
CarstenKoenig / gist:9690331
Created March 21, 2014 16:39
error starting mono
INFO [2014-03-21 17:38:19Z]: Starting MonoDevelop 4.2.3
INFO [2014-03-21 17:38:19Z]: Running on Mono 3.0.6 (tarball Sat Sep 28 04:42:52 UTC 2013) (64-bit)
INFO [2014-03-21 17:38:19Z]: Using GTK+ 2.24.22
INFO [2014-03-21 17:38:20Z]: Add-in loaded: MonoDevelop.Core
INFO [2014-03-21 17:38:20Z]: Add-in loaded: MonoDevelop.Ide
WARNING [2014-03-21 17:38:20Z]: No proxy credential provider was found
INFO [2014-03-21 17:38:20Z]: Initializing Runtime Mono 3.0.6
INFO [2014-03-21 17:38:20Z]: Add-in loaded: MonoDevelop.Debugger
INFO [2014-03-21 17:38:20Z]: Add-in loaded: MonoDevelop.SourceEditor2
INFO [2014-03-21 17:38:20Z]: Add-in loaded: MonoDevelop.VersionControl
@CarstenKoenig
CarstenKoenig / gist:9756074
Created March 25, 2014 06:12
Help for a G+er
{-# LANGUAGE BangPatterns #-}
piCalc :: Int -> Float
piCalc iterations = step * loop 0 iterations
where step = 1.0 / fromIntegral iterations
loop a i =
if i == 0 then a
else
let x = (fromIntegral i - 0.5) * step
!a' = a + (4.0 / (1.0 + x*x))
### 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) =