Skip to content

Instantly share code, notes, and snippets.

@mat-mcloughlin
mat-mcloughlin / ioCContainer
Last active December 21, 2015 03:18
A very basic example of an IoC Container
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var container = new Container();
container.Bind<ICar, Car>();
@mat-mcloughlin
mat-mcloughlin / TurtleModule.cs
Last active December 21, 2015 08:59
A simple Nancy module
using Nancy;
using Nancy.ModelBinding;
public class TurtleModule : NancyModule
{
public TurtleModule() : base("/turtle")
{
// Note: arguments can be named anything.
Get["/"] = arguments =>
{
@mat-mcloughlin
mat-mcloughlin / gist:6376025
Created August 29, 2013 09:25
A knockout binding handler that formats dates correctly. It requires the use of jquery, knockout and moment Ideally I'd do this without jquery
ko.bindingHandlers.date = {
update: function(element, valueAccessor, allBindingsAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
var allBindings = allBindingsAccessor();
var format = allBindings.format || 'DD/MM/YYYY'; // default format.
if (value && value != 'Invalid Date') {
var formattedDate = moment(value).format(format);
if ($(element).is('input')) {
class RandomObject
{
public decimal? PropertyA { get; set; }
public decimal? PropertyB { get; set; }
}
class CalculatePropertyA : ICalculator
{
string Name { get { return "PropertyA"; } }
@mat-mcloughlin
mat-mcloughlin / Attempt One
Created December 10, 2013 16:28
Some random attempts at god knows what
public class Program
{
public static void Main(string[] args)
{
var store = Wireup.Init().UsingInMemoryPersistence().Build();
var repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector());
var handler = new CreatePostCommandHandler(repository);
handler.Execute(new CreatePostCommand(new Guid(), "Test Title", "Test Description"));
}
@mat-mcloughlin
mat-mcloughlin / ಠ_ಠAttribute.cs
Created December 11, 2013 16:33
This code is bad and you should feel bad
[AttributeUsage(System.AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class ಠ_ಠAttribute : Attribute
{
public ILog Log { get; set; }
public ಠ_ಠAttribute()
{
Log.Info("This code is bad and you should feel bad");
}
}
namespace Kata
{
using System.Collections.Generic;
using System.Linq;
using Xunit;
public interface ICheckout
{
void Scan(string item);
@mat-mcloughlin
mat-mcloughlin / reservation-pattern
Created July 17, 2014 10:38
Attempt at reservation pattern
public class FooReserver
{
private readonly int reserveFor;
public static List<string> ReservedFoos = new List<string>();
public FooReserver(int reserveFor)
{
this.reserveFor = reserveFor;
}
public class GameId : TypedGuid
{
}
public class TypedGuid
{
protected Guid Value { get; set; }
public static implicit operator Guid(TypedGuid typedGuid)
{
var decision = "Dave".DecidesTo<InviteToLobby>();
decision.ProvidedDataIs("something");
decision.NewKnowledgeIs<InvitedToLobby>((e) => e.Something.ShouldBe("test"));
decision.IsAvailableWhen(() => new TestTopicInValidState());
decision.IsntAvailableWhen<ExpectedException>(() => new TestTopicInInvalidState());