Skip to content

Instantly share code, notes, and snippets.

type Agent =
| Async of MailboxProcessor<MailboxMessage>
| Sync of MailboxProcessor<MailboxMessage * AsyncReplyChannel<unit>>
let agent =
match mode with
| Default -> agent <- Async <| createDefaultAgent ()
| UnitTest -> agent <- Async <| createUnitTestAgent ()
let post msg =
@mexx
mexx / weirdTuple.fs
Created October 11, 2017 09:52
Weird tuple handling F#
open System
open System.Collections.Generic
let f (items: IEnumerable<Tuple<int, string>>) =
items
|> Seq.iter (fun i -> printf "%d %s" i.Item1 i.Item2)
let x = seq { yield Tuple.Create(10, "ten") }
f x
@mexx
mexx / GlobalResourceFileSystem.fs
Last active January 20, 2016 21:23
OWIN file system for `BuildAction = Resource` typed resouces
namespace Mexx.Owin
open System
open System.Collections.Generic
open System.IO
open System.Reflection
open System.Resources
open Microsoft.Owin.FileSystems
/// <summary>
@mexx
mexx / kata.fsx
Last active December 17, 2015 12:56 — forked from MarkXA/kata.fsx
Functional Kats Belfast kata 2015-12-16
(*
Consider a list of four points on a plane; the points have integral coordinates, and their order is irrelevant. The four points determine a square if the distances between them are all equal, and the lengths of the two diagonals are also equal. For instance, the following lists are all squares:
(0,0), (0,1), (1,1), (1,0) -- the unit square
(0,0), (2,1), (3,-1), (1, -2) -- square not aligned to axis
(0,0), (1,1), (0,1), (1,0) -- unit square, in different order
And the following lists do not represent squares:
(0,0), (0,2), (3,2), (3,0) -- rectangle
@mexx
mexx / app.ts
Last active September 8, 2016 15:53
Bind input type datetime-local in Angular 2.0.0-alpha.45
import {bootstrap, Component, FORM_DIRECTIVES} from 'angular2/angular2';
import {Hero} from './hero.ts';
import {DateValueAccessor} from './date_value_accessor.ts';
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>
<h5>{{hero.dateOfBirth}}</h5>
<div><label>id: </label>{{hero.id}}</div>
@mexx
mexx / gist:ac1ba83fc4fb7095b3a4
Last active August 29, 2015 14:16
Build test projects into per project folders under some give root
Target "BuildTests" (fun _ ->
trace "Building Tests..."
!! "tests/**/*.csproj"
|> Seq.collect (fun p -> MSBuildDebug (artifactsTestsDir @@ (Path.GetFileName(p))) "Build" [p])
|> Log "TestBuild-Output: "
)
@mexx
mexx / Code.fs
Created October 17, 2014 14:11
FSharpWorkshop
[<AutoOpen>]
module Code
type Quintuple<'t> = 't * 't * 't * 't * 't
module Seq =
let toQuintuple s =
match s with
| [a; b; c; d; e] -> (a, b, c, d, e)
| _ -> failwith "Ungültige Hand"
open Microsoft.Owin.Hosting
open Owin
open System
open System.Net
open System.Net.Http
open System.Web.Http
type HttpRouteDefaults = { Controller : string; Id : obj }
type HomeController() =
@mexx
mexx / LazyPartition.cs
Created September 10, 2014 11:47
Lazy partition
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Xunit;
namespace LazyPartition
{
public static class PartitionExtension
@mexx
mexx / mine.fs
Last active August 29, 2015 14:04 — forked from johnazariah/mine.fs
type Building = {
left : int
right : int
height : int
}
let buildings : Building[] = [| {left = 1; right = 10; height = 5}; {left = 1; right = 10; height = 5} |]
let getHeight building = building.height
let getWidth building = building.right - building.left