Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / MachineSetup.ps1
Last active May 25, 2016 08:13
Dev machine PC set up **NB* *: You must have your execution policy set to unrestricted for this to work (Set-ExecutionPolicy Unrestricted). There have been reports that RemoteSigned is enough for the install to workUses Chocolatey and PS-Get to do the heavy lifting TAGS chocolatey setup build
$ErrorActionPreference = "Stop"
Set-ExecutionPolicy RemoteSigned
ECHO "Installing PsGet and PS plugins"
iex ((new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1"))
Install-Module pscx
Install-Module psake
ECHO "FINISHED - Installing PsGet and PS plugins - FINISHED"
@RhysC
RhysC / CopyLibFilesAslinksToBgoToYour.Msbuild
Last active May 19, 2016 07:20
Getting pesky linked DLLs in to the bin dir without subfolders (MSBUILD in csproj files)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- pervious msbuild project cruft clipped this is just a .csproj-->
<ItemGroup>
<Content Include="..\OtherProject\libs\**\*.dll">
<Link>libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
<!-- copy after the build so i can have the dlls in a linked lib folder in the project bt in the root in bin -->
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
@RhysC
RhysC / IgnoreUntilFactAttribute.cs
Created March 18, 2016 11:10
Xunit skip/ignore until a given date
//using System;
//using Xunit;
public class IgnoreUntilFactAttribute : FactAttribute
{
public int Year { get; set; }
public int Month { get; set; }
public int Day { get; set; }
public override string Skip
{
@RhysC
RhysC / Dispatch.cs
Created January 5, 2016 08:29
Execute/Dispatch/Call all available methods on the object that can handle the parameter
void Main()
{
new MyObject().Dispatch(new Bar());
/* OUTPUT:
Easy more specific target
Hitting the Bar
Fooing it up
Easy target
*/
}
@RhysC
RhysC / Get-AzureEmulatorErrors.ps1
Created January 13, 2014 02:14
get the warn and errors for the azure emulator log file (assuming pretty std log4net set up)
function Get-AzureEmulatorErrors
{
$LocalApplicationDataPath = [Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)
$AzureResourceRoot = "$LocalApplicationDataPath\dftmp\Resources"
Write-Host "Local Azure Resource Root: $AzureResourceRoot"
pushd "$AzureResourceRoot"
$logs = (dir -Recurse *\directory\LoggingStorage\*.log)
$ErrorAndWarnLines = $logs | Select-String -pattern "\[ERROR\]|\[WARN \]"
$entries = $ErrorAndWarnLines | select LineNumber, `
Line, `
@RhysC
RhysC / 1_MVCHelper.txt
Last active January 2, 2016 16:28
MVC test helpers (.net 4.5) using Log4net, NSubstitute and xUnit. Intend for : - checking attributation of the controller and actions. - asserting ActionResult values in a fluent manner - reducing set up noise for underling type that help form a testable controller
Example usages:
public class MyControllerFixture : IUseFixture<ControllerFixtureInit>
{
private readonly MyController _sut;
private ControllerTestContext _controllerTestContext;
private readonly IMyDependency _dependency;
public MyControllerFixture()
{
@RhysC
RhysC / PartialGlobal.asax
Last active December 31, 2015 19:59
Scratch working of registering Mediator QueryHandlers with Autofac using the Query type interface, not their actual type for ShortBus mediator pattern (https://github.com/mhinze/ShortBus). Why? Because the Query implementations could/should be view models that are Web specific however the contract doesn't care about any of the crap that may be o…
private static void ConfigureContainer()
{
var containerBuilder = new ContainerBuilder();
var assembly = Assembly.GetExecutingAssembly();
containerBuilder.RegisterControllers(assembly);
containerBuilder.RegisterType<Mediator>().As<IMediator>();
containerBuilder.RegisterAssemblyTypes(typeof(CustomerService).Assembly)
.AsImplementedInterfaces();//Will regiter the
@RhysC
RhysC / Azure_GetLastDaysLogsFromStorage.cs
Last active December 31, 2015 02:58
Gets all the blobs in wad-log4net from the last 24 hours (by last mod date). Also can be found here for easy linq pad use : http://share.linqpad.net/hltnqf.linq
void Main()
{
var accounts = new Dictionary<string,string>{
{"accountname", "accountkey"},
};
var latestLogsByAppName = GetLatestLogsByAppName(accounts);
latestLogsByAppName//.Where (l => !l.ApplicationName.Contains("WebRole") )
//.Where(l => l.LastModified < DateTime.UtcNow.AddDays(-1))
.OrderBy (l => l.LastModified)
@RhysC
RhysC / ResponseCodesToEnumValues.cs
Created September 19, 2013 03:43
Turn external response codes into an enum - we are suing this for SMS central (see page 28 for an example http://www.smscentral.com.au/wp-content/uploads/SMS-Central-API-Reference-May-2013.pdf)
void Main()
{
//turn response codes into enum values
var things = GetData().Select (x =>{
var id = GetNumberFromStart(x);
var name = ConvertToVariable(x.Replace(id.ToString(),string.Empty));
return string.Format("{0} = {1},",id,name);
} );
things.Dump();
}
@RhysC
RhysC / WarmUpForGithub.ps1
Last active December 22, 2015 03:28
WarmuP equivalent via power shell, using Github. Will take a zip from a given Git-hub location (https://github.com/{OrgOrUserName}/{Project} and pull it down and swap out the old project name for a new project name. You can now push this to a new origin or do what you will.
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse -exclude *.exe,*.dll,*.pdb,*.jpg,*.png,*.gif,*.mst,*.msi,*.msm,*.gitignore,*.idx,*.pack,*.suo,*.ico,*.nupkg,*.zip,*.7z |
Select-String -Pattern $pattern |
Where-Object { $_ -ne $null } |
Select-Object Path -Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)