Skip to content

Instantly share code, notes, and snippets.

Avatar
🍿

João Bragança thefringeninja

🍿
View GitHub Profile
View gist:1860325ad6dcf490795b
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 Jun 10, 2014
Undo with Knockout and Eventing
View bus.coffee
class window.Bus
constructor: ->
@dispatcher = {}
subscribe: (pattern, handler) ->
handlers = @dispatcher[pattern] || []
handlers.push handler
@dispatcher[pattern] = handlers
publish: (e) ->
View MessageSpecification.cs
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>();
View gist:cc19e7259f85cca07c64
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 Aug 18, 2014
Sample GES Projection That "Unrolls" NES Commit
View 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 Aug 19, 2014
Dtos, Value Objects, Casting and You
View gist:379f4096ad81ce15e452
[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]
View Fanout
RabbitMQ
|
|
|
|
My Application's
Main Queue
/ | \
/ | \
/ | \
View Program.cs
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 Feb 3, 2015
FSharp and DotLiquid
View annoying
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 Feb 3, 2015
Raven Async and Tests
View Dude.cs
public class RavenTestBase {
Task<IDocumentStore> _createDocumentStore;
ctor() {
var source = new TaskCompletionSource<IDocumentStore>();
_createDocumentStore = source.Task;
Task.Run(async () => {
var store = InitializeDocumentStore();