Skip to content

Instantly share code, notes, and snippets.

View JefClaes's full-sized avatar

Jef Claes JefClaes

View GitHub Profile
@JefClaes
JefClaes / gist:c25e90d01b5a376e4e0a
Last active April 26, 2017 20:56
Force create LocalDB database
using (var conn = new SqlConnection(@"Data Source=(LocalDb)\v11.0;Initial Catalog=Master;Integrated Security=True"))
{
conn.Open();
var cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = string.Format(@"
IF EXISTS(SELECT * FROM sys.databases WHERE name='{0}')
BEGIN
ALTER DATABASE [{0}]
@JefClaes
JefClaes / gist:1c53c3ab0e5bc19438f8
Created November 16, 2014 12:06
streamIsHot test
[<Test>]
member this.``Given a hot aggregate, a hot aggregate will be detected``() =
let treshold = 4
let secondsInWindow = 5
let eventStream = createEventStream [0; 1; 2; 10; 11; 12; 13; 14; 60; 90]
streamIsHot eventStream treshold secondsInWindow |> should equal true
@JefClaes
JefClaes / gist:b482f8b6021f70153b7a
Created November 16, 2014 12:08
streamIsHot function
let streamIsHot (events : seq<Event>) treshold secondsInWindow =
let folder acc e =
let detect acc e =
let windowFilter = (fun x -> x >= e.Timestamp.AddSeconds(- float secondsInWindow))
let window = e.Timestamp :: acc.Window |> List.filter windowFilter
let hot = (window |> Seq.length) > treshold
{ acc with Hot = hot; Window = window }
match acc.Hot with
| true -> acc
@JefClaes
JefClaes / gist:c73e95f4715f1568b3d3
Last active August 29, 2015 14:10
Spinning the wheel in F# (1)
type PocketLabel = Miss | Win
type Pocket = { Label : PocketLabel }
type PhysicalWheel = Pocket seq
@JefClaes
JefClaes / gist:af76848299db8451489d
Last active August 29, 2015 14:10
Spinning the wheel in F# (2)
let (physicalWheel : PhysicalWheel) =
[
{ Label = Miss };
{ Label = Miss };
{ Label = Win };
{ Label = Miss }
] |> Seq.ofList
@JefClaes
JefClaes / gist:05018f831afed3987ec0
Last active August 29, 2015 14:10
Spinnin the wheel in F# (3)
let rng = new Random()
let randomIndex (rng : Random) physicalWheel =
rng.Next(0, physicalWheel |> Seq.length)
let spin physicalWheel rng =
physicalWheel |> Seq.nth (randomIndex rng physicalWheel)
@JefClaes
JefClaes / gist:09a10b8503ea2d8a8f8b
Last active August 29, 2015 14:10
Spinning the wheel in F# (4)
let spin physicalWheel rng times =
[1 .. times] |> List.map (fun x -> spin physicalWheel rng)
@JefClaes
JefClaes / gist:d4495dd612bbb72f1238
Created December 7, 2014 12:52
Spinning the wheel in F# (5)
let results = spin physicalWheel rng 1000000
@JefClaes
JefClaes / gist:301b352f0dc8f13a3bf3
Created December 7, 2014 12:54
Spinning the wheel in F# (6)
let groupedResults =
results
|> Seq.groupBy (fun x -> x.Label)
|> Seq.map (fun (x, y) -> (x, (y |> Seq.length)))
printfn "%A" groupedResults
@JefClaes
JefClaes / gist:196ce06e21f52f25369c
Created December 7, 2014 12:55
Spinnig the wheel in F# (7)
seq [(Miss, 750505); (Win, 249495)]