Skip to content

Instantly share code, notes, and snippets.

View davidwhitney's full-sized avatar
🍸
You're all wonderful. That's what's happening.

David Whitney davidwhitney

🍸
You're all wonderful. That's what's happening.
View GitHub Profile
@davidwhitney
davidwhitney / setup.ps1
Last active April 10, 2024 10:54
Machine setup chocolatey script
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n allowGlobalConfirmation
choco install notepad2
choco install notepadplusplus
choco install 7zip
choco install paint.net
choco install autoruns
choco install vcredist140
choco install dotnetfx
@davidwhitney
davidwhitney / gilded-rose.ts
Last active October 21, 2019 23:09
A Typescript version of the guilded rose
export class Item {
name: string;
sellIn: number;
quality: number;
constructor(name: string, sellIn: number, quality: number) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
@davidwhitney
davidwhitney / LICENSE.txt
Last active October 7, 2019 21:14
A Tiny Typescript mocking... um... library? class? That doesn't annoy me, and doesn't cause Typescript linters to get confused or fill your code up with :anys. The license is MIT.
Copyright (c) 2019 David Whitney
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@davidwhitney
davidwhitney / Container.java
Last active September 6, 2019 06:15
Container.java - a feature rich DI container in 339 LOC
package com.electricheadsoftware.tinycontainer;
import lombok.Data;
import lombok.Getter;
import lombok.var;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@davidwhitney
davidwhitney / RowWithSchema.java
Last active March 26, 2019 11:27
Create Spark Row in Java for tests etc
package com.gfk.igl.insights.processor.spark.builders;
import lombok.var;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema;
import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
class Program
{
static void Main(string[] args)
{
var spinner = new Spinner();
spinner.Start(0, 0);
Console.WriteLine("Hello World!" + Console.BufferHeight);
Console.WriteLine("Hello World!" + Console.BufferHeight);
using System;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Routing;
using Microsoft.Owin.Hosting;
using Owin;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace Pen.Loader
{
public class QuillData
{
public QuillData(string dbrFilePath)
{

How stuff works – meta-programming in C# 101

We live in a world where our tools, frameworks and libraries are often built for us. Especially in .NET, we rely on ASP.NET MVC, DI Containers, Unit testing tools and IDEs and all of these things sell themselves on hiding complexity and being "hard problems".

In this session, I want to explain how all these big tools and frameworks aren't really that different, and are built using the same language and practices that you using in your user-land code every day.

We'll break down how all that stuff works - MVC, Test frameworks and containers - illustrating how it's all just meta-programming with reflection, and hopefully leave you with practical tips for implementing strong conventions, discovery, and implementing composition in your own code bases.

@davidwhitney
davidwhitney / Container.cs
Created February 3, 2016 11:15
Kata example for IoC
public class Container
{
private readonly Dictionary<Type, Type> _simpleMappings = new Dictionary<Type, Type>();
public T Create<T>()
{
return (T) Create(typeof (T));
}
public object Create(Type t)