Skip to content

Instantly share code, notes, and snippets.

View CarstenKoenig's full-sized avatar

Carsten König CarstenKoenig

View GitHub Profile
@CarstenKoenig
CarstenKoenig / FayBrot.hs
Created December 19, 2012 10:23
very simple mandelbrot-set drawing using js / canvas - performance ok in Firefox + noobish version using my first steps in Fay - very poor performance + added version with funscript/F# - performance ... well not as bad as Fay but still a lot slower than the native
-- | Simple Mandelbrot-drawing into a Canvas using Fay
--
-- Compile with
-- $ fay -p FayBrot.hs
{-# OPTIONS -fno-warn-orphans -fno-warn-type-defaults -fno-warn-unused-do-bind #-}
{-# LANGUAGE EmptyDataDecls #-}
module FayBrot (main) where
@CarstenKoenig
CarstenKoenig / Observable.fs
Created June 4, 2013 05:54
the changed AwaitObservable method
/// Creates an asynchronous workflow that will be resumed when the
/// specified observables produces a value. The workflow will return
/// the value produced by the observable.
static member AwaitObservable(observable : IObservable<'T1>) =
let removeObj : IDisposable option ref = ref None
let removeLock = new obj()
let setRemover r =
lock removeLock (fun () -> removeObj := Some r)
let remove() =
lock removeLock (fun () ->
@CarstenKoenig
CarstenKoenig / Aggregate.cs
Created June 5, 2013 14:09
Fragen bezüglich Aggregate.cs
protected void ApplyChanges<T>(T changeEvent) where T : class
{
var id = IdFrom((dynamic)changeEvent);
if (id == Guid.Empty)
{
try { id = Id; }
catch (NullReferenceException)
{
throw new ArgumentException(
@CarstenKoenig
CarstenKoenig / Option.cs
Created June 27, 2013 05:47
typisches Beispiel eines Option-Typs in C#
public delegate bool TryFunc<in tIn, tOut>(tIn input, out tOut output);
public static class Option
{
public static Option<tType> None<tType>()
{
return Option<tType>.None;
}
public static Option<tType> Some<tType>(this tType value)
@CarstenKoenig
CarstenKoenig / Vec.hs
Last active December 19, 2015 16:19
Vec.hs
-- basic implementation of a vector type
-- modeled after the Vec type from Courseras "Coding the Matrix" class
-- | implementation of a sparse-vector representation based on the
-- Courseras "Coding the Matrix" MOOC class
-- this is in no way optimized and is just indended for learning
module Vec where
-- *** I worked with these imports ... you might want others (or not)
@CarstenKoenig
CarstenKoenig / lightsOut.py
Last active December 19, 2015 19:28
ligths Out for "Coding the Matrix: Linear Algebra through Computer Science Applications" You need pygame to run this and you have to place this file inside your matrix-folder (where it can find GF2.py and your vec.py) Then you can run it with "python3 ligthOut.py" Mouseclick will switch the ligth according to the rules of the game To exit click …
import pygame
import random
import math
from vec import Vec
from GF2 import *
pygame.init()
screen_width = 600

Beschreibung der Kata

Ziel dieser Kata ist es ein Programm zu schreiben, dass Wechselgeld berechnet. Dazu wird dem Programm eine Liste mit Münz-Werte (zum Beispiel [1, 2, 5, 10, 20, 50, 100, 200] für unsere üblichen EUR-Münzen) und der zu wechselnde Betrag übergeben. Das Programm soll darauf hin eine Liste von Anzahl/Münzwert-Paaren ausgeben, so dass der Betrag korrekt gewechselt wird und die Gesamtzahl der herausgegebenen Münzen minimiert wird.

Beispiel

Es soll 2,53 EUR gewechselt werden. Sowohl "1x2EUR, 1x50ct und 1x2ct, 1x1ct" als auch "2x1EUR, 2x20ct, 1x10ct, 3x1ct" würden den Betrag korrekt wechseln, aber die erste Möglichkeit gibt 4 Münzen zurück, während die Alternative 8 Münzen ausgeben würde. Das Programm soll in diesem Fall die erste Alternative zurückgeben (da diese hier die Optimallösung darstellt).

sei "greedy"...

@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))