Skip to content

Instantly share code, notes, and snippets.

@mhinze
mhinze / BaseController.cs
Created November 19, 2013 19:43
BaseController.cs with Async
using System.Threading.Tasks;
using System.Web.Mvc;
using JetBrains.Annotations;
using ShortBus;
public abstract class BaseController : Controller
{
public IMediator Mediator { get; set; }
protected Response<TResult> Query<TResult>(IQuery<TResult> query)
@mhinze
mhinze / gist:123732
Created June 4, 2009 17:34
git svn workflow
# adapted from http://notes.jimlindley.com/2008/3/25/git-svn-that-works-for-me
# initial setup
git svn clone <svn_repo>
# begin the workflow
git svn fetch -r HEAD --ignore-paths="Package.zip" # aliased to 'git up', my Package.zip is very large.
git svn rebase -l # we just updated, no need to go back to the svn repo
# 99% of daily workflow
public static bool IsSubclassOfOpenGeneric(this Type type, Type generic)
{
// fine!
return type != typeof(object) &&
(generic == (type.IsGenericType ? type.GetGenericTypeDefinition() : type) ||
type.BaseType.IsSubclassOfOpenGeneric(generic));
}
@mhinze
mhinze / subroute-slack.cs
Last active June 6, 2016 20:00
slack subroute.io
using System;
using System.Net;
using Subroute.Common;
using System.Configuration;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
// Slack webhook example
namespace Subroute.Container
{
@mhinze
mhinze / README.txt
Created March 17, 2016 21:31 — forked from mattweber/README.txt
ElasticSearch Multi-Select Faceting Example
This is an example how to perform multi-select faceting in ElasticSearch.
Selecting multiple values from the same facet will result in an OR filter between each of the values:
(facet1.value1 OR facet1.value2)
Faceting on more than one facet will result in an AND filter between each facet:
(facet1.value1 OR facet1.value2) AND (facet2.value1)
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh).
@mhinze
mhinze / EntityFrameworkExtensions.cs
Created January 8, 2014 16:03
A useful little EF extension method
using System;
using System.Data.Entity;
public static class EntityFrameworkExtensions
{
/// <summary>
/// Given an id, creates a reference to an existing (persisted) *unchanged* entity
/// </summary>
/// <typeparam name="TEntity">Entity CLR type</typeparam>
/// <param name="db">DbContext</param>
@mhinze
mhinze / BaseController.cs
Last active December 27, 2015 16:29
Sample ShortBus BaseController
using System.Web.Mvc;
using JetBrains.Annotations;
using ShortBus;
public abstract class BaseController : Controller
{
public IMediator Mediator { get; set; }
protected Response<TResult> Query<TResult>(IQuery<TResult> query)
{
@mhinze
mhinze / PropsShouldMatch.cs
Created September 30, 2013 18:15
All properties should match assertion based on Rhino.Mocks AllPropertiesMatchConstraint
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public static class ShouldExtensions
{
/// <summary>
@mhinze
mhinze / Delete-BinObj.ps1
Last active December 23, 2015 19:59
Delete-BinObj.ps1
function global:Delete-BinObj()
{
$path = join-path $solutionScriptsContainer '..' -resolve
Get-ChildItem $path -include bin,obj -recurse -Force | remove-item -force -recurse
}
public class CustomConvention : Convention
{
public CustomConvention()
{
Cases.Where(StartsWith("should", "it"));
FixtureExecution.CreateInstancePerFixture();
InstanceExecution.SetUpTearDown(StartsWithWhen(), StartsWithAfter());
}