Skip to content

Instantly share code, notes, and snippets.

Avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@Horusiath
Horusiath / HashRings.fs
Last active Aug 13, 2021
Hash rings implementations in F#
View HashRings.fs
module Demo.HashRings
open System
open System.Collections.Generic
/// Range is a tuple describing (s,e] - where `s` is start
/// (exclusive) index, while `e` is end (inclusive) index.
type Range = ValueTuple<int,int>
[<RequireQualifiedAccess>]
@Horusiath
Horusiath / Dht.fs
Last active Aug 5, 2021
Consistent hash ring and virtual bucket hash ring implementations
View Dht.fs
module Demo.Dht
open System
open System.Collections.Generic
/// Range is a tuple describing (s,e] - where `s` is start
/// (exclusive) index, while `e` is end (inclusive) index.
type Range = ValueTuple<int,int>
[<RequireQualifiedAccess>]
@Horusiath
Horusiath / Ramp.fs
Last active Aug 21, 2021
RAMP Hybrid transaction protocol implementation using Akka.NET in F#
View Ramp.fs
module Demo.Ramp
open System
open Akka.Actor
open Akkling
/// A Lamport clock timestamp used as transaction identifier - sequence number with unique node identifier.
/// Original paper implementation uses combination of hybrid logical clock with node id encoded together into uint64.
type TxnId = DateTime * int
View workouts.md

Requirements:

  • Pull up bar
  • Dumbells (mine had regulated weight: 40kg total)
  • Rubber band (mine is 25kg)
  • Workout 2 uses gymnastics rings
  • Workouts 9 and 10 use bars with higher weights

Warmup

@Horusiath
Horusiath / Protocols.fs
Last active Jan 18, 2021
Plumtree + Hyparview implementation in F#
View Protocols.fs
namespace Protocols
open System
open System.Runtime.ExceptionServices
type Endpoint = string
type TTL = int
type Binary = byte[]
type MessageId = Guid
type Round = uint64
@Horusiath
Horusiath / Hyparview.fs
Last active Aug 18, 2021
HyParView: a membership protocol for reliable gossip-based broadcast
View Hyparview.fs
// Reference: https://asc.di.fct.unl.pt/~jleitao/pdf/dsn07-leitao.pdf
module Protocols.Hyparview
open System
open System.Runtime.ExceptionServices
open System.Threading
type Endpoint = string
type TTL = int
@Horusiath
Horusiath / Effect.fs
Created Sep 19, 2020
Inferred dependency injection over async bindings.
View Effect.fs
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 Jul 24, 2020
Throttling operator for Rx.NET
View Throttle.cs
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 Apr 22, 2020
Fun with concepts about composeable logging.
View Program.fs
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
CASPaxos implementation
View CASPaxos.fs
/// 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>]