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 / ExpectedObjectJasmineMatcher.js
Last active August 29, 2015 14:03
Expected Object like approach in Jasmine - Tags - JavaScript JS TDD Spec ExpectedObject Matcher addMatchers 2.0
var customMatchers = {
toInclude: function (util, customEqualityTesters) {
return {
compare: function (actual, expected) {
if (expected === undefined) {
expected = '';
}
var result = {
message: '',
@RhysC
RhysC / UnhandledException.cs
Created May 12, 2014 06:35
Events that you should be using to get UnhandledExceptions
// .NET/CLR app domains
// You - always want to be logging these errors!
AppDomain.CurrentDomain.UnhandledException += (s,e) => {};
// Framework specific handlers
System.Windows.Application.Current.DispatcherUnhandledException += (s,e) => {}; // WPF
System.Windows.Forms.Application.ThreadException += (s,e) => {}; // Windows Forms
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (s,e) => {}; // TPL - not really very imporant
// ASP.NET (i'm guessing you hook into this in your Global.asx?)
@RhysC
RhysC / gist:11362100
Created April 28, 2014 04:54
asafaweb Excessive headers fixes
//On start up :
MvcHandler.DisableMvcResponseHeader = true;
// as an http module/global asax
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
// Remove the "Server" HTTP Header from response - security review recommends against sending this
var app = sender as HttpApplication;
if (app == null || null == app.Context) return;
@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)
@RhysC
RhysC / gist:6006795
Created July 16, 2013 08:15
Make visual studio command prompt available in powershell : just jam this into your profile (http://stackoverflow.com/questions/2124753/how-i-can-use-powershell-with-the-visual-studio-command-prompt)
#Set environment variables for Visual Studio Command Prompt
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
write-host "`nVisual Studio 2012 Command Prompt variables set." -ForegroundColor Yellow