Skip to content

Instantly share code, notes, and snippets.

View stephenpatten's full-sized avatar

Stephen Patten stephenpatten

View GitHub Profile
@stephenpatten
stephenpatten / AutofacFluentValidationModule.cs
Created October 15, 2018 23:47 — forked from ShawInnes/AutofacFluentValidationModule.cs
Autofac Fluent Validation Module (MVC 5)
using Autofac;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebSite
{
using System;
using Autofac;
using FluentValidation;
namespace Sample.Web.Infrastructure
{
public class AutofacValidatorFactory : ValidatorFactoryBase
{
private readonly IComponentContext _context;
@stephenpatten
stephenpatten / remove-docker-containers.md
Created September 6, 2018 12:36 — forked from ngpestelos/remove-docker-containers.md
How to remove unused Docker containers and images

May 8, 2018

I wrote this four years ago, so instead use this command:

$ docker rmi $(docker images -q -f dangling=true)
@stephenpatten
stephenpatten / Program.cs
Created August 2, 2018 15:34 — forked from janpieterz/Program.cs
Serilog and Topshelf
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Serilog;
using Serilog.Extras.Topshelf;
using Topshelf;
using Topshelf.Logging;
namespace ConsoleApplication1
{
@stephenpatten
stephenpatten / README.md
Created June 25, 2018 21:11 — forked from aaronk6/README.md
launchUri

Cross-browser implementation of navigator.msLaunchUri

Microsoft’s navigator.msLaunchUri method only works in Internet Explorer on Windows 8. Therefore I came up with a (nearly) cross-browser implementation that uses the native msLaunchUri when it’s available and falls back to adventurous hacks when running in other browsers.

Description

launchUri (uri, successCallback, noHandlerCallback, unknownCallback)
@stephenpatten
stephenpatten / .java.env.sh
Created June 15, 2018 04:22 — forked from lance/.java.env.sh
Java version switcher
# Props to qmx and abstractj for the inspiration
#
# Put this file in your home directory and these lines to .profile
# if [[ -f "$HOME/.java.env" ]]; then
# source "$HOME/.java.env";
# fi
VERSION=$1
if [ ! -n "$VERSION" ]
@stephenpatten
stephenpatten / retry.cs
Created May 11, 2018 19:27 — forked from benhysell/retry.cs
Polly - Back Off and Retry on Error http client
//Retry http with a back off on failure
await Policy.Handle<HttpRequestException>().WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
.ExecuteAsync(async () =>
{
var result = await httpClient.GetAsync("api/CallToServer/" + varibleToSendToServer, cancellationToken);
if (result.IsSuccessStatusCode)
{
returnValue = await result.Content.ReadAsAsync<List<Results>>(token);
}
@stephenpatten
stephenpatten / Logstash-log4net-README.md
Created March 11, 2018 01:25 — forked from junxy/Logstash-log4net-README.md
Logstash 2.1.x config for log4net logs.
<!- .... ->
<log4net>    
    <appender name="RollingLogFileAppenderLogstash" type="log4net.Appender.RollingFileAppender">
      <encoding value="utf-8" />
      <!--该目录必需有 IIS用户 写权限-->
      <file value="X:/var/log/[app_name]/logfile.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
@stephenpatten
stephenpatten / README.md
Created February 17, 2018 05:33 — forked from magnetikonline/README.md
NSSM - the Non-Sucking Service Manager cheatsheet.
@stephenpatten
stephenpatten / unzip.ps1
Created January 26, 2018 21:50 — forked from nachivpn/unzip.ps1
Unzip a file in powershell by overwriting existing files
function Unzip($zipfile, $outdir)
{
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile)
foreach ($entry in $archive.Entries)
{
$entryTargetFilePath = [System.IO.Path]::Combine($outdir, $entry.FullName)
$entryDir = [System.IO.Path]::GetDirectoryName($entryTargetFilePath)
#Ensure the directory of the archive entry exists