Skip to content

Instantly share code, notes, and snippets.

@adamchester
adamchester / twitter_clients_2014.fsx
Created January 3, 2015 03:31
F# Community Twitter Clients (2014)
#I @"packages/"
#r @"FSharp.Data/lib/net40/FSharp.Data.dll"
#load @"FSPlot\FsPlotBootstrap.fsx"
#r @"Deedle\lib\net40\Deedle.dll"
do fsi.AddPrinter(fun (printer:Deedle.Internal.IFsiFormattable) -> "\n" + (printer.Format()))
open FSharp.Data
type Tweets = CsvProvider<"fsharp_2013-2014.csv">
open System
type WeekOf<'T> = { Mo:'T; Tu:'T; We:'T; Th:'T; Fr:'T; Sa:'T; Su:'T }
with
static member FromDays (allDays: (DayOfWeek * 'T)[]) =
let dayFor theDay = snd (allDays |> Array.find (fun (day, data) -> day = theDay))
{ Mo = dayFor DayOfWeek.Monday
Tu = dayFor DayOfWeek.Tuesday
We = dayFor DayOfWeek.Wednesday
Th = dayFor DayOfWeek.Thursday
@adamchester
adamchester / states.fs
Last active July 4, 2018 00:25
Describing a state machine / approval workflow in F#
type State = Initial | Draft | PendingApproval | Approved | Cancelled | Completed
type Action = Create | Cancel | SendForApproval | Approve | Reject | Complete
type Role = Creator | Approver | Completor
type Transition = { Action:Action; From:State; To:State; Roles:Role list }
module Transitions =
let create = { Action=Create; From=Initial; To=Draft; Roles=[ Creator ] }
let cancel = { Action=Cancel; From=Draft; To=Cancelled; Roles=[ Creator ] }
let sendForAppr = { Action=SendForApproval; From=Draft; To=PendingApproval; Roles=[ Creator ] }
let approve = { Action=Approve; From=PendingApproval; To=Approved; Roles=[ Approver ] }
let reject = { Action=Reject; From=PendingApproval; To=Draft; Roles=[ Approver ] }
@adamchester
adamchester / generate.fsx
Last active March 13, 2016 09:01
Generate a Visual Studio DGML Graph from F#
[<AutoOpen>]
module Workflow =
type State = Initial | Draft | PendingApproval | Approved | Cancelled | Completed
type Action = Create | Cancel | SendForApproval | Approve | Reject | Complete
type Role = Creator | Approver | Completor
type Transition = { Action:Action; From:State; To:State; Roles:Role list }
module Transitions =
let create = { Action=Create; From=Initial; To=Draft; Roles=[ Creator ] }
let cancel = { Action=Cancel; From=Draft; To=Cancelled; Roles=[ Creator ] }
let sendForAppr = { Action=SendForApproval; From=Draft; To=PendingApproval; Roles=[ Creator ] }
@adamchester
adamchester / keybase.md
Created May 27, 2015 04:41
keybase proof

Keybase proof

I hereby claim:

  • I am adamchester on github.
  • I am adamchester (https://keybase.io/adamchester) on keybase.
  • I have a public key whose fingerprint is 6573 51C0 41D2 58D2 9BE8 83F1 835B 3087 94D3 EC6F

To claim this, I am signing this object:

@adamchester
adamchester / suaveSerilog.fsx
Created June 8, 2015 11:15
A simple Suave to Serilog adapter
// Step 0. Boilerplate to get the paket.exe tool
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
let url = "https://github.com/fsprojects/Paket/releases/download/0.31.5/paket.exe"
use wc = new Net.WebClient()
let tmp = Path.GetTempFileName()
@adamchester
adamchester / NoSpecPerf.fs
Created December 28, 2015 06:50
AutoFixture NoSpecimen Perf (Singleton vs. new Instance)
#r "./bin/NoSpecimenNewInst/lib/net40/Ploeh.AutoFixture.dll"
printfn "%A" typeof<Ploeh.AutoFixture.Fixture>.AssemblyQualifiedName
let createWithNoSpecNewInst<'T> =
let fixture = Ploeh.AutoFixture.Fixture()
fun () -> fixture.Create(typeof<'T>, Ploeh.AutoFixture.Kernel.SpecimenContext(fixture)) :?> 'T
#r "./bin/NoSpecimenSingleton/lib/net40/Ploeh.AutoFixture.dll"
printfn "%A" typeof<Ploeh.AutoFixture.Fixture>.AssemblyQualifiedName
let noSpecimenSingleton = typeof<Ploeh.AutoFixture.Kernel.NoSpecimen>
@adamchester
adamchester / NoSpec-report-github.md
Last active February 20, 2016 02:34
AutoFixture NoSpecimen Benchmark: NewInst vs. Singleton
BenchmarkDotNet-Dev=v0.9.1.0+
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz, ProcessorCount=8
Frequency=10000000 ticks, Resolution=100.0000 ns, Timer=HPET
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
JitModules=clrjit-v4.6.1063.1

Type=NoSpec  Mode=Throughput  Platform=AnyCpu  
Framework=V45 TargetCount=10 
@adamchester
adamchester / netstandard.fs
Last active April 24, 2016 06:07
How .NET Standard relates to .NET Platforms (in F#)
// Converted to F# from https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7
module Analogy =
type ASetOfApis = unit -> unit
// Each interface represents a target framework and methods represents groups of APIs available on that target framework.
// The goal is to show the relationship between .NET Standard API surface and other .NET platforms
// .NET Standard
@adamchester
adamchester / netstandard.fs
Created April 24, 2016 01:21
How .NET Standard relates to .NET Platforms (in F# functions)
type ASetOfApis = unit->unit
module ApiSets =
type Primatives = ASetOfApis
type Reflection = ASetOfApis
type Tasks = ASetOfApis
type Collections = ASetOfApis
type Linq = ASetOfApis
type ConcurrentCollections = ASetOfApis