Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
jamesrcounts / DevEnvDiffReporter.cs
Created March 16, 2012 02:36
A VS 11 DiffReporter for ApprovalTests
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ApprovalTests.Reporters
{
public class DevEnvDiffReporter : GenericDiffReporter
{
@jamesrcounts
jamesrcounts / BeyondCompareReporter.cs.patch
Created March 19, 2012 15:15
A patch that corrects GetPathInProgramFilesX86 behavior in a process compiled for x86
Index: BeyondCompareReporter.cs
===================================================================
--- BeyondCompareReporter.cs (revision 378)
+++ BeyondCompareReporter.cs (working copy)
@@ -20,7 +20,7 @@
public static string GetPathInProgramFilesX86(string path)
{
var x86Path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\" + path;
- return File.Exists(x86Path) ? x86Path : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\" + path;
+ return File.Exists(x86Path) ? x86Path : Environment.GetEnvironmentVariable("ProgramW6432") + @"\" + path;
@jamesrcounts
jamesrcounts / CodeCompareReporter.patch
Created March 27, 2012 16:25
A DevArt CodeCompare DiffReporter for ApprovalTests
Index: ApprovalTests.sln
===================================================================
--- ApprovalTests.sln (revision 392)
+++ ApprovalTests.sln (working copy)
@@ -4,7 +4,7 @@
ProjectSection(SolutionItems) = preProject
ApprovalTests.build = ApprovalTests.build
ApprovalTests.vsmdi = ApprovalTests.vsmdi
- ApprovalTests3.vsmdi = ApprovalTests3.vsmdi
+ ApprovalTests1.vsmdi = ApprovalTests1.vsmdi
@jamesrcounts
jamesrcounts / README.md
Created April 20, 2012 17:09
A coffeescript finite state machine, just for fun. This machine implements a string.Contains() function.

Finite State Machine Revisited

This machine determines if a specified substring exists within a string. The initial machine is the first machine I wrote in CoffeeScript, so there should be plenty of room for improvement.

Also interesting, I think there is an opportunity for some meaningful use of CoffeeScript classes.

First we'll add a shim for alert.

alert = (value) -> console.log value
@jamesrcounts
jamesrcounts / pda.coffee
Created April 21, 2012 16:10
A pushdown automata in coffeescript
createResult = (state, symbols) -> {
resultState: state
pushSymbols: symbols.reverse()
}
createRule = (state, input, symbol, result) -> {
currentState: state
inputChar: input
stackSymbol: symbol
ruleResult: result
@jamesrcounts
jamesrcounts / turing.coffee
Created April 23, 2012 22:42
A turing machine in coffeescript
alert = (s) -> console.log s
createResult = (state, symbol, direction) ->
nextState: state
writeSymbol: symbol
moveTo: direction
toString: () -> [this.nextState, this.writeSymbol, this.moveTo].join ", "
createRule = (state, symbol, result) ->
inState: state
@jamesrcounts
jamesrcounts / WriteOnlyProperty.patch
Created May 2, 2012 17:16
A patch to handle Write-Only properties in WritePropertiesToString<T>. Are write only properties a good idea? I don't know. Did I find one in legacy code? Yes. Did I write that legacy code? Yes.
Index: ApprovalUtilities.Tests/Utilities/StringUtilitiesTest.cs
===================================================================
--- ApprovalUtilities.Tests/Utilities/StringUtilitiesTest.cs (revision 408)
+++ ApprovalUtilities.Tests/Utilities/StringUtilitiesTest.cs (working copy)
@@ -26,12 +26,34 @@
[TestMethod]
public void WritePropertiesToStringTest()
{
- var anonymous = new
+ var anonymous = new
@jamesrcounts
jamesrcounts / Examples.txt
Created June 12, 2012 22:53
A patch that updates ScrubPath to handle when the "text" parameter is null.
// I expected scrub path to handle null input. There is no reason to let the
// NullReferenceException to propogate, since Verify can handle nulls.
// This test will pass or fail based on the contents of approved.txt
[TestMethod]
public void MyTestMethod()
{
string file = null;
ApprovalTests.Approvals.Verify(file);
}
@jamesrcounts
jamesrcounts / 1-ndc2011.coffee
Created June 21, 2012 21:03 — forked from anoras/1-ndc2011.coffee
NDC 2011 - Wake Up and Smell The Coffee
# This file contains brushed up version of all the examples [Anders Norås] programmed live during the talk.
# CoffeeScript compiles to JavaScript
numbers = [1,2,3,4] # No need for semicolons!
location = conference = "NDC 2011" # Multiple assigns.
awake = false
console.log location # No need for parens!
# Run, Build
@jamesrcounts
jamesrcounts / InlineTask.targets.xml
Created June 22, 2012 11:53 — forked from bradwilson/InlineTask.targets.xml
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" />