Skip to content

Instantly share code, notes, and snippets.

@tkellogg
tkellogg / SiteVisitWorkflow.cs
Created March 8, 2011 16:44
Abstract workflow factory & example usage (SiteVisitWorkflow) for ObjectFlow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using kpa.mko.dal;
using kpa.common.workflow;
using Rainbow.ObjectFlow.Stateful;
using kpa.common.container;
using kpa.common.interfaces;
@tkellogg
tkellogg / ModelsAndViewModels.cs
Created September 16, 2011 03:05
AutoMapper example for my blog (http://timkellogg.blogspot.com)
public class Account
{
public virtual int AccountId { get; set; }
[Matches(@"[A-Z]{2}\d{5}")]
public virtual string Code { get; set; }
[Required]
public virtual string Name { get; set; }
public virtual int? Age { get; set; }
}
@tkellogg
tkellogg / gist:1221166
Created September 16, 2011 03:58
Another AutoMapper example using polymorphism
public class Account
{
public virtual int AccountId { get; set; }
[Matches(@"[A-Z]{2}\d{5}")]
public virtual string Code { get; set; }
[Required]
public virtual string Name { get; set; }
public virtual int? Age { get; set; }
}
@tkellogg
tkellogg / BDD.cs
Created December 28, 2011 17:44
BDD in C#
[TestFixture]
class when_adding_numbers
{
Maths maths;
void Given_an_object_in_bigint_mode()
{
maths = new Maths();
maths.BigInt = true;
}
var css = {
"margin-top": (($(dv).parent().height - $(dv).height()) / 2) + 'px',
"position":"absolute"
};
$(dv).css(css);
$(dv).parent().css('position', 'relative');
@tkellogg
tkellogg / log.cs
Created February 15, 2012 17:30
A really expensive way to log
// ...
throw new Exception("Wizard package not imported.");
}
}
catch (Exception e)
{
Logger.log(e);
}
@tkellogg
tkellogg / gist:1941345
Created February 29, 2012 14:56
Example of option types in F#
let find kittens =
match kittens.IndexOf("kittens") with
| -1 -> None
| x -> Some kittens.SubString(x, 7)
match find "a box of kittens" with
| None -> printf "no kittens"
| Some container -> printf "kittens found inside '%s'" container
@tkellogg
tkellogg / case-block.cs
Created March 10, 2012 20:14
Some C# & F# code to talk about discriminated unions
public enum LightSwith
{
On,
Dimmed(int intensity),
Off
}
// And to use
var value = GetLightSwitchValue();
@tkellogg
tkellogg / DomainObject-simple.cs
Created March 20, 2012 03:35
Basic object model for mongo-nhibernate abstract data layer
public abstract class DomainObject : IDomainObject
{
public virtual object Id { get; set; }
#region Overloads of Equals & GetHashCode
// ...
#endregion
}
@tkellogg
tkellogg / Word-Definition.cs
Created March 23, 2012 03:38
Why Object IDs & Primary Keys Are Implementation Details
public class Word {
public int Id { get; set; }
public string Name { get; set; }
public IList<Definition> Definitions { get; private set; }
}
public class Definition {
public int Id { get; set; }
public int WordId { get; set; }
public string Text { get; set; }