Skip to content

Instantly share code, notes, and snippets.

View bradwilson's full-sized avatar
🤘
All metal, all the time!

Brad Wilson bradwilson

🤘
All metal, all the time!
View GitHub Profile
@bradwilson
bradwilson / InlineTask.targets.xml
Created March 11, 2012 00:41
Inline MSBuild task to download NuGet.exe
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
@bradwilson
bradwilson / gist:2229275
Created March 28, 2012 18:41
Scorch PowerShell script for mixed Git/TFS environments
& taskkill /f /im msbuild.exe
if ((get-gitstatus) -ne $null) {
& git clean -xdf -e *.suo -e packages/*
} else {
& tfpt scorch . /recursive /deletes /diff /noprompt /exclude:"*.suo,.\packages"
}
@bradwilson
bradwilson / gist:2417226
Created April 18, 2012 22:55
Ninject dependency resolver for Web API
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Web.Http.Dependencies;
using Ninject;
using Ninject.Syntax;
public class NinjectDependencyScope : IDependencyScope
{
private IResolutionRoot resolver;
@bradwilson
bradwilson / Console.xml
Created May 1, 2012 23:15
console.xml for Console2
<?xml version="1.0"?>
<settings>
<console change_refresh="10" refresh="100" rows="35" columns="160" buffer_rows="9999" buffer_columns="0" shell="" init_dir="" start_hidden="1" save_size="0">
<colors>
<color id="0" r="48" g="48" b="48"/>
<color id="1" r="0" g="0" b="128"/>
<color id="2" r="0" g="150" b="0"/>
<color id="3" r="0" g="150" b="150"/>
<color id="4" r="174" g="87" b="0"/>
<color id="5" r="128" g="0" b="128"/>
@bradwilson
bradwilson / My.Types.ps1xml
Created May 2, 2012 03:54
My profile.ps1 (and several related scripts)
<Types>
<Type>
<Name>System.String</Name>
<Members>
<ScriptProperty>
<Name>ToBase64</Name>
<GetScriptBlock>
[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($this))
</GetScriptBlock>
</ScriptProperty>
[alias]
co = checkout
st = status
br = branch
re = rebase
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
cat = cat-file -t
type = cat-file -t
dump = cat-file -p
[color "branch"]
@bradwilson
bradwilson / InvalidModelStateFilterAttribute.cs
Created June 3, 2012 02:58
A filter for ASP.NET Web API to return 400 upon invalid model binding
using System;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class InvalidModelStateFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
@bradwilson
bradwilson / reset.ps1
Created June 7, 2012 17:51
reset.ps1
git reset --hard head
git clean -xdf -e *.suo -e packages/*
git checkout $args
@bradwilson
bradwilson / net40.cs
Created August 21, 2012 03:15
Alternate implementation of WriteToStreamAsync
public override Task WriteToStreamAsync(Type type, object value,
Stream stream,
HttpContent content,
TransportContext transportContext)
{
if (string.IsNullOrEmpty(JsonpCallbackFunction))
return base.WriteToStreamAsync(type, value, stream, content, transportContext);
StreamWriter writer = null;