Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@Horusiath
Horusiath / Effect.fs
Created September 19, 2020 04:58
Inferred dependency injection over async bindings.
open System
[<Struct>] type Effect<'env, 'out> = Effect of ('env -> Async<'out>)
[<RequireQualifiedAccess>]
module Effect =
/// Create value with no dependency requirements.
let inline value (x: 'out): Effect<'env,'out> = Effect (fun _ -> async.Return x)
/// Create value which uses depenendency.
@Horusiath
Horusiath / Throttle.cs
Last active July 24, 2020 17:07
Throttling operator for Rx.NET
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace CsDemo
{
public static class ObservableExtensions
{
/// <summary>
/// Pass through up to <paramref name="count"/> items downstream within given <paramref name="interval"/>.
@Horusiath
Horusiath / Program.fs
Last active June 21, 2023 18:23
Fun with concepts about composeable logging.
open System
open System.IO
open System.Threading.Tasks
(*
Some notes:
1. TextWriter is overbloated. Ideally this should be something like Go's io.Writer interface. Notice that Go doesn't
differentiate between async/non-async functions (it doesn't have to), which makes API even simpler.
2. While very rough, this snippet already provides a lot of what mature logging frameworks (like Serilog) can do:
@Horusiath
Horusiath / CASPaxos.fs
Last active May 7, 2020 14:45
CASPaxos implementation
/// Toy implementation of CAS Paxos (see: https://github.com/rystsov/caspaxos/blob/master/latex/caspaxos.pdf).
module DemoFs.CASPaxos
open Akka.Actor
open Akkling
open System
type NodeId = string
[<Struct>]
@Horusiath
Horusiath / Program.fs
Last active December 26, 2023 12:21
A simple Reliable Causal Broadcast implementation using F# and Akka.NET
module Program =
type InMemoryDb(replica: ReplicaId) =
let snapshot = ref null
let mutable events : Map<uint64,obj> = Map.empty
interface Db with
member _.SaveSnapshot state = async { snapshot := (box state) }
member _.LoadSnapshot<'s>() = async {
match !snapshot with
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18363
Intel Core i5-4430 CPU 3.00GHz (Haswell), 1 CPU, 4 logical and 4 physical cores
.NET Core SDK=3.1.200
  [Host]     : .NET Core 3.1.2 (CoreCLR 4.700.20.6602, CoreFX 4.700.20.6702), X64 RyuJIT DEBUG
  DefaultJob : .NET Core 3.1.2 (CoreCLR 4.700.20.6602, CoreFX 4.700.20.6702), X64 RyuJIT

// #r "nuget: Ply"
// #r "nuget: BCrypt.Net-Next"
module FsDemo.Demo1
open System
open System.Text
open System.Threading.Tasks
open FSharp.Control.Tasks.Builders
@Horusiath
Horusiath / Program.fs
Last active April 9, 2020 13:19
Toy implementation of SWIM protocol in Akkling (Akka.NET F#)
open System
open System.Threading
open Akkling
open DemoFs
[<EntryPoint>]
let main argv =
let config = """
akka.loglevel = DEBUG
@Horusiath
Horusiath / Program.cs
Created February 14, 2020 06:53
Demo presenting how to extend C# LINQ syntax over tasks and how to build our own async/await-capable type.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace Demo
{
public readonly struct Void
open System
open System.Text.Json
open FsCheck.Xunit
open Newtonsoft.Json
open Swensen.Unquote
[<Property>]
let ``Parsing strings: System.Text.Json`` (i: char[]) =
let sb = System.Text.StringBuilder()
for c in i do