Skip to content

Instantly share code, notes, and snippets.

View michael-wolfenden's full-sized avatar

Michael Wolfenden michael-wolfenden

View GitHub Profile
@michael-wolfenden
michael-wolfenden / types.ts
Created January 14, 2021 20:16 — forked from ClickerMonkey/types.ts
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
@michael-wolfenden
michael-wolfenden / .gitattributes
Created June 21, 2020 21:00 — forked from bjrmatos/.gitattributes
My default .gitattributes
# Git to autodetect text files and normalise their line endings to LF when they are checked into your repository.
* text=auto
#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.php text
*.css text
@michael-wolfenden
michael-wolfenden / machine_setup.ps1
Last active April 6, 2020 01:14
My Boxstarter Script
##########################################################################
# Disable UAC (temporarily)
##########################################################################
Disable-UAC
##########################################################################
# Create temporary directory
##########################################################################
Get-NetTCPConnection | Group-Object -Property State, OwningProcess | Select -Property Count, Name, @{Name="ProcessName";Expression={(Get-Process -PID ($_.Name.Split(',')[-1].Trim(' '))).Name}}, Group | Sort Count -Descending
@michael-wolfenden
michael-wolfenden / fscheck.cs
Last active November 2, 2018 07:00
FsCheck Generic Rules Test
/*
<Query Kind="Program">
<NuGetReference>FsCheck.Xunit</NuGetReference>
<NuGetReference>TypeShape</NuGetReference>
<NuGetReference>xunit</NuGetReference>
<NuGetReference>xunit.runner.utility</NuGetReference>
<Namespace>FsCheck</Namespace>
<Namespace>FsCheck.Xunit</Namespace>
<Namespace>TypeShape</Namespace>
<Namespace>TypeShape.Core</Namespace>
@michael-wolfenden
michael-wolfenden / XUnitRunner.cs
Last active July 23, 2019 02:49
[Linqpad XUnit Runner] Run xunit within linqpad #xunit
/*
<Query Kind="Program">
<NuGetReference>xunit</NuGetReference>
<NuGetReference>xunit.runner.utility</NuGetReference>
<Namespace>Xunit</Namespace>
<Namespace>Xunit.Runners</Namespace>
<CopyLocal>true</CopyLocal>
</Query>
*/
@michael-wolfenden
michael-wolfenden / main.cs
Created October 13, 2018 08:51
Serialize Lefts
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
using LanguageExt;
using static LanguageExt.Prelude;
using Newtonsoft.Json;
public class Error : NewType<Error, string>
{
public Error(string value) : base(value) { }
@michael-wolfenden
michael-wolfenden / main.cs
Last active October 13, 2018 08:52
Serialize Left
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
using LanguageExt;
using static LanguageExt.Prelude;
using Newtonsoft.Json;
public class Error : NewType<Error, string>
{
public Error(string value) : base(value) { }
@michael-wolfenden
michael-wolfenden / Pattern.cs
Last active November 4, 2020 03:12
Pattern
public class Pattern<TReturn>
: List<(Type Type, Func<object, TReturn> Map)>
{
public void Add<T>(Func<T, TReturn> map)
=> Add((typeof(T), o => map((T)o)));
public Pattern<TReturn> Default(TReturn val)
{
Add((object _) => val);
return this;