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
param(
[string]$server = "origin",
[string]$branch = "master"
)
$gitStatus = (Get-GitStatus)
if ($gitStatus -eq $null) {
write-error "Not in a Git repository."
} elseif ($gitStatus.HasUntracked -or $gitStatus.HasWorking -or $gitStatus.HasIndex) {
@bradwilson
bradwilson / Example Output (grouped)
Created November 8, 2012 20:50
find-string.ps1: A PowerShell script to find strings
src\xunit\Sdk\Executor.cs
15: /// ExecutorWrapper instead.
src\xunit.runner.msbuild\Utility\XmlTestRunner.cs
8: public XmlTestRunner(IExecutorWrapper executorWrapper, IRunnerLogger logger)
10: testRunner = new TestRunner(executorWrapper, logger);
src\xunit.runner.msbuild\xunit.cs
98: using (ExecutorWrapper wrapper = new ExecutorWrapper(assemblyFilename, configFilename, ShadowCopy))
src\xunit.runner.msbuild\xunitproject.cs
48: using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy))
src\xunit.runner.tdnet\TdNetRunner.cs
@bradwilson
bradwilson / gist:4215933
Last active August 17, 2020 16:46
.gitconfig
[user]
name = Brad Wilson
email = dotnetguy@gmail.com
[alias]
a = add -A
abort = rebase --abort
amend = commit --amend -C HEAD
bl = blame -w -M -C
br = branch
cat = cat-file -t
[Fact]
public void Monkey()
{
string schema =
@"{
""id"": ""System.Version"",
""type"": ""object"",
""additionalProperties"": false,
""properties"": {
""Major"": {
@bradwilson
bradwilson / get-hash.ps1
Created January 31, 2013 04:32
Hashing function for PowerShell
param(
[string]$pattern = "*.*",
[ValidateSet("md5", "sha1", "sha256", "sha384", "sha512")]$algorithm = "sha1",
[switch]$recurse
)
[Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null
if ($algorithm -eq "sha1") {
$hashimpl = new-Object System.Security.Cryptography.SHA1Managed
@bradwilson
bradwilson / NameTaskReturningMethodAppropriately.cs
Last active December 15, 2015 11:09
FxCop rule to ensure that Task-returning methods are suffixed with 'Async'
using System.Runtime.CompilerServices;
using Microsoft.FxCop.Sdk;
namespace Tier3.FxCop.TaskRules
{
public class NameTaskReturningMethodAppropriately : BaseIntrospectionRule
{
public NameTaskReturningMethodAppropriately() :
base("NameTaskReturningMethodAppropriately",
"Tier3.FxCop.Rules",
@bradwilson
bradwilson / gist:6232391
Created August 14, 2013 15:53
IIndexedEnumerable (a non-grouped replacement for ILookup)
using System;
using System.Collections.Generic;
using System.Linq;
public interface IIndexedEnumerable<TKey, TValue>
{
TValue this[TKey key] { get; }
int Count { get; }
@bradwilson
bradwilson / AutoMockWebApiAttribute.cs
Created August 22, 2013 17:56
Auto-mock setup for Web API
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using NSubstitute;
Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:line 22
at Ninject.Activation.Caching.GarbageCollectionCachePruner.PruneCacheIfGarbageCollectorHasRun(Object state) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Caching\GarbageCollectionCachePruner.cs:line 83
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at
@bradwilson
bradwilson / StandardTestKernel.cs
Created September 24, 2013 23:25
This is a very hacked together replacement kernel for when your tests are making lots of kernels across many threads, and you hit stack traces like these: https://gist.github.com/bradwilson/6691434 . It's not pretty, but it does the job. It steals the implementation of the cache pruner that's built into Ninject and wraps locks around manipulatio…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Ninject.Activation.Caching;
using Ninject.Components;
using Ninject.Modules;
namespace Ninject
{