Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@Horusiath
Horusiath / Fiber.fs
Last active April 16, 2024 06:11
Custom fibers implementation in F#
/// MIT License
///
/// Copyright (c) 2024 Bartosz Sypytkowski
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@Horusiath
Horusiath / Fibers.cs
Created November 24, 2019 22:09
Minimal example of working async method builder
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
namespace Fibers
{
public struct AsyncFiberMethodBuilder<T>
{
private Fiber<T>? fiber;
@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
// #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 / 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 / hyperion.md
Last active June 21, 2023 18:31
[DRAFT] Hyperion binary format

Hyperion

This is a draft for binary format and implementation proposal for Hyperion, a fast binary serializer for .NET. Currently Hyperion is in beta and uses non-standard binary format. This document aims to specify it. Before we do that, there are few important properties of the serializer we wish to maintain:

Polymorphic

Hyperion is polymorphic serializer, therefore it's tolerant for subtyping rules. Example using C# pseudo-code:

var serializer = new Serializer();
@Horusiath
Horusiath / README.md
Last active June 21, 2023 18:29
Operation conflation of Commutative Replicated Data Types

Operation conflation of Commutative Replicated Data Types

Intro to Commutative Replicated Data Types

Operation-based variant of CRDTs is based on idea, that instead of replicating the state (or its delta), we replicate the operations, and let the corresponding replica build eventually consistent state from operations only. A standardized API for such data types consist of several members:

  • initial: empty instance of CRDT object.
  • query: returns a value out of the CRDT object.
  • atSource: which returns a serializable operation. I.e. for a given Counter CRDT, its atSource function could return operations like inc(replicaId, delta) or dec(replicaId, delta).
  • downstream which is used to consume operations incoming from both local and remote sources to produce new state of the CRDT object.
@Horusiath
Horusiath / Main.fs
Last active June 21, 2023 18:27
Affine thread pool
/// The MIT License (MIT)
///
/// Copyright (c) Bartosz Sypytkowski <b.sypytkowski@gmail.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@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 / DESIGN.md
Last active June 21, 2023 18:21
Yggdrassil design document

Yggdrassil design document

This paper discusses some ideas of how to extend HyParView/Plumtree beyond the most straightforward implementation. It presents the goals that we wanted to have in mind when building actual implementation in Rust.

Motivation

While Partisan - the original and probably the most widely adopted implementation of HyParView+Plumtree - value proposition relies on building huge clusters (having >10 000 nodes) capable of broadcasting messages via self-healing broadcast trees, its network protocol seems to limit its possibilities to centralized solutions - like services living in data centres or at the edge, where peer discoverability and reachability is in control of their developers/operators. Other issue is that when exchanging neighbors/shuffle peers, plumtree blindly replaces them with current passive view without checking if they are reachable for the current peer in the first place.

We think, that adopting HyParView/Plumtree in Rust with extensible API could expand its capabil