Skip to content

Instantly share code, notes, and snippets.

View trbngr's full-sized avatar

Chris Martin trbngr

  • Phoenix, AZ, USA
View GitHub Profile
@trbngr
trbngr / ExtendImmutableEnvelope.cs
Created June 28, 2011 18:10
Injecting Message Information in Lokad CQRS v2
public static class ExtendImmutableEnvelope
{
public static Guid GetGuid(this ImmutableEnvelope envelope, string key)
{
return Get(envelope, key, s =>
{
Guid result;
return Guid.TryParse(s, out result) == false ? Guid.Empty : result;
});
}
public class Program
{
private static void Main()
{
var instance = new SomeClass
{
SomePropertyWithAttribute = "I have an attribute",
SomeProperty = "I don't have an attribute"
};
@trbngr
trbngr / ApiResourceSerializationTests.cs
Created August 26, 2012 09:54
Demonstrating how to skip fields that aren't decorated with a certain attribute using json.net.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using GuessWho;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using SignalR.Client;
using SignalR.Client.Hubs;
using SignalR.Hubs;
namespace EventDay.Web.Api.Controllers
EventStoreConnection connection = get your connection;
string streamName = GetStreamName(aggregate);
//try to read the slice
var slice = connection.ReadStreamEventsForward(streamName, 0, int.MaxValue, false);
if (slice.Status == SliceReadStatus.StreamNotFound)
{
//create the stream if doesn't exist.
//NOTE: isJson MUST be true for this to work.
@trbngr
trbngr / SubscriptionRoot.js
Last active July 22, 2016 19:06
My root component for a relay-subscriptions application.
import React, {Component, PropTypes} from 'react';
import {SubscriptionProvider} from 'relay-subscriptions'
import uuid from 'uuid'
const outgoing = {
subscribe: 'subscribe',
ping: 'ping'
};
const incoming = {
import { GraphQLScalarType } from 'graphql';
import { GraphQLError } from 'graphql/error';
import { Kind } from 'graphql/language';
import moment from 'moment';
import tz from 'moment-timezone';
function coerceDate(value) {
if(typeof value === 'string')
value = moment(value);
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<akka>
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.ExecutionContext.Implicits.global
object ModelReaders {
implicit object UserReader extends ModelReader[User] {
def read(repo: Repo, id: Int) = repo.getUser(id)
}
implicit object RoomReader extends ModelReader[Room] {
def read(repo: Repo, id: Int): Future[Option[Room]] = repo.getRoom(id)
}
@trbngr
trbngr / JsonSerializer.scala
Created August 30, 2016 20:50
json4s serializer for [EventStore.Akka.Persistence](https://github.com/EventStore/EventStore.Akka.Persistence)
package com.company.serialization
import java.nio.ByteBuffer
import java.nio.charset.Charset
import akka.actor.{ActorRef, ExtendedActorSystem}
import akka.persistence.PersistentRepr
import akka.persistence.eventstore.EventStoreSerializer
import akka.persistence.eventstore.snapshot.EventStoreSnapshotStore.SnapshotEvent
import akka.persistence.journal.Tagged