Skip to content

Instantly share code, notes, and snippets.

module Git =
open System
open System.Diagnostics
let private runCommand cmd args =
let startInfo = new ProcessStartInfo()
startInfo.FileName <- cmd
startInfo.Arguments <- args
startInfo.UseShellExecute <- false
startInfo.RedirectStandardOutput <- true
@battermann
battermann / ConditionalsExtensions.cs
Last active November 1, 2016 21:56
CondictionalsExtensions
public static class CondictionalsExtensions
{
public static Tuple<bool, T> If<T>(this T src, Predicate<T> p)
{
return p(src)
? Tuple.Create(true, src)
: Tuple.Create(false, src);
}
public static Tuple<bool, T, R> Then<T, R>(this Tuple<bool, T> src, Func<T, R> f)
@battermann
battermann / QuickSort.cs
Created April 15, 2016 22:16
Recursive implementation of QuickSort in C#. It's really slow and absolutely not recommended to use it!! It's only meant for demonstration purposes.
static class Program
{
static void Main(string[] args)
{
var list = new List<int> {4, 5, 4, 7, 9, 1, 6, 1, 0, -99, 10000, 3, 2};
var sorted = list.QuickSort();
Console.WriteLine(String.Join(", ", sorted));
// output: -99, 0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 9, 10000
@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
}
@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 / 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)

db scripts

CREATE TABLE [dbo].[UniqueIdentifier]
(
	[Typ] NVARCHAR(50) NOT NULL PRIMARY KEY,
	[CurrentMaxId] NVARCHAR(max) NOT NULL
)
// 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;
@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 };
@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