Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@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 / 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 / Program.cs
Last active November 24, 2020 05:45
An interfaced generic-aware Akka.NET actor implementation
using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
namespace AkkaDemos
{
public interface IGreeter
{
Task<string> Greet(IGreeter who);
@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 / Demo.cs
Last active November 24, 2020 06:04
Custom Akka.NET Streams graph stage for prefetching elements, when the buffer comes close to the empty
using Akka.Streams;
using Akka.Streams.Stage;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
sealed class PreFetch<T> : GraphStage<SourceShape<T>>
@Horusiath
Horusiath / main.c
Created May 24, 2019 05:23
Demo of a simple custom virtual machine. Presentation available at https://www.slideshare.net/BartoszSypytkowski1/virtual-machines-how-they-work/
#include <stdio.h>
#include <stdlib.h>
// stack will have fixed size
#define STACK_SIZE 1024
#define DEBUG_ENABLED 1
#define DBG if(DEBUG_ENABLED) printf
#define PUSH(vm, v) vm->stack[++vm->sp] = v // push value on top of the stack
#define POP(vm) vm->stack[vm->sp--] // pop value from top of the stack
#define NEXT(vm) vm->code[vm->pc++] // get next bytecode
@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 / 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 / CSharpBenchmark.cs
Last active July 1, 2018 18:07
Delegates vs. generic readonly structs
using System;
using BenchmarkDotNet.Attributes;
namespace Tachyon.Benchmarks.Core
{
// Instead of delegate, use interface.
interface IFunc<in I, out O>
{
O Invoke(I arg);
@Horusiath
Horusiath / Benchmark.cs
Last active May 14, 2018 07:48
Direct vs indirect enumerator call
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
namespace Benchmarks
{
public class EnumeratorBenchmarks
{
private const int SIZE = 1_000_000;
private static readonly int[] array = GetArray();