Skip to content

Instantly share code, notes, and snippets.

#lang racket
(require pict
rackunit)
; left and right are (or/c choice? team?)
; winner is (or/c #f team?)
(struct choice (left right winner) #:transparent)
(struct team (name strength) #:transparent)
@default-kramer
default-kramer / slides.rkt
Created August 9, 2018 02:13
Talk I gave about Contracts vs Types
#lang slideshow
(require slideshow/code)
(set-margin! 20)
(current-font-size 36) ; default is 32
(slide
#:title "My Perspective"
(item "A long-time fan of static types")
(item "Respect that very good programmers disagree")
@default-kramer
default-kramer / DapperCombination.cs
Created April 27, 2016 18:16
combining two individually-defined dapper queries
interface IDapperQuery<out TResult>
{
string GetSql();
DynamicParameters GetParameters(); // <--- can't make this work
IDictionary<string, object> GetParametersAsDict(); // this works
TResult MapResult(SqlMapper.GridReader reader);
}
// Combines both queries for one DB round trip
class CombinedQuery<T1, T2> : IDapperQuery<Tuple<T1, T2>>
if exists(select * from INFORMATION_SCHEMA.ROUTINES where ROUTINE_NAME = 'DropView')
drop procedure DropView;
go
create procedure DropView
@viewname varchar(99)
as
if exists(select * from INFORMATION_SCHEMA.VIEWS where TABLE_NAME = @viewname)
exec('drop view ' + @viewname);
go
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Autofac;
using Autofac.Core;
using System.Reflection;
using System.Linq.Expressions;
namespace test_autofac_generic_source
[TestMethod]
public void terse_test()
{
doTheTest();
// bucket # 01 02 03 04 05 06 07 08 09 10 11 12
Assert.AreEqual(" | | 4| | 4|10| | 6| | 4| |10", TerseString());
}
// the code under test fills these buckets
private int?[] buckets;
[TestMethod]
public void verbose_test()
{
doTheTest();
Assert.IsNull(buckets[0]);
Assert.IsNull(buckets[1]);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using System.Reflection.Emit;
using System.Linq.Expressions;
namespace Mixer.Tests
class A<T>
{
public string Foo { get { return "hello"; } }
}
class B<T> : A<T> { }
// this is OK (because A's generic parameter doesn't go to its base class?)
class Ok<T> : A<Ok<T>> { }
@default-kramer
default-kramer / NLog.config
Created October 10, 2013 14:34
NLog rolling
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true">
<!-- make sure to set 'Copy To Output Directory' option for this file -->
<!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->
<targets>
<target name="file" xsi:type="File"