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 / RouteFixture.cs
Created March 5, 2013 09:26
Testing ASP.net MVC routes does not need to be hard or require external testing libraries. this uses XUnit and Nsubstitue. refactoring out the RequestPath and the assertion and you have a very simple test fixture.
public class RouteFixture
{
private readonly HttpContextBase _httpContextMock;
private readonly RouteCollection _routes;
public RouteFixture()
{
_routes = new RouteCollection();
RouteConfig.RegisterRoutes(_routes);
@RhysC
RhysC / build.ps1
Created December 30, 2012 03:49
sample psake script for migrations
Properties {
$build_dir = Split-Path $psake.build_script_file
$build_artifacts_dir = "$build_dir\..\BuildArtifacts\"
$code_dir = "$build_dir\..\"
$soln = "$build_dir\..\AgentHoney.Azure.sln"
$nuget_package_dir = "$build_dir\..\..\Packages"
$database_server = ".\SqlExpress"
$database_instance = "AgentHoney_AutoTestDb"
$ef_tools_ouput = "$build_artifacts_dir\Tools\EF\"
}
@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 / TimeZones.linq
Created November 29, 2012 09:34
Time zones for relevant States
var dt = DateTime.UtcNow;
var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
//TimeZoneInfo.GetSystemTimeZones() - provides timezone identifiers
(from t in new []{
new {Name = "UK", TimeZoneId= "GMT Standard Time"},
new {Name = "WA", TimeZoneId= "W. Australia Standard Time"},
new {Name = "NT", TimeZoneId= "AUS Central Standard Time"},
new {Name = "NSW", TimeZoneId= "E. Australia Standard Time"},
new {Name = "VIC", TimeZoneId= "E. Australia Standard Time"},
new {Name = "ACT", TimeZoneId= "E. Australia Standard Time"},
@RhysC
RhysC / Temcity.linq
Created November 29, 2012 08:55
Team city linq query over http
void Main()
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var results = from project in TeamCityWebRequest.GetTeamCityProjects()
from build in TeamCityWebRequest.GetTeamCityBuilds(project)
select new {project, build};
results.Dump();
}
public class TeamCityWebRequest
@RhysC
RhysC / Sample1.cs
Created October 16, 2012 04:12
Most Simple Relational EF sample
using System;
using System.Collections.Generic;
using System.Data.Entity;
namespace EFConsoleApplication.Basic
{
public class Parent
{
public Parent()
{
@RhysC
RhysC / Sample.cs
Created October 16, 2012 01:22
EF DB Context not persisting Child record
public class Parent
{
public Parent()
{
Children = new HashSet<Child>();
}
public int ParentId { get; set; }
public string Name { get; set; }
public ICollection<Child> Children { get; set; }
}
@RhysC
RhysC / Helpers.ps1
Created August 1, 2011 09:38
String and file helpers
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse |
Select-String -Pattern $pattern |
Select-Object Path |
Get-Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)
@RhysC
RhysC / GetChildFolderTotalSize.Ps1
Created July 18, 2011 20:00
Get all the immediate children folders and tell me their total size
function Get-ChildFolderTotalSize
{
param($parentDir)
$children = (Get-ChildItem $parentDir | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
$results = @();
foreach ($i in $children)
{
$childSum = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
$results += New-Object Object |
@RhysC
RhysC / ConfigTemplateSwitcher.ps1
Created May 5, 2011 10:47
handles swapping out templated values in configs from nested prop files
#config swapper
#load the default values in to a hash
#get the values from the env and override in the hash
#foreach key in the hash replace the {[key]} with the value i.e. (Get-Content $_) -replace "$tokenedKey","$value" | Set-Content -path $_.$env
function Create-ConfigFromTemplate{
param ([string]$envPropFile, #".\$env.properties"
[string]$outputFolder,#".\$env\
[string]$templateFile #".\App.template.config"
)