Skip to content

Instantly share code, notes, and snippets.

View motowilliams's full-sized avatar

Eric Williams motowilliams

View GitHub Profile
@motowilliams
motowilliams / VSBouncer.cs
Created February 13, 2012 23:47
Test craplet to look at closing solution, change branch, open solution
using System;
using EnvDTE;
namespace VSBouncer
{
class Program
{
static void Main(string[] args)
{
var command = args[0];
@motowilliams
motowilliams / ServiceStackTextFormatter.cs
Created February 22, 2012 04:03
aspnet web api json MediaTypeFormatter using Servicestack.Text
public class ServiceStackTextFormatter : MediaTypeFormatter
{
public ServiceStackTextFormatter()
{
// Fill out the mediatype and encoding we support
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
Encoding = new UTF8Encoding(false, true);
}
protected override Task<object> OnReadFromStreamAsync(Type type, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext)
@motowilliams
motowilliams / gist:1881448
Created February 22, 2012 04:36 — forked from half-ogre/NuGet.targets.xml
An MSBuild target to add to your project files that will restore packages *if* nuget.exe is available via the PATH environment variable.
<!-- add this target to *each* project file, and modify the BeforeBuild target that's already in the project file (usually commented out) to depend on it -->
<Target Name="RestoreNuGetPackages" Condition="Exists('.\packages.config')">
<!-- try to execute `nuget help` to see if it's available from what's in the PATH -->
<Exec Command="cmd.exe /c nuget help &gt; NUL" IgnoreExitCode="True">
<Output TaskParameter="ExitCode" PropertyName="NuGetExitCode"/>
</Exec>
<!-- raise an error if nuget.exe wassn't available from what's in the PATH -->
<Error Text="Failed to execute nuget.exe; please make sure your PATH environment variable provides a path to nuget.exe." Condition="'$(NuGetExitCode)' != '' and '$(NuGetExitCode)' > '0'" />
<!-- restore packages -->
<Exec Command="nuget install .\packages.config -o $(SolutionDir)\packages" />
using System;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ContactManager.Models;
namespace ContactManager.Controllers
{
public class ContactController : ApiController
{
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ContactManager.Models;
namespace ContactManager.Controllers
{
public class ContactsController : ApiController
@motowilliams
motowilliams / NuGet.targets.xml
Created March 12, 2012 23:52 — forked from bradwilson/InlineTask.targets.xml
Inline MSBuild task to download NuGet.exe - NuGet.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
@motowilliams
motowilliams / gist:2026429
Created March 13, 2012 03:25 — forked from darrelmiller/gist:2026145
ThroughputMessageHandler
public class ThroughputMessageHandler : DelegatingHandler
{
private readonly ILogger _logger;
private Timer _timer;
private int _count;
public ThroughputMessageHandler(ILogger logger)
{
_logger = logger;
_count = 0;
_timer = new Timer(new TimerCallback(timerCallback),null,1000,1000);
using System;
using EnvDTE;
namespace VSBouncer
{
class Program
{
static void Main(string[] args)
{
var command = args[0];
@motowilliams
motowilliams / ItemBuild.cshtml
Created May 22, 2012 22:09
li helper to look at the requested route and add a 'selected' css class to the li tag
@helper ItemBuild(string menuItemText, string controllerName, string actionName){
var controller = ViewContext.Controller.ValueProvider.GetValue("controller").RawValue;
var action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue;
<li @(controller.Equals(controllerName) && action.Equals(actionName) ? "class=selected" : string.Empty)>@Html.ActionLink(menuItemText, actionName, controllerName)</li>}
@motowilliams
motowilliams / gist:2892716
Created June 8, 2012 00:47
mv versus git mv
md RenameTest
cd RenameTest
git init
md FolderV1
echo Test1 > FolderV1\FileV1.txt
echo Test2 > FolderV1\FileV2.txt
git add -A
git commit -m "inital commit"
(git) mv FolderV1\FileV1.txt FolderV1\FileV1a.txt
(git) mv FolderV1\FileV2.txt FolderV1\FileV2a.txt