Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
jamesrcounts / .gitattributes
Created June 25, 2012 01:35
A Finite State Machine to accept even length strings of 0s and 1s. Written at SoCalCodeCamp San Diego, 6/24/2012. Details, Video, Slides: http://wp.me/p1HYUa-80
# Disable LF normalization for all files
* -text
@jamesrcounts
jamesrcounts / README.md
Created July 2, 2012 01:52
Patch for VisualStudioReporter

Alternate method seems to work more reliably. Old version only works under MSTEST, since the module we looked for was an MSTEST module. This version gets the parent process and checks if the parent process was VS11. Actually old version isn't working for me under MSTEST either, not sure when it stopped working since I haven't been using VS2012 much.

I should say that it doesn't work with FirstWorkingReporter. It works when used directly.

@jamesrcounts
jamesrcounts / README.md
Created July 7, 2012 01:32
String.Contains, C# Finite State Machine Implementation

String.Contains C# Edition

I enjoy playing with state machines. They are simple enough to implement quickly, and complex enough to give the implementation language a little workout. Followers of this blog will know that I've enjoyed using Finite State Machines to explore CoffeeScript.

But, when I look at the search terms leading to my blog, I see that people want to see FSMs implemented in C#, C++, or even VB. About the only language I haven't seen people looking for is CoffeeScript. I'm not too suprised, since most people searching for FSM implementations are probably students trying to cheat on thier homework. I doubt any professors are accepting CoffeeScript implemenations.

When I see these search results, I consider quickly posting a solution in the requested language. I don't mind if students crib solutions from me. I'm a big believer in learning by example. Certainly if by looking at my FSMs I can save one student from writing a switch statement, then I'll consider it a public serv

@jamesrcounts
jamesrcounts / CassiniReporter.cs
Created July 20, 2012 13:49
MvcReporter for MvcApprovals which use self-hosted webserver
namespace ApprovalTests.Reporters
{
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using ApprovalTests.Asp.CassiniDev;
using ApprovalTests.Core;
@jamesrcounts
jamesrcounts / DemoForm.cs
Created August 8, 2012 15:29
WinForms+EventApprovals
using System;
using System.Windows.Forms;
namespace ApprovalUtilities.Tests.Reflection
{
public partial class DemoForm : Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox checkBox1;
@jamesrcounts
jamesrcounts / FormatCommand.cs
Created September 7, 2012 17:11
A text formatter for SqlCommand instances
/// <summary>
/// Formats the command.
/// </summary>
/// <param name="command">The command.</param>
/// <returns>A formatted <see cref="SqlCommand"/></returns>
private static string FormatCommand(SqlCommand command)
{
string result = command.CommandText + Environment.NewLine;
result = string.Format("{0}{{{1}", result, Environment.NewLine);
foreach (var item in command.Parameters)
@jamesrcounts
jamesrcounts / TheoryApprover.cs
Created October 2, 2012 03:25
A dumbed down version of FileApprover, that makes Verifying two arbitrary text files easier.
public class TheoryApprover : IApprovalApprover
{
private readonly string approved;
private readonly string received;
private ApprovalException failure;
public TheoryApprover(string approved, string received)
{
this.received = received;
this.approved = approved;
@jamesrcounts
jamesrcounts / AutoTestReporter.cs
Created February 14, 2013 22:01
A MightyMoose reporter suitable for front loading.
using System.Linq;
using ApprovalTests.Core;
namespace ApprovalTests.Reporters
{
public class AutoTestReporter : IEnvironmentAwareReporter
{
public static readonly AutoTestReporter INSTANCE = new AutoTestReporter();
public void Report(string approved, string received)
@jamesrcounts
jamesrcounts / EmptyIfNull.cs
Created August 20, 2013 17:15
Don't get bit by null collections
public static IEnumerable<TMembers> EmptyIfNull<TMembers>(this IEnumerable<TMembers> source)
{
return source ?? Enumerable.Empty<TMembers>();
}
@jamesrcounts
jamesrcounts / StackTraceScrubber.cs
Last active December 23, 2015 07:39
Methods to scrub stack traces, and a Verifier that applies the scrubbers as a workaround until Approvals.Verify gets support for scrubbers.
public static class StackTraceScrubber
{
public static string ScrubAnonymousIds(string source)
{
var regex = new Regex(@"\w+__\w+");
return regex.Replace(source, string.Empty);
}
public static string ScrubLineNumbers(string source)
{