Skip to content

Instantly share code, notes, and snippets.

@haydosw
haydosw / .Net Topshelf Service Installer
Created March 12, 2015 03:09
Simple script to scan the .\bin directory, look for Topshelf service executable (very basic *.exe scan) and install. (http://docs.topshelf-project.com/en/latest/overview/faq.html#what-about-command-line-arguments)
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
{
@haydosw
haydosw / Force SSL-Always for NancyFx requests
Last active April 28, 2016 22:26
Force SSL-Always for NancyFx requests
public class AlwaysUseHttps : IApplicationStartup
{
private readonly IConfigurationService _config;
public AlwaysUseHttps(IConfigurationService config)
{
_config = config;
}
public void Initialize(IPipelines pipelines)
@haydosw
haydosw / Fluent Validator Engine.cs
Last active August 29, 2015 14:26
Fluent Validator Engine - Helper class to find all validators and provide a common way of validating objects.
/// <summary>
/// Helper class to find all validators and provide a common way of validating objects.
/// </summary>
public class ValidationEngine
{
private static readonly Dictionary<Type, IValidator> AllValidatorsInAssembly;
static ValidationEngine()
{
AllValidatorsInAssembly = new Dictionary<Type, IValidator>();
@haydosw
haydosw / Check-MissingOctoVariables.ps1
Last active January 23, 2019 05:39
Checks for missing octopus variables given a project and scope to test
<#
.SYNOPSIS
Using AppName the script will find all variables for that project.
It will then look at EnvironmentToCheck for variables that have
been configured in other environments but not the one specified
i.e.
A variable named "Test" under the scope of a "Test" environment
will be reported if a "Test" variable under the "Prod" environment
@haydosw
haydosw / getCert.cs
Last active September 23, 2016 05:19
private static X509Certificate2 GetIISExpressCertificateFromLocalStore()
{
// http://stackoverflow.com/questions/1742938/how-to-solve-could-not-establish-trust-relationship-for-the-ssl-tls-secure-chan
ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true;
var store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", false);