Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am sillyotter on github.
  • I am sillyotter (https://keybase.io/sillyotter) on keybase.
  • I have a public key ASALxtcTSUduR1roTJW6rQxjJ6Ej2WQCUivWk6JjhvLkdAo

To claim this, I am signing this object:

let damerauLevenshteinDistance (a:string) (b:string) : float =
let cost i j =
if a.[i] = b.[j] then
0.0
else
1.0 // replace with querty distance?
// below not tail recursive, make it so. else it wont work well on large strings. probably be fine for names though
// most people implement this with an array,
@sillyotter
sillyotter / commandquerygenericagent.fs
Created December 1, 2015 16:14
fsharp generic command query agent
type Message<'S> =
| Query of ('S -> unit)
| Command of ('S -> 'S)
type CQAgent<'S>(state: 'S) =
let innerModel =
MailboxProcessor<Message<'S>>.Start(fun inbox ->
let rec messageLoop (state:'S) =
async {
let! msg = inbox.Receive()
@sillyotter
sillyotter / flipfancy.fsx
Created February 11, 2015 10:34
flip as point free
((<|) >> (>>) >> ((>>) (|>))) (sprintf "%s %s") "Original." "The";;
((>>) >> ((>>) (|>))) (sprintf "%s %s") "Much better." "A slightly neater flip.";;
@sillyotter
sillyotter / totp.fs
Last active August 29, 2015 14:14
TOTP
open System
open System.Security.Cryptography
open System.Text
open System.Threading
let base32alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" |> Encoding.ASCII.GetBytes
let valToChar (b : byte) = base32alphabet.[int (b)]
module Seq =
let groupsOfAtMost (size : int) =
open System.Data.SQLite
open Dapper
type Gender =
| Male = 1
| Female = 2
[<CLIMutable>]
type thingy =
{ Id : int
@sillyotter
sillyotter / Apply
Created June 17, 2014 19:45
Foreward Pipe Operator for C#
public static tB Apply<tA,tB>(this tA a, Func<tA,tB> f) { return f (a); }
@sillyotter
sillyotter / StateMachine.fs
Last active December 29, 2015 06:49
State Machine idea for F#
module StateMachine
type StateFunction<'a,'b> =
| StateFunction of ('a -> 'b -> (StateFunction<'a,'b> * 'b))
| Nothing
let private executeState (sf, context) token =
match sf with
| StateFunction(xf) -> xf token context
| Nothing -> Nothing,context