Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@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();
@Horusiath
Horusiath / Benchmark.cs
Last active December 5, 2017 20:04
Benchmarks for .NET collection creation
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using BenchmarkDotNet.Attributes;
namespace Hyperion.Benchmarks
{
public class HyperionConfig : ManualConfig
@Horusiath
Horusiath / Example.cs
Created September 27, 2017 06:59
Generic Google Protocol Buffers serializer for Akka.NET
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Serialization.Protobuf;
using ProtoBuf;
namespace App
{
/// <summary>
/// Interface used to recognize messages to be serialized by <see cref="ProtobufSerializer"/>.
@Horusiath
Horusiath / AkklingAPI.fs
Last active March 13, 2018 11:25
akka-typed Akkling API idea
type Command = Job of string
let active (count: int): Behavior<Command> =
Actor.behavior (fun ctx msg ->
match msg with
| Job payload ->
printfn "Received %s, current state: %d" payload count
// return updated state behavior, equivalent of become
active (count + 1))
|> onSignal (fun ctx sig ->
@Horusiath
Horusiath / missing union types.fs
Created June 15, 2017 10:35
Lack of union types
// we define two message-based protocols: one for data replication one for persistence
// those can be defined easily using discriminated union semantics
type ReplicationProtocol =
| Sync of Endpoint
| ReplicationProgess of ReplicaId * int
| Read of ReplicaId
| ReadRepair of ReplicaId
type PersistenceProtocol =
| Save of PersistenceId * byte[]
@Horusiath
Horusiath / log
Created February 1, 2017 10:13
linux/mono DotNetty exception
Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Net.Sockets.SocketException: Invalid arguments
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00036] in <filename unknown>:0
at DotNetty.Transport.Channels.Sockets.TcpServerSocketChannel.DoBind (System.Net.EndPoint localAddress) [0x00000] in <filename unknown>:0
at DotNetty.Transport.Channels.AbstractChannel+AbstractUnsafe.BindAsync (System.Net.EndPoint localAddress) [0x00026] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unkn
@Horusiath
Horusiath / Program.cs
Created January 26, 2017 09:08
Akka.Persistence example with proto-buf.net as a custom domain event serializer
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Persistence.SqlServer;
namespace TestApp
{
class Program
{
public static void Main()
@Horusiath
Horusiath / Client.cs
Last active January 18, 2017 08:06
DotNetty example of failing TLS layer support
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Common.Internal.Logging;
using DotNetty.Handlers.Logging;
@Horusiath
Horusiath / Example.cs
Created January 16, 2017 13:26
Akka.NET new DotNetty-based transport pipelines (more or less accurate)
// server
new ServerBootstrap()
.Group(serverEventLoopGroup)
.Option(ChannelOption.SoReuseaddr, Settings.TcpReuseAddr)
.Option(ChannelOption.SoKeepalive, Settings.TcpKeepAlive)
.Option(ChannelOption.TcpNodelay, Settings.TcpNoDelay)
.Option(ChannelOption.AutoRead, false)
.Option(ChannelOption.SoBacklog, Settings.Backlog)
.ChannelFactory(() => Settings.EnforceIpFamily
? new TcpServerSocketChannel(addressFamily)
@Horusiath
Horusiath / ReplicatorMessageSerializer.cs
Created January 13, 2017 15:59
DData serializer on proto-buf
internal sealed class ReplicatorMessageSerializer : SerializerWithStringManifest
{
#region internal classes
/// <summary>
/// A cache that is designed for a small number (&lt;= 32) of
/// entries. It is using instance equality.
/// Adding new entry overwrites oldest. It is
/// thread safe but duplicates of same entry may occur.