Skip to content

Instantly share code, notes, and snippets.

View davidglassborow's full-sized avatar

David Glassborow davidglassborow

View GitHub Profile
@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 / 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")
open System
let dispose x = (x :> IDisposable).Dispose()
module Workflow =
/// Represents what we will tell the Twilio phone system to do
type PhoneCommand =
/// Connect the caller to a given phone queue
| ConnectToQueue of queueName:string
@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 / 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
// 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 / 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.

@davidglassborow
davidglassborow / engine.c
Created August 18, 2019 18:52 — forked from druska/engine.c
Quant Cup 1's winning order book implementation
/*****************************************************************************
* QuantCup 1: Price-Time Matching Engine
*
* Submitted by: voyager
*
* Design Overview:
* In this implementation, the limit order book is represented using
* a flat linear array (pricePoints), indexed by the numeric price value.
* Each entry in this array corresponds to a specific price point and holds
* an instance of struct pricePoint. This data structure maintains a list
@davidglassborow
davidglassborow / nested_ce.fs
Created January 20, 2020 15:43 — forked from Szer/nested_ce.fs
Nested CE
type ThirdLevel =
| Payload of int
and SecondLevel =
| Nested of ThirdLevel list
| Payload of string
and FirstLevel =
| Nested of SecondLevel list
| Payload of double
| EmptyLine
and AllBuilder() =
@davidglassborow
davidglassborow / oo-cheat.md
Last active November 15, 2021 01:42
FSharp OO cheat sheet