Skip to content

Instantly share code, notes, and snippets.

View thefringeninja's full-sized avatar
🍿

João Bragança thefringeninja

🍿
View GitHub Profile
@thefringeninja
thefringeninja / gist:1860325ad6dcf490795b
Created May 27, 2014 16:47
MessagingAcceptanceTests
public interface MessageFormatter
{
byte[] Serialize(object message);
object Deserialize(byte[] data, Type type);
}
public class NetDataContractMessageFormatter : MessageFormatter
{
private readonly NetDataContractSerializer serializer;
@thefringeninja
thefringeninja / bus.coffee
Created June 10, 2014 04:03
Undo with Knockout and Eventing
class window.Bus
constructor: ->
@dispatcher = {}
subscribe: (pattern, handler) ->
handlers = @dispatcher[pattern] || []
handlers.push handler
@dispatcher[pattern] = handlers
publish: (e) ->
@thefringeninja
thefringeninja / MessageSpecification.cs
Created July 15, 2014 17:49
Message Specification
public class MessageSpecification : TypedSpecification<MessageSpecification.Result>, HasMessages
{
public Action Before;
public Action<Bus> Bootstrap = bus => { };
public List<Expression<Func<Result, bool>>> Assertions = new List<Expression<Func<Result, bool>>>();
public Action Finally;
public readonly List<Event> Given = new List<Event>();
public static Task<DbDataReader> ExecuteReaderAsync(this IDbCommand dbCommand) {
var command = dbCommand as DbCommand;
if (command == null) throw new ArgumentException("dbCommand");
return command.ExecuteReaderAsync();
}
@thefringeninja
thefringeninja / NES Commit
Created August 18, 2014 15:47
Sample GES Projection That "Unrolls" NES Commit
{
"BucketId": "b",
"StreamId": "1b42e222-92d6-4242-a528-53a8e61fa524",
"StreamRevision": 2,
"CommitId": "0b7efcaa-9923-4813-a780-380fb23ad04a",
"CommitSequence": 1,
"CommitStamp": "2014-08-18T15:36:43.5386215Z",
"Headers": {
"A header": "A string value",
"Another header": 2
@thefringeninja
thefringeninja / gist:379f4096ad81ce15e452
Created August 19, 2014 12:03
Dtos, Value Objects, Casting and You
[DataContract]
public class MoneyDto {
[DataMember(Order = 1)] public readonly decimal Amount;
[DataMember(Order = 2)] public readonly string CurrencyCode;
public CurrrencyDto(decimal amount, string currencyCode) {
Amount = amount;
CurrencyCode = currencyCode;
}
}
[DataContract]
RabbitMQ
|
|
|
|
My Application's
Main Queue
/ | \
/ | \
/ | \
@thefringeninja
thefringeninja / Program.cs
Created October 27, 2014 15:50
Creating a Cluster
public static class Program {
const int ClusterSize = 3;
public static void Main(string[] args) {
int clusterMemberId = Int32.Parse(args[0]);
var options = new StartupOptions {
ClusterMemberId = clusterMemberId
}
ClusterVNode node = options.BuildVNode(ClusterSize);
@thefringeninja
thefringeninja / annoying
Created February 3, 2015 10:30
FSharp and DotLiquid
open System.Linq
let isSimpleType (typ:Type) =
typ.IsPrimitive || typ.IsEnum || primitiveTypes.Contains typ
open System.Collections
open System.Reflection
let rec private proxy(target : obj) =
let maybeTarget = Some target
@thefringeninja
thefringeninja / Dude.cs
Created February 3, 2015 22:47
Raven Async and Tests
public class RavenTestBase {
Task<IDocumentStore> _createDocumentStore;
ctor() {
var source = new TaskCompletionSource<IDocumentStore>();
_createDocumentStore = source.Task;
Task.Run(async () => {
var store = InitializeDocumentStore();