Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
jamesrcounts / IAsyncSaver.cs
Created July 25, 2014 16:12
A more convenient way to write a saver when you want async
// New interface...
using System.Threading.Tasks;
public interface IAsyncSaver<T>
{
Task<T> Save(T item);
}
// Old way...
@jamesrcounts
jamesrcounts / DataQueryAdaptor.cs
Created August 11, 2014 21:54
LINQ to SQL adapter for ApprovalTests
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Linq;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@jamesrcounts
jamesrcounts / EF6.cs
Created August 14, 2014 16:10
EF6 Adapter, works with CodeFirst. Main difference is the namespaces. Also, better error checking
namespace ApprovalTests.Persistence.EntityFramework.Version6
{
using System;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Reflection;
@jamesrcounts
jamesrcounts / WebApiApprovals.cs
Created September 8, 2014 21:12
WebApi Route Test
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using ApprovalTests;
using ApprovalUtilities.Utilities;
@jamesrcounts
jamesrcounts / verifylogs.cs
Last active August 29, 2015 14:06
Verify Log4Net logs
public static void VerifyLog(Action code)
{
var memoryAppender = new MemoryAppender();
BasicConfigurator.Configure(memoryAppender);
code.Invoke();
var aggregate = memoryAppender.GetEvents().Aggregate(
string.Empty,
(s, @event) => s + Environment.NewLine + @event.RenderedMessage);
Approvals.Verify(aggregate);
@jamesrcounts
jamesrcounts / VerifyConfig.cs
Last active August 29, 2015 14:07
Approve app.config
private static void VerifyConfig(string path, Action<Configuration> action)
{
using (var t = new TempFile(Path.GetRandomFileName()))
{
File.Copy(path, t.File.FullName, true);
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = t.File.FullName };
var exeConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
action.Invoke(exeConfig);
var config = File.ReadAllText(exeConfig.FilePath);
Approvals.Verify(config);
@jamesrcounts
jamesrcounts / starter.cmd
Last active August 29, 2015 14:10
My Boxstarter Script
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
choco install VisualStudio2013Ultimate
choco install googlechrome
choco install sublimetext2
choco install console2
choco install sourcecodepro
choco install resharper
choco install stylecop
choco install git-credential-winstore
@jamesrcounts
jamesrcounts / CreateHash.cs
Created December 11, 2014 20:20
Snippet to create a hash as a hex string
public static async Task<string> CreateHash(Stream stream)
{
byte[] b;
using (var ctx = new System.Security.Cryptography.SHA256Managed())
{
var input = await stream.ReadDataAsync();
b = ctx.ComputeHash(input);
}
@jamesrcounts
jamesrcounts / if2hash.java
Created March 12, 2015 06:39
IF to Hash refactoring
//1) Starting code...
Color color;
if (branchLength == 10) {
color = PenColors.Greens.Lime;
} else if (branchLength == 20) {
@jamesrcounts
jamesrcounts / starter.cmd
Created March 20, 2015 16:35
vb6 boxstarter
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
choco install googlechrome
choco install sublimetext2
choco install console2
choco install sourcecodepro
choco install githubforwindows
choco install tortoisemerge
choco install pscx