Skip to content

Instantly share code, notes, and snippets.

Bartosz Sypytkowski Horusiath

View GitHub Profile
@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>]
@Horusiath
Horusiath / Program.fs
Last active Jun 7, 2020
A simple Reliable Causal Broadcast implementation using F# and Akka.NET
View Program.fs
module Program =
type VolatileCursor(map: Map<string, obj>, key: string) =
let rec moveToKey (enum: IEnumerator<KeyValuePair<string,obj>>) =
if enum.MoveNext() then
if enum.Current.Key.StartsWith key then true, enum
else moveToKey enum
else false, enum
let mutable ok, enum = moveToKey <| (map :> IEnumerable<KeyValuePair<string,obj>>).GetEnumerator()
View Benchmark-Results.md
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

View Demo1.fs
// #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 Apr 9, 2020
Toy implementation of SWIM protocol in Akkling (Akka.NET F#)
View Program.fs
open System
open System.Threading
open Akkling
open DemoFs
[<EntryPoint>]
let main argv =
let config = """
akka.loglevel = DEBUG
@Horusiath
Horusiath / Program.cs
Created Feb 14, 2020
Demo presenting how to extend C# LINQ syntax over tasks and how to build our own async/await-capable type.
View Program.cs
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
View json-string-parsing.fs
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
@Horusiath
Horusiath / Fibers.cs
Created Nov 24, 2019
Minimal example of working async method builder
View Fibers.cs
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 / Fiber.fs
Last active Mar 31, 2020
Custom fibers implementation in F#
View Fiber.fs
open System
open System.Threading
type FiberResult<'a> = Result<'a, exn> option
[<Sealed;AllowNullLiteral>]
type Cancel(parent: Cancel) =
let mutable flag: int = 0
let mutable children: Cancel list = []
new() = Cancel(null)
You can’t perform that action at this time.