Skip to content

Instantly share code, notes, and snippets.

/// <summary>
/// This is just a helper class to make resolving dependencies manually a bit tidier
/// </summary>
public static class WebApiDependencyResolver
{
/// <summary>
/// Use configured WebApi DependencyResolver to resolve dependency of type T.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
@donaldgray
donaldgray / ModelStateTempDataAttribute.cs
Last active December 2, 2015 13:23
ModelState Import/Export
/// <summary>
/// Base class for Import/Export ModelState From/To TempData action filters
/// </summary>
public abstract class ModelStateTempDataAttribute : ActionFilterAttribute
{
protected static readonly string Key = typeof(ModelStateTempDataAttribute).FullName;
}
/// <summary>
/// Import ModelState from previous ActionMethod from TempData
@donaldgray
donaldgray / MachineIdentifier.cs
Created January 12, 2016 23:13
GetMachineIdentifier, used to identify machines in a cluster
using System;
using System.Net.NetworkInformation;
namespace ServiceLayer.Utilities.Identity
{
/// <summary>
/// Class used to get a unique machine identifier
/// </summary>
public static class MachineIdentifier
{
@donaldgray
donaldgray / setHeader.ps1
Created November 7, 2016 09:16
Powershell script for setting IIS header
$PSPath = 'MACHINE/WEBROOT/APPHOST/' + $WebsiteName
$Filter = 'system.webServer/httpProtocol/customHeaders'
# Ensure working with IIS 7 and 7.5(+?)
try {
Add-PSSnapin WebAdministration
}
catch {
try {
Import-Module WebAdministration
@donaldgray
donaldgray / Cake_Teamcity_Metarunner.xml
Created November 10, 2016 08:46 — forked from wwwlicious/Cake_Teamcity_Metarunner.xml
Provides a teamcity metarunner that executes a cake script
<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Cake">
<description>Execute a cake script</description>
<settings>
<parameters>
<param name="mr.Cake.script" value="" spec="text description='The location of the Cake Script, relative to the root folder' display='normal' label='Cake Script:'" />
<param name="mr.Cake.target" value="" spec="text description='The name of the Target within the Cake Script to execute' display='normal' label='Target:'" />
<param name="mr.Cake.verbosity" value="" spec="select data_1='Quiet' data_3='Minimal' data_5='Normal' data_7='Verbose' data_9='Diagnostic' description='The logging level for the Cake Script' display='normal' label='Verbosity:'" />
<param name="mr.Cake.arguments" value="" spec="text description='Additional arguments to pass to Cake Script' display='normal' label='Cake Arguments:'" />
</parameters>
@donaldgray
donaldgray / EscapeSingleUser.sql
Created October 24, 2017 15:34
Script to grab single user mode and set back to multi user. Useful in event of DB in single user but something like polling service grabs connection.
-- Check user with access
SELECT
p.loginame
FROM
sys.databases d
inner join sys.sysprocesses p ON (d.database_id = p.[dbid])
WHERE
d.name = 'database_name'
-- Try to grab database 1000 times
@donaldgray
donaldgray / replaceTfVars.cs
Created December 1, 2017 11:20
Iterates through tfvars file and replaces values with corresponding values from Octopus Deploy.
var varsFile = Octopus.Parameters["tfvarsfile"];
Console.WriteLine("Parsing tfVarsFile: " + varsFile);
if (string.IsNullOrEmpty(varsFile))
throw new ApplicationException("You must provide a tf vars file location");
if (!File.Exists(varsFile))
throw new ApplicationException(string.Format("Specified tf vars file, {0}, not found", varsFile));
string tempFile = string.Concat(varsFile, "-temp");
@donaldgray
donaldgray / DevelopmentNonRunningSchedule.cs
Created March 19, 2018 09:13
DailySchedule for Azure function that will not run if AzureWebJobEnv == "Development"
public abstract class DevelopmentNonRunningSchedule : DailySchedule
{
protected DevelopmentNonRunningSchedule(params string[] times) : base(times)
{
}
protected DevelopmentNonRunningSchedule() : base()
{
}
@donaldgray
donaldgray / DictionaryExtensions.cs
Created July 17, 2018 14:03
A collection Dictionary Extensions for consuming/creating dictionaries
/// <summary>
/// Creates a <see cref="T:System.Collections.Generic.Dictionary`2" /> from an <see cref="T:System.Collections.Generic.IEnumerable`1" /> according to specified key selector and element selector functions.
/// If duplicates keys are present, only the first will be used. Values with duplicate keys will be ignored.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam>
/// <typeparam name="TValue">The type of the value returned by <paramref name="elementSelector" />.</typeparam>
/// <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to create a <see cref="T:System.Collections.Generic.Dictionary`2" /> from.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <param name="elementSelector">A transform function to produce a result element value from each element.</para
@donaldgray
donaldgray / index.js
Created October 3, 2019 08:45
Handler for testing RESTful svc
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
console.log(`${ctx.method} ${ctx.url}`);
const responseCode = ctx.url.startsWith('/') ? ctx.url.substring(1) : 200;
const delay = ctx.response.get('X-Delay-Ms');
if (delay) {
setTimeout(() => {
console.debug('done...');