Skip to content

Instantly share code, notes, and snippets.

View stand-sure's full-sized avatar

Christopher J. Anderson stand-sure

View GitHub Profile
@stand-sure
stand-sure / Moq-demo.cs
Last active April 26, 2024 14:58
Example of how to use Moq in ASP.NET MVC Unit Tests with NUnit
namespace MoqDemo.Tests
{
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Moq;
using NUnit.Framework;
using HomeController = Controllers.HomeController;
@stand-sure
stand-sure / sum.ts
Created May 27, 2020 18:01
sums an arbitrary number of arguments
const sum: (...values: any[]) => number = (...values) => {
return values.reduce(
(total, val) => total + (isNaN(Number(val)) ? 0 : Number(val))
);
};
export { sum };
@stand-sure
stand-sure / isSubclassOf.ts
Created May 28, 2020 14:17
determines if the shape of an object's prototype is the same as the shape of another object
const isSubclassOf = function isSubclassOf(derived: any, base: any) {
const pair = [Reflect.getPrototypeOf(derived), base];
const allKeys = pair.reduce(
(keys, instance) => keys.concat(Object.keys(instance)),
[]
);
const distinctKeys = new Set(allKeys);
@stand-sure
stand-sure / AsyncLazy.cs
Created December 3, 2020 20:24
Async version of Lazy<T>
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
//// inspired by Stephen Toub's https://devblogs.microsoft.com/pfxteam/asynclazyt/
/// <summary>
/// Provides support for async lazy initialization.
/// </summary>
/// <typeparam name="T">Specifies the type of element being lazily initialized.</typeparam>
@stand-sure
stand-sure / bot.cs
Created August 25, 2021 23:13
GetBot
public static string GetBot(string message)
{
string bot = $"\n {message}";
bot += @"
__________________
\
\
....
....'
....
@stand-sure
stand-sure / additional-config.sh
Last active April 8, 2022 23:00 — forked from davebarnwell/brew-dnsmasq.md
install dnsmasq with brew
cp /usr/local/etc/dnsmasq.conf /usr/local/etc/dnsmasq.conf.orig
echo "conf-dir=/usr/local/etc/dnsmasq.d/,*.conf" | tee /usr/local/etc/dnsmasq.conf
@stand-sure
stand-sure / ConfigureMvcOptions.cs
Created July 8, 2022 22:35
C# trim string binder (MVC)
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Options;
public class ConfigureMvcOptions : IConfigureOptions<MvcOptions>
{
private readonly IHttpRequestStreamReaderFactory readerFactory;
public ConfigureMvcOptions(IHttpRequestStreamReaderFactory readerFactory)
{
@stand-sure
stand-sure / TSDemoInput.cs
Last active July 8, 2022 22:41
HotChocolate trimming strings in inputs
public record TSDemoInput(string Name);
public class TSDemoInputType : InputObjectType<TSDemoInput>
{
protected override void Configure(IInputObjectTypeDescriptor<TSDemoInput> descriptor)
{
descriptor.Field(input => input.Name)
.Type<TrimmedStringType>();
}
}
@stand-sure
stand-sure / checkout-pull-prune.sh
Created July 14, 2022 12:28
Git porcelain repo catch-up
#! /bin/bash
# checkout-pull-prune.sh
branchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout "$branchName" && \
git pull && \
git fetch --prune
@stand-sure
stand-sure / delete-merged-branches.sh
Created July 14, 2022 12:29
Git delete merged branches
#! /bin/bash
branchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout "$branchName" \
| git branch --merged \
| grep -E --invert-match "(^\*|master|main|dev)" \
| xargs git branch --delete \
&& git remote prune origin