Skip to content

Instantly share code, notes, and snippets.

View kjnilsson's full-sized avatar

Karl Nilsson kjnilsson

View GitHub Profile
type CodeListElement = CodeListElement of int * string
using(var pub = new ChangeReceiver("tcp://*:5555"))
{
Console.WriteLine("Listening...");
var staffSender = new NotificationSender("tcp://localhost:5556");
var customerSender = new NotificationSender("tcp://localhost:5557");
var obs = Observable.FromEventPattern<Tuple<Guid, string>>(pub, "ChangeRecieved").Select(ep => ep.EventArgs);
obs.GroupBy(x => x.Item2)
let countChar (c:char) (s:string) =
let mutable length = s.Length
let mutable k = 0
while (length <- length - 1; length >= 0) do
if s.[length] = c then k <- k + 1
k
@kjnilsson
kjnilsson / gist:d22beedd080aeee141f0
Last active August 29, 2015 14:15
FSharp recursive async fuction [Non leaking] + Closure representation
[<EntryPoint>]
let main argv =
let rec loop () = async {
do! Async.Sleep 10
return! loop () }
Async.Start <| loop ()
System.Console.ReadLine() |> ignore
0
(* compled representations of loop
@kjnilsson
kjnilsson / gist:f447395871cf36bc547c
Last active August 29, 2015 14:15
FSharp recursive async fuction [Leaking] + Closure representation
[<EntryPoint>]
let main argv =
let rec loop () = async {
do! Async.Sleep 10
return! loop ()
return! loop () }
Async.Start <| loop ()
System.Console.ReadLine() |> ignore
0
@kjnilsson
kjnilsson / gist:35c946e71c4ff2104674
Created February 23, 2015 11:12
FSharp recursive async function [Leaking likely scenario] + Closure representation
open System
[<EntryPoint>]
let main argv =
let create wait =
let agent = new MailboxProcessor<_>(fun inbox ->
let rec loop () = async {
let! msg = inbox.TryReceive wait
match msg with
| Some _ ->
() //no return
@kjnilsson
kjnilsson / gist:ab87d836a2102bfca6e8
Created March 19, 2015 12:27
libgit2sharp push repro
#r "libgit2sharp/Build/LibGit2Sharp.dll"
open System
open System.IO
open LibGit2Sharp
let stores = (Path.GetTempPath() + "local") |> Directory.CreateDirectory
let remote = (Path.GetTempPath() + "remote") |> Directory.CreateDirectory
let repoName = string (Guid.NewGuid())
let first = (remote.FullName + "//" + repoName) |> Directory.CreateDirectory
@kjnilsson
kjnilsson / gist:f455107d1c5086d87a11
Created April 13, 2015 12:54
riemann - exclude by tag
(expired
(where* (fn [e] (not (tagged-any? ["iis"] e)))
...))
@kjnilsson
kjnilsson / gist:77f3102321a525a83878
Created July 8, 2015 12:02
fluent-plugin-riemann
2015-07-08 12:56:01 +0100 [warn]: temporarily failed to flush the buffer. next_retry=2015-07-08 12:57:09 +0100 error_class="NoMethodError" error="undefined method `&' for 1436356479.1659427:Float" instance=70010588238460
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/lib/beefcake/buffer/encode.rb:86:in `append_uint64'
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/lib/beefcake/buffer/encode.rb:61:in `append_int64'
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/lib/beefcake/buffer/encode.rb:13:in `append'
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/lib/beefcake.rb:102:in `block in encode!'
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/lib/beefcake.rb:90:in `each'
2015-07-08 12:56:01 +0100 [warn]: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/beefcake-0.5.0/li
@kjnilsson
kjnilsson / handy.fs
Last active April 6, 2018 17:49
my current favourite handy fsharp helpers
//invaluable for all those Choice<'a, exn> flows
let exnf f = Printf.ksprintf (fun s -> exn s) f
//combine paths
let (</>) x y = System.IO.Path.Combine(x, y)
//allows you to pattern match on values in the current scope rather than just literals
let (|Eq|_|) expected value =
if expected = value then Some ()
else None