Skip to content

Instantly share code, notes, and snippets.

View mikeminutillo's full-sized avatar
🏠
Working from home

Mike Minutillo mikeminutillo

🏠
Working from home
View GitHub Profile
@mikeminutillo
mikeminutillo / Permute.cs
Created October 27, 2011 12:57
Permutations - writing LISP in C#
public static class Extensions
{
public static IEnumerable<IEnumerable<T>> Permute<T>(this IEnumerable<T> items)
{
var isEmpty = true;
foreach (var item in items)
{
isEmpty = false;
foreach (var p in items.Except(item.Yield()).Permute())
yield return item.Yield().Concat(p);
@mikeminutillo
mikeminutillo / rxhelper.cs
Created February 20, 2012 06:15
Extnesion method for Rx-ification
public static class Async
{
public static Func<Task<T>> Make<T>(Action<TaskCompletionSource<T>> action)
{
var completionSource = new TaskCompletionSource<T>();
action(completionSource);
return completionSource.Task;
}
@mikeminutillo
mikeminutillo / extract.xml
Created March 21, 2012 06:09
Simple DSL for defining Document structures from Relational Data
<?xml version="1.0" encoding="UTF-8"?>
<Extract>
<Orders>
<Order DateCreated="2012-03-21" CustomerNumber="1234">
<OrderLine Qty="2" UnitPrice="15.00" ProductCode="TAC123" />
<OrderLine Qty="45" UnitPrice="0.15" ProductCode="TAC321" />
</Order>
<Order DateCreated="2012-03-21" CustomerNumber="5678">
<OrderLine Qty="9" UnitPrice="27.00" ProductCode="TAC987" />
</Order>
@mikeminutillo
mikeminutillo / Bootstrap.cs
Created August 8, 2012 07:29
Use Fake implementations at debug time
var builder = new ContainerBuilder();
builder.AddModule(new ModuleA());
builder.AddModule(new ModuleB());
builder.AddModule(new DebugFakesModule());
var container = builder.Build();
// Will be FakeEmailService if compiled with DEBUG
@mikeminutillo
mikeminutillo / DataDictionary.cs
Created August 10, 2012 08:46
LINQPad DataDictionary
var ignoredColumns = new[] {
"CreatedBy",
"CreatedDate",
"ModifiedBy",
"ModifiedDate",
"LogicallyDeletedBy",
"LogicallyDeletedDate",
"LastModified"
};
@mikeminutillo
mikeminutillo / Core.cs
Created September 18, 2012 07:55
Arbitrary Attachments on Arbitrary Objects
interface IHaveAttachments { }
interface IAttachment<T> where T : IHaveAttachments {
void AttachTo(T obj);
}
class AttachmentsModule : Autofac.Module
{
private static readonly MethodInfo _attach = typeof(AttachmentsModule).GetMethod("Attach", BindingFlags.Static | BindingFlags.NonPublic);
@mikeminutillo
mikeminutillo / gist:4015997
Created November 5, 2012 08:23
How to determine the Wednesday's in a given date range
void Main()
{
var start = new DateTime(2012, 10, 1);
var end = new DateTime(2012, 10, 31);
var days = from d in start.UpTo(end)
where d.DayOfWeek == DayOfWeek.Wednesday
select d;
@mikeminutillo
mikeminutillo / gist:4016067
Created November 5, 2012 08:38
How to split a list into ‘chunks’ (Fun Code)
void Main()
{
var items = new List<string>{ "A", "B", "C", "D", "E", "F", "G", "H", "I" };
items.Chunk(2).Dump();
}
public static class Ext
{
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunkSize)
@mikeminutillo
mikeminutillo / gist:4212342
Created December 5, 2012 04:52
Dynamic Dispatch
void Main()
{
DoTheThing(1);
DoTheThing(2);
DoTheThing("Banana");
}
public static void DoTheThing(object o)
{
DoTheThingInternal((dynamic)o);
@mikeminutillo
mikeminutillo / CalendarDates.cs
Last active December 10, 2015 14:39
A way to generate the dates that need to appear on a calendar page
void Main()
{
var refDate = DateTime.Today.AddMonths(-1);
var start = refDate.StartOfMonth().Backwards().FirstOrDefault (d => d.DayOfWeek == DayOfWeek.Monday);
var end = refDate.EndOfMonth().Forwards().FirstOrDefault (d => d.DayOfWeek == DayOfWeek.Sunday);
start.UpTo(end).ToArray().Dump();
}