Skip to content

Instantly share code, notes, and snippets.

@tkellogg
tkellogg / gist:5619461
Created May 21, 2013 12:33
How I installed mono 3 and monodevelop 4 on Ubuntu 13.04 with NuGet and F# support
# Add this line to your software sources
deb http://debian.meebey.net/experimental/mono /
sudo apt-get update
# of course, apt-get remove mono-complete first...
sudo apt-get install mono-complete
# I installed monodevelop from apt just to get all the prereqs
sudo apt-get install monodevelop
@tkellogg
tkellogg / Closure.cs
Created June 25, 2012 04:19
"The anatomy of closures" blog post
class Anon1
{
private int second;
// constructor
public Anon1(int second)
{
this.second = second;
}
@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; }
@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 / 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 / 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 / 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);
}
var css = {
"margin-top": (($(dv).parent().height - $(dv).height()) / 2) + 'px',
"position":"absolute"
};
$(dv).css(css);
$(dv).parent().css('position', 'relative');
@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;
}
@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; }
}