Skip to content

Instantly share code, notes, and snippets.

View davidglassborow's full-sized avatar

David Glassborow davidglassborow

View GitHub Profile
@davidglassborow
davidglassborow / README.md
Created May 1, 2019 19:32 — forked from mrange/README.md
[F#/OCaml] Implementing a data streams library using a bunch of one-liners

[F#/OCaml] Implementing a data streams library using a bunch of one-liners

A few years ago when I read the presentation motivating the design behind Nessos Streams I was struck by the beauty of simplistic push streams.

type PushStream<'T> = ('T -> bool) -> bool

LINQ (in .NET) is a pull stream, ie we pull values out of the stream by calling MoveNext + Current. One of the problems with pull streams is the constant checking "Are we done?" at each level in the stream.

// This is am example of an immediate write / random access cursor for Excel with basic formatting options.
// Implementation is based on a concrete, non generic writer monad with no payload ("do!"" only) (only state).
// Instead of directl writing to excel, an alternatives would be a random acces to a
// copy-on-write list (or even a mutable array) and then bulk-write the result to excel in one shot.
// When only forward access would have been required, a simple seq expression with yields would have been enough.
// Anyway, it is a demonstration on how to "hide" pseudo-mutable state that is passed through a computation.
//
// I personally use it for generating reports based on various data sources.
@davidglassborow
davidglassborow / App.fs
Created January 30, 2019 17:24 — forked from mathias-brandewinder/App.fs
Lorentz attractor in Fable-Elmish
(*
Simulation of the Lorentz attractor, using Fable.
If you want to see this code in action, just copy this code into the Fable REPL:
https://fable.io/repl/
*)
module App
open Elmish
open Elmish.React
@davidglassborow
davidglassborow / HttpClient.cs
Created January 18, 2019 18:02 — forked from marekstachura/HttpClient.cs
C# http long polling example
var url = "http://localhost:8082/consumers/my_binary_consumer/instances/my_instance/topics/test";
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
var request = new HttpRequestMessage(HttpMethod.Get, url);
using (var response = await client.SendAsync(
request,
HttpCompletionOption.ResponseHeadersRead))
@davidglassborow
davidglassborow / zebra4.fs
Last active December 13, 2018 14:53 — forked from dungpa/zebra4.fs
The whole solution for Zebra Puzzle using SolverFoundation
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.Solver.Foundation.dll"
module ZebraPuzzle =
open System
open Microsoft.SolverFoundation.Services
let solve() =
let context = SolverContext.GetContext()
let rootModel = context.CreateModel()
let person = rootModel.CreateSubModel("Person")
@davidglassborow
davidglassborow / free.fs
Created December 5, 2018 12:50 — forked from johnazariah/free.fs
Free Monad with Trampoline Infrastructure and Computation Builder
// F<'a> is any type with member 'map' of type ('a -> 'b) -> F<'a> -> F<'b>
type F<'a> = QIL<'a>
and S<'a> = F<Q<'a>>
and Q<'a> =
private
| Step of Step<'a>
| Bind of IBind<'a>
with
static member lift (k : F<'a>) : Q<'a> = Step (Suspend (fun () -> S<_>.map (Yield >> Step) k))
@davidglassborow
davidglassborow / Windows Defender Exclusions VS 2017.ps1
Last active November 29, 2018 16:33 — forked from dknoodle/Windows Defender Exclusions VS 2017.ps1
Adds Windows Defender exclusions for Visual Studio 2017
$userPath = $env:USERPROFILE
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null
$pathExclusions.Add('C:\Windows\assembly') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio\Packages') > $null
$pathExclusions.Add('C:\Program Files (x86)\MSBuild') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio 14.0') > $null
@davidglassborow
davidglassborow / tutorial.md
Created July 19, 2018 11:11 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

@davidglassborow
davidglassborow / Async.Timeout.fs
Created June 28, 2018 12:26 — forked from eulerfx/Async.Timeout.fs
F# Async Timeout
let timeoutNone (timeoutMs:int) (a:Async<'a>) : Async<'a option> = async {
let! ct = Async.CancellationToken
let res = TaskCompletionSource<_>()
use cts = CancellationTokenSource.CreateLinkedTokenSource ct
res.Task.ContinueWith (fun _ -> cts.Cancel ()) |> ignore
use timer = new Timer((fun _ -> res.TrySetResult None |> ignore), null, timeoutMs, Timeout.Infinite)
Async.StartThreadPoolWithContinuations (
a,
(fun a -> res.TrySetResult (Some a) |> ignore),
(fun e -> res.TrySetException e |> ignore),
let ParallelThrottledIgnore (startOnCallingThread:bool) (parallelism:int) (xs:seq<Async<_>>) = async {
let! ct = Async.CancellationToken
let sm = new SemaphoreSlim(parallelism)
let count = ref 1
let res = TaskCompletionSource<_>()
let tryWait () =
try sm.Wait () ; true
with _ -> false
let tryComplete () =
if Interlocked.Decrement count = 0 then