Skip to content

Instantly share code, notes, and snippets.

View rofr's full-sized avatar

Robert Friberg rofr

View GitHub Profile
@rofr
rofr / movieGraphModel.cs
Created December 1, 2017 19:40
Memstate movie model - strongly typed graphs
//define actor node type
class Actor {
String Name;
Set<Role> Movies;
}
//define movie node type
class Movie {
String Name;
Set<Role> Roles;
@rofr
rofr / memstate-graph-example.cs
Created December 1, 2017 10:51
Memstate models are strongly typed object graphs
//user defined model with collections of user defined entities
class MyGraph {
Dictionary<Guid,Customer> Customers;
Dictionary<Guid,Order> Orders;
Dictionary<Guid,Product> Products;
}
class Order {
Customer Customer;
List<OrderLine> Lines;
@rofr
rofr / funkyProduct.js
Last active November 29, 2017 12:35
Recursive implementation of silly FB challenge
function funkyProduct(list, leftProduct = 1) {
if (list.length === 0) return [1];
else {
var result = funkyProduct(list.slice(1), leftProduct * list[0]);
var rightProduct = result[0] * list[0];
result[0] *= leftProduct;
if (leftProduct > 1) result.unshift(rightProduct);
return result;
}
}
@rofr
rofr / MemstateBenchmarks.cs
Last active November 6, 2017 17:15
Failing benchmarkdotnet benchmarks for memstate
namespace Memstate.Benchmarks
{
using System;
using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;

Keybase proof

I hereby claim:

  • I am rofr on github.
  • I am rofr (https://keybase.io/rofr) on keybase.
  • I have a public key ASAWCZS4EE6xRnrKxwT2RO80c-wpEuIGVQBLJ07eL-NapAo

To claim this, I am signing this object:

@rofr
rofr / piggyback-consensus.md
Created October 3, 2017 13:45
Thoughts on CAP, consensus and replication in a memstate cluster

OrigoDB

OrigoDB Server is an in-memory database for dotnet written in c#. It's implemented as a replicated state machine using write ahead logging of the mutating operations. The in-memory state model is derived from the sequence of operations persisted to the log. Writes are only accepted by the primary node and syncronously replicated to each of the replica nodes.  OrigoDB has no leader election (because the effort would be massive), promotion to primary is a manual process. https://github.com/devrexlabs/origodb

Memstate

Memstate is a reimplementation/port of OrigoDB based on the same principles but with a fundamentally different approach to logging. By routing the mutating operations (commands) through an underlying stream database (eventstore, kafka, kinesis, etc) message ordering, distribution and durability are guaranteed at the logging level. The key is to apply the commands when they return from the stream database. Using this model it's possible to accept writes at any node. This is the curren

@rofr
rofr / JsonSerializer.cs
Created September 4, 2017 18:59
Failed attempt at a JsonConverter to intercept JsonToken.Integer, (which will default to Int64 when assigned to a property of type Object)
namespace Memstate.JsonNet
{
public class JsonObjectToIntegerConverter : JsonConverter
{
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
//never called because CanWrite is false
throw new NotImplementedException();
@rofr
rofr / OperationInfo.cs
Created September 1, 2017 07:28
Would you put the second return statement in an else block?
public object Execute(Client<T> client, MethodCall methodCall, string signature)
{
if (IsMapped && TryGetMappedOperation(methodCall, out var mappedOperation))
{
return ExecuteMapped(client, methodCall, mappedOperation);
}
return ExecuteImpl(client, methodCall, signature);
}
@rofr
rofr / DEVREXLABS_CLA
Last active June 25, 2017 15:43 — forked from CLAassistant/SAP_CLA
Devrex Labs Individual Contributor License Agreement
###Devrex Labs Individual Contributor License Agreement
Thank you for your interest in contributing to open source software projects (“Projects”) made available by Devrex Labs. This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to Devrex Labs in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact opensource@devrexlabs.com.
You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.
**Copyright License.** You hereby grant, and agree to grant, to Devrex Labs a non-exclusive, perpetual, irrevocable
@rofr
rofr / test.cs
Created June 25, 2017 14:20
testing assumptions on framework behavior
[Fact]
public void TryTake_returns_false_when_marked_for_completion()
{
var blockingCollection = new BlockingCollection<int>();
blockingCollection.CompleteAdding();
var result = blockingCollection.TryTake(out var item);
Assert.False(result);
}