Skip to content

Instantly share code, notes, and snippets.

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 / table-emptying-order.sql
Created October 5, 2014 19:43
SqlServer - list tables in delete/truncate order.
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
@drunkcod
drunkcod / gist:2351063
Created April 10, 2012 12:32
Dynamically add 'require' to any function
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(',');
@drunkcod
drunkcod / gist:4488313
Last active December 10, 2015 20:28
a rough but workable way to "inject" contract tests into a NUnit fixture
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NUnitBehavesLike
{
public interface IThingamabob
{
@drunkcod
drunkcod / EntitySupport.cs
Created September 3, 2013 15:18
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.
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 / fake-vs-stub.cs
Created November 27, 2016 19:21
Supersimple Mock/Fake Proxy vs handrolled
/* using FakeItEasy and Cone */
interface ICandy { }
interface ICandyShop
{
ICandy GetTopSellingCandy();
void BuyCandy(ICandy candy);
}
class SweetTooth