Skip to content

Instantly share code, notes, and snippets.

View kjnilsson's full-sized avatar

Karl Nilsson kjnilsson

View GitHub Profile
@kjnilsson
kjnilsson / gist:300a7693f401ca104512
Created May 8, 2014 10:58
Delegating handler to capture request processing times
type TimingHandler() =
inherit DelegatingHandler ()
let cont (sw : Stopwatch) (t: Task<HttpResponseMessage>) =
sw.Stop()
debug "request time: %i" sw.ElapsedMilliseconds
t.Result // dont like this
override this.SendAsync (request, token) =
let sw = new Stopwatch()
Found 1 unique roots (run '!GCRoot -all' to see all roots).
0:000> !gcroot 161f97f0
HandleTable:
044f4788 (strong handle)
-> 161f9b64 System.Threading._ThreadPoolWaitOrTimerCallback
-> 161f9b1c System.Threading.WaitOrTimerCallback
-> 161f9af8 <StartupCode$FSharp-Core>.$Control+AwaitWaitHandle@1624-2
-> 161f9a80 Microsoft.FSharp.Control.AsyncBuilderImpl+args@797-1[[System.Boolean, mscorlib],[Microsoft.FSharp.Core.FSharpOption`1[[Riemann.Proto.Event, Riemann]], FSharp.Core]]
-> 161f9a60 Microsoft.FSharp.Control.AsyncParams`1[[Microsoft.FSharp.Core.FSharpOption`1[[Riemann.Proto.Event, Riemann]], FSharp.Core]]
type IdGenerator () =
let agent = MailboxProcessor<AsyncReplyChannel<int>>.Start(fun inbox ->
let rec loop c = async {
let! rc = inbox.Receive ()
rc.Reply (c + 1)
return! loop (c + 1) }
loop 0)
member this.Next () =
agent.PostAndReply(fun rc -> rc)
@kjnilsson
kjnilsson / gist:52e2c862077dd77a8e86
Created September 3, 2014 08:38
fsautocomplete fsharp-vim log
> parse "/Users/karlnilsson/code/fs/test.fs" full
> module Test =
>
> let tryX () =
> Map.
> <<EOF>>
< INFO: Background parsing started
complete: base =
> completion "/Users/karlnilsson/code/fs/test.fs" 4 12
< DATA: errors
@kjnilsson
kjnilsson / gist:93cf2e695fd198e8692c
Created September 19, 2014 10:54
riemann-dash error when saving
[2014-09-19 03:44:25] INFO WEBrick 1.3.1
[2014-09-19 03:44:25] INFO ruby 1.9.3 (2011-10-30) [x86_64-linux]
== Sinatra/1.4.5 has taken the stage on 8080 for development with backup from WEBrick
[2014-09-19 03:44:25] INFO WEBrick::HTTPServer#start: pid=8251 port=8080
NoMethodError - undefined method `[]' for nil:NilClass:
/var/lib/gems/1.9.1/gems/riemann-dash-0.2.9/lib/riemann/dash/browser_config.rb:62:in `merge_configs'
/var/lib/gems/1.9.1/gems/riemann-dash-0.2.9/lib/riemann/dash/browser_config/file.rb:26:in `update'
/var/lib/gems/1.9.1/gems/riemann-dash-0.2.9/lib/riemann/dash/browser_config.rb:70:in `update'
/var/lib/gems/1.9.1/gems/riemann-dash-0.2.9/lib/riemann/dash/controller/index.rb:14:in `block in <class:App>'
/var/lib/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'
@kjnilsson
kjnilsson / asynchow
Last active August 29, 2015 14:08
How do I make this properly async?
type ContentLengthHandler() =
inherit DelegatingHandler ()
override __.SendAsync (request, token) =
let resp = base.SendAsync(request, token).Result //GAH
match resp.Content with
| :? ObjectContent as oc ->
let s = oc.ReadAsStreamAsync().Result //GAH
resp.Content <- new StreamContent(s)
resp.Content.Headers.ContentLength <- Nullable (int64 s.Length)
Task.FromResult resp
@kjnilsson
kjnilsson / gist:8c8e4c86fc5ea316c3e0
Last active August 29, 2015 14:09
FsCheck problem/query
#r "./bin/Debug/FsCheck.dll"
open System
open FsCheck
//ensure fscheck is fully initialised.
Runner.init.Force()
let whiteList =
let x = ['a' .. 'z'] @ ['A' .. 'Z']
Gen.choose (0, x.Length - 1)
|> Gen.map (fun i -> x.[i])
@kjnilsson
kjnilsson / gist:d9c8fc813e047936c8ab
Created December 18, 2014 13:21
influxdb error log when writing to docker mounted directory
[2014/12/18 13:03:09 UTC] [INFO] (github.com/influxdb/influxdb/cluster.(*ClusterConfiguration).GetShardToWriteToBySeriesAndTime:834) No matching shards for write at time 1418907789187110u, creating...
[2014/12/18 13:03:09 UTC] [INFO] (github.com/influxdb/influxdb/cluster.(*ClusterConfiguration).createShards:865) createShards for space default: start: Thu Dec 18 00:00:00 +0000 UTC 2014. end: Thu Dec 25 00:00:00 +0000 UTC 2014
[2014/12/18 13:03:09 UTC] [INFO] (github.com/influxdb/influxdb/datastore.(*ShardDatastore).GetOrCreateShard:158) DATASTORE: opening or creating shard /mnt/data/db/shard_db_v2/00005
[2014/12/18 13:03:09 UTC] [EROR] (github.com/influxdb/influxdb/cluster.(*ClusterConfiguration).AddShards:1075) AddShards: error setting local store: %!(EXTRA rocksdb.DatabaseError=IO error: directory: Invalid argument)
[2014/12/18 13:03:09 UTC] [EROR] (github.com/influxdb/influxdb/coordinator.(*RaftServer).doOrProxyCommandOnce:168) Cannot run command &coordinator.CreateShardsCommand{Shards:[]*cluster.NewShardDa
@kjnilsson
kjnilsson / gist:c330928d1eab9138e489
Created December 19, 2014 11:48
mono segfault backtrace
(gdb) run FifteenBelow.VersionedStorage.Service.exe
Starting program: /usr/bin/mono FifteenBelow.VersionedStorage.Service.exe
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff4d1c700 (LWP 24667)]
[New Thread 0x7ffff45ff700 (LWP 24668)]
[New Thread 0x7ffff45be700 (LWP 24669)]
Configuration Result:
[Success] Name FifteenBelow.VersionedStorage.Service
[Success] DisplayName FifteenBelow Versioned Storage Service
@kjnilsson
kjnilsson / gist:e40f1d9fc8fb89829ac3
Created December 19, 2014 12:07
mono SIGSEGV gdp outpout
dev@ubuntu:~/vs$ sudo ./run.sh
Configuration Result:
[Success] Name FifteenBelow.VersionedStorage.Service
[Success] DisplayName FifteenBelow Versioned Storage Service
[Success] Description Provides a versioned store
[Success] ServiceName FifteenBelow.VersionedStorage.Service
Topshelf v3.1.122.0, .NET Framework v4.0.30319.17020
The FifteenBelow.VersionedStorage.Service service is now running, press Control+C to exit.
System.UInt16[] doesn't implement interface System.IDisposable