Skip to content

Instantly share code, notes, and snippets.

View bartelink's full-sized avatar

Ruben Bartelink bartelink

View GitHub Profile
@bartelink
bartelink / describe_AClass.cs
Created September 14, 2012 09:01
Row test in NSpec
/*
output of the row test below
describe AClass
describe many variations
A should equal A
C should equal A - [Failed]
*/
//top level context to describe class
class describe_AClass
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Xunit.Extensions;
namespace Prototypes.AutoFixture.Xunit.Extensions
{
public class CompositeDataAttribute : DataAttribute
@bartelink
bartelink / gist:5671464
Created May 29, 2013 16:04
Ninject Scoping Learnings and Tests to accompany http://stackoverflow.com/a/15836383/11635
public static class NinjectScopingLearning
{
public static class InParentScope
{
[Fact]
public static void WorksIffParentScopeAllWayUp()
{
var kernel = new StandardKernel();
kernel.Bind<Root>().ToSelf().InSingletonScope();
kernel.Bind<Child>().ToSelf().InParentScope();
@bartelink
bartelink / DiagnosticFeatures.fs
Last active December 24, 2015 12:58
My TickSpec.xunit boilerplate (just add .feature files as EmbeddedResources and group them into XXXFeatures.fs as in the example DiagnosticFeatures.fs file)
open TickSpec
open Features
module DiagnosticFeatures =
[<TickFact>]
let ConnectivityFeature () =
generateScenariosFromEmbeddedFeatureFile "Connectivity"
@bartelink
bartelink / Consolidate-VSFindInFilesSpec.ps1
Last active January 4, 2016 09:09
Ugly hacky script to generate a VS Find in Files uber-Filter
# TODO dig out of registry instead of cutting and pasting from VS!
$x="*.c;*.cpp;*.cxx;*.cc;*.tli;*.tlh;*.h;*.hh;*.hpp;*.hxx;*.hh;*.inl;*.rc;*.resx;*.idl;*.asm;*.inc;*.tlh;*.h;*.hh;*.hpp;*.hxx;*.hh;*.inl;*.rc;*.resx;*.idl;*.asm;*.inc;*.cs;*.resx;*.resw;*.xsd;*.wsdl;*.xaml;*.xml;*.htm;*.html;*.css;*.vb;*.resx;*.xsd;*.wsdl;*.htm;*.html;*.aspx;*.ascx;*.asmx;*.svc;*.asax;*.config;*.asp;*.asa;*.cshtml;*.vbhtml;*.css;*.xml;*.xml;*.xsl;*.xslt;*.xsd;*.dtd;*.srf;*.htm;*.html;*.xml;*.gif;*.jpg;*.png;*.css;*.disco;*.txt;*.json;*.vb;*.resx;*.xsd;*.wsdl;*.htm;*.html;*.aspx;*.ascx;*.asmx;*.svc;*.asax;*.config;*.asp;*.asa;*.cshtml;*.vbhtml;*.css;*.xml;*.cs;*.resx;*.resw;*.xsd;*.wsdl;*.xaml;*.xml;*.htm;*.html;*.css"
$x+=";*.fs;*.json;*.ts"
# strip *.
$all = $x.Split( ";") | % { $_.Replace("*.","") }
#xml fins too much junk in obj dirs
@bartelink
bartelink / EventMachines.md
Last active August 23, 2016 14:47 — forked from eulerfx/EventMachines.md
The relationship between state machines and event sourcing

A state machine is defined as follows:

  • Input - a set of inputs
  • Output - a set of outputs
  • State - a set of states
  • S0 ∈ S - an initial state
  • T : Input * State -> Output * State - a transition function

If you model your services (aggregates, projections, process managers, sagas, whatever) as state machines, one issue to address is management of State. There must be a mechanism to provide State to the state machine, and to persist the resulting State for subsequent retrieval. One way to address this is by storing State in a key-value store. Another way is to use a SQL database. Yet another way is event sourcing. The benefit of event sourcing is that you never need to store State itself. Instead, you rely on the Output of a service to reconstitute state. In order to do that, the state machine transition function needs to be factored into two functions as follows:

@bartelink
bartelink / TickSpecXunit2FeatureAttributeAndDiscoverer.fs
Created November 17, 2016 09:57
Stash of a spike to grab TickSpec Scenarios during the xUnit 2 discovery phase in order to surface the Scenarios as individual Tests in the VS Test Runner list. AFAICT this will never work as it will require all of TickSpec's object model and more (the compiled code) to be serializable
namespace TickSpec
open System
open System.Reflection
open System.Threading.Tasks
open Xunit
open Xunit.Abstractions
open Xunit.Sdk
module Impl =
@bartelink
bartelink / NesGateway.fs
Last active May 7, 2017 13:42
Dump of ProtoBuf serialization spike for http://github.com/bartelink/FunDomain
module FunDomain.Persistence.NEventStore.NesGateway
open FunDomain.Persistence.Serialization
open NEventStore
open NEventStore.Persistence
open NEventStore.Persistence.Sql.SqlDialects
open Microsoft.FSharp.Reflection
open System
### Keybase proof
I hereby claim:
* I am bartelink on github.
* I am bartelink (https://keybase.io/bartelink) on keybase.
* I have a public key ASBsuiXja6_19Fq_ZG-VmuGchBYVYRFszqzRoRoy4vDl4go
To claim this, I am signing this object:
/// Thread-safe coordinator that batches concurrent requests for a single <c>dispatch</> invocation such that:
/// - requests arriving together can be coalesced into the batch during the linger period via TryAdd
/// - callers that have had items admitted can concurrently await the shared fate of the dispatch via AwaitResult
/// - callers whose TryAdd has been denied can await the completion of the in-flight batch via AwaitCompletion
type internal AsyncBatch<'Req, 'Res>(dispatch : 'Req[] -> Async<'Res>, linger : System.TimeSpan) =
let lingerMs = int linger.TotalMilliseconds
// Yes, naive impl in the absence of a cleaner way to have callers sharing the AwaitCompletion coordinate the adding
do if lingerMs < 5 then invalidArg "linger" "must be >= 5ms"
let queue = new System.Collections.Concurrent.BlockingCollection<'Req>()
let dispatch = async {