Skip to content

Instantly share code, notes, and snippets.

@drunkcod
drunkcod / fake-vs-stub.cs
Created Nov 27, 2016
Supersimple Mock/Fake Proxy vs handrolled
View fake-vs-stub.cs
/* using FakeItEasy and Cone */
interface ICandy { }
interface ICandyShop
{
ICandy GetTopSellingCandy();
void BuyCandy(ICandy candy);
}
class SweetTooth
@drunkcod
drunkcod / table-emptying-order.sql
Created Oct 5, 2014
SqlServer - list tables in delete/truncate order.
View table-emptying-order.sql
with tab(object_id, level, ref_id) as (
select t.object_id, 0, null
from sys.tables t
where t.type = 'U'
union all
select fk.parent_object_id, level + 1, t.object_id
from tab t
inner join sys.foreign_keys fk on fk.referenced_object_id = t.object_id
)
select
View ACE-Bio
Torbjörn is a organizational debugger, developer, architect, hugger and
collector of ideas.He has a deep belief in the untapped potential of folks
and the power of mutually meeting needs to improve the way work works.
Manager by day @drunkcod by night.
@drunkcod
drunkcod / EntitySupport.cs
Created Sep 3, 2013
So I wanted a general enough way to get the id columns from my entities. This is either Paula Bean brilliant or glorious. I don't know which.
View EntitySupport.cs
static class EntitySupport
{
class IdentityGetter<TEntity>
{
public readonly static Func<TEntity,int> Instance = GetIdentityGetter<TEntity>();
}
public static Func<TEntity,int> GetIdentityGetter<TEntity>()
{
var id = typeof(TEntity).GetMembers()
@drunkcod
drunkcod / gist:4488313
Last active Dec 10, 2015
a rough but workable way to "inject" contract tests into a NUnit fixture
View gist:4488313
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NUnitBehavesLike
{
public interface IThingamabob
{
@drunkcod
drunkcod / gist:2351063
Created Apr 10, 2012
Dynamically add 'require' to any function
View gist:2351063
function addRequire(target) {
while(target.next){ target = target.next; }
function requireArguments() {
var args = requireArguments.args;
for(var i = 0; i != args.length; ++i) {
require(arguments[i], args[i]);
}
return requireArguments.next.apply(this, arguments);
}
requireArguments.args = /\((.*?)\)/.exec(target.toString())[1].replace(' ','').split(',');