Skip to content

Instantly share code, notes, and snippets.

View rofr's full-sized avatar

Robert Friberg rofr

View GitHub Profile
@rofr
rofr / gist:9684919
Last active August 29, 2015 13:57
More scriptcs and origodb awesomeness!
rofr@DELLCRAPPO /c/git/scriptcs/origo1
$ scriptcs
scriptcs (ctrl-c to exit)
> using OrigoDB.Core;
> #r Todo.Core.dll
> using Todo.Core;
> var engine = Engine.Load<TodoModel>();
> using OrigoDB.Core.Proxy;
> var db = engine.GetProxy();
@rofr
rofr / ImmutablilityKernel.cs
Created March 28, 2014 22:38
What a lame name, help me out here!
/// <summary>
/// A Kernel that handles immutable models and commands using lock free mvcc
/// </summary>
public class ImmutabilityKernel : OptimisticKernel
{
public ImmutabilityKernel(EngineConfiguration config, Model model) :
base(config, model)
{
}
@rofr
rofr / fakeiteasy.cs
Created April 1, 2014 15:09
First attempt, well almost, at using FakeItEasy
[Test]
public void Timestamp_is_transfered_to_journalentry()
{
JournalEntry entry = null;
var fake = A.Fake<IJournalWriter>();
A.CallTo(() => fake.Write(A<JournalEntry>._))
.Invokes((JournalEntry je) =>
{
@rofr
rofr / RedisModel.cs
Created April 8, 2014 23:22
First draft of OrigoDB redis clone
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using OrigoDB.Core;
using OrigoDB.Core.Proxy;
public class RedisModel : Model
{
@rofr
rofr / RedisModel.ZRank.cs
Created April 11, 2014 10:24
Is there a more an efficient way to get the index of an item in a SortedSet?
/// <summary>
/// Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high.
/// The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.
/// </summary>
/// <param name="key"></param>
/// <param name="member"></param>
/// <returns>the rank of member or null if the set or member does not exist</returns>
public int? ZRank(string key, string member)
{
SortedSet<ZSetEntry> set = GetSortedSet(key);
@rofr
rofr / gist:b163e0721bfdb2d415f2
Created May 5, 2014 17:56
Language feature ('missing type') not yet implemented in Roslyn
C:\git\scriptcs>scriptcs
scriptcs (ctrl-c to exit)
> #r C:\git\Origo\OrigoDB.Modules\Protobuf\OrigoDB.Modules.Protobuf\bin\Release\origodb.modules.protobuf.dll
> #r C:\git\Origo\OrigoDB.Modules\Protobuf\OrigoDB.Modules.Protobuf\bin\Release\protobuf-net.dll
> #r C:\git\GeekStream\src\GeekStream.Core\bin\Release\geekstream.core.dll
> using GeekStream.Core.Commands;
> using GeekStream.Core.Domain;
> typeof(AddFeedItemCommand)
"GeekStream.Core.Commands.AddFeedItemCommand, GeekStream.Core, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null"
@rofr
rofr / gist:eeac5c0390101b97783a
Created September 17, 2014 03:12
Naive OrigoDB document database model
[Serializable]
public class DocumentModel : Model
{
private readonly Dictionary<object,object> _documents;
public DocumentModel()
{
_documents = new Dictionary<object, object>();
}
@rofr
rofr / gist:6a1ab40cb1a5eeb96860
Created September 17, 2014 03:14
OrigoDB document database commands
[Serializable]
public class PutCommand : Command<DocumentModel>
{
public readonly object Key;
public readonly object Document;
public PutCommand(object key, object document)
{
Key = key;
Document = document;
@rofr
rofr / gist:d54e7b89947ff9ffc5dd
Created September 17, 2014 03:16
OrigoDB Document database engine wrapper
public class DocumentDatabaseEngine
{
private readonly Engine<DocumentModel> _engine;
public DocumentDatabaseEngine(string location)
{
_engine = Engine.LoadOrCreate<DocumentModel>(location);
}
public DocumentDatabaseEngine() : this(String.Empty)
@rofr
rofr / gist:1ccb93d107d9ae16c7fd
Created September 17, 2014 03:17
OrigoDB document database example
public class Program
{
public static int CountCustomersQuery(Dictionary<object,object> docs)
{
return docs.OfType<Customer>().Count();
}
public static void Main(string[] args)
{
//Loads or creates a new database at the default location