Skip to content

Instantly share code, notes, and snippets.

@tombatron
tombatron / AutofacExtensions.cs
Last active May 19, 2017 18:22
Setup MediatR, with "decorator" support.
using Autofac;
using Autofac.Features.Variance;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Mediatr.Extras.Autofac
{
using Autofac;
using Autofac.Features.Variance;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using System;
namespace MediatR.Decorator.Example
@tombatron
tombatron / Enumerate.cs
Last active April 18, 2017 10:42
Python's `enumerate` in C# 7.
void Main()
{
var items = new []{ "first", "second", "third" };
foreach(var (item, index) in Enumerate(items))
{
Console.WriteLine($"{item} is index {index}.");
}
}
@tombatron
tombatron / gist:a27a695ff4d9792b621a
Created October 18, 2014 23:42
Custom Command Line Prompt
export PS1="(#\#) @ \d \t : \w \r\n->"
namespace TestingApplication
{
using CommandLine;
using CommandLine.Text;
public class Options
{
[VerbOption("testverbone", HelpText = "Test Verb One.")]
public RssSubOptions RssVerb { get; set; }
@tombatron
tombatron / gist:5173058
Created March 15, 2013 20:58
Archiving only changed files between revisions in hg.
From bash...
hg grep -r rev1:rev2 --all . | cut -d : -f 1 | sort -u | sed 's/^/-I /' | xargs echo hg archive
import random
import numpy
class Cell(object):
x = None
y = None
is_alive = None
_neighbors = None
@tombatron
tombatron / life.py
Last active December 11, 2015 23:58
PyLife
import curses
import random
class Life(object):
max_x = 200
max_y = 60
_grid = {}
@tombatron
tombatron / gist:4416637
Created December 31, 2012 01:22
Decompress zlib'd data
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zlib;
namespace TestZlib
{
class Program
@tombatron
tombatron / gist:4010049
Created November 4, 2012 03:42
A VBScript class for converting Kofax MFA files to regular TIFF files.
Class MfaImageConverter
Private sourceFileStream
Private sourceFileHexStream
Private convertedFileStream
Private convertedFileHexStream
Private Sub Class_Initialize()
Set sourceFileStream = CreateObject("ADODB.Stream")
sourceFileStream.Type = 1 ' Binary