Skip to content

Instantly share code, notes, and snippets.

public class Optimalstrategie : IStrategie
{
private List<Schnitt> _ausgangsgroessen;
private Schnittverteilung _best;
private ILaufzeitMonitor _monitor;
public Optimalstrategie(ILaufzeitMonitor monitor)
{
_monitor = monitor;
_best = null;
@battermann
battermann / PrimeGenerator.cs
Last active August 29, 2015 14:07
Prime Generator aus Agile Principles, Patterns and Practices in C# von Robert C. Martin refactored nach IOSP
///<remark>
/// Refactored Version (following IOSP)
///</remark>
using System;
using System.Collections.Generic;
using System.Linq;
namespace primegenerator
{
@battermann
battermann / CSharpToFSharpConverter.cs
Last active August 29, 2015 14:22
How to pass an argument to a F# function that takes ('a -> unit) from C#
using System;
using Microsoft.FSharp.Core;
namespace FSharpConverter
{
public static class ToFSharpFuncConverterExtensions
{
private static readonly Unit Unit = (Unit)Activator.CreateInstance(typeof(Unit), true);
public static Func<T, Unit> ToFunc<T>(this Action<T> action)
@battermann
battermann / FunctionCompositionExamples.cs
Created June 10, 2015 10:34
Function composition in C#
using System;
using System.Collections.Generic;
using NUnit.Framework;
using System.Linq;
namespace function_composition_in_csharp
{
// The NUnit Nuget package is required for this
// To install NUnit, run the following command in the Package Manager Console
// PM> Install-Package NUnit -Version 2.6.4
@battermann
battermann / App.xaml.cs
Last active December 8, 2018 00:11
Typesafe conversion of viewmodel property to observable stream
using System.Windows;
namespace PropertyToobsevable
{
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
var vm = new MainWindowViewModel();
var mainWindow = new MainWindow { DataContext = vm };
// The NUnit and Chessie Nuget packages are required for this
// To install NUnit and Chessie run the following commands from the Package Manager Console
// PM> Install-Package NUnit -Version 2.6.4
// PM> Install-Package Chessie
using System;
using System.Text.RegularExpressions;
using Chessie.ErrorHandling;
using Chessie.ErrorHandling.CSharp;
using Microsoft.FSharp.Core;

db scripts

CREATE TABLE [dbo].[UniqueIdentifier]
(
	[Typ] NVARCHAR(50) NOT NULL PRIMARY KEY,
	[CurrentMaxId] NVARCHAR(max) NOT NULL
)
@battermann
battermann / romNumParser.hs
Last active December 3, 2015 09:51
Parser for Roman Numerals
import Text.ParserCombinators.Parsec (char, many1, string, choice, try, parse)
import Text.Parsec.Prim (parserReturn, parserFail, ParsecT)
import Data.Functor
import Data.Functor.Identity
import Data.Either
import Test.Hspec
sat :: String -> (a -> Bool) -> ParsecT s u m a -> ParsecT s u m a
sat msg predicate parser = parser >>= (\x -> if predicate x then parserReturn x else parserFail msg)
@battermann
battermann / Game.fsx
Created February 19, 2016 11:14
Data-centric vs Function-centric Domain Design
open System
// -----------------------------------------------------------
// Domain
// -----------------------------------------------------------
module GameDomain =
type Dice = One | Two | Three | Four | Five | Six
@battermann
battermann / TicTacToe.cs
Last active March 10, 2016 12:01
Model for Tic-Tac-Toe
using System.Collections.Generic;
namespace TicTacToe
{
public enum Player
{
PlayerX,
PlayerO
}