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 / catch-up-current-branch.sh
Created July 14, 2022 12:30
Git catch up current branch
#! /bin/bash
# checkout-pull-prune.sh
branchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git fetch origin "$branchName:$branchName"
git merge "$branchName"
@stand-sure
stand-sure / graph.sh
Last active June 1, 2023 15:15
Git graph to HTML
#!/bin/bash
script -q -c "git --no-pager log --decorate --graph --format='%C(auto,#aa5500) %h %C(auto,#55ff55) (%an %GK %G?) %Creset %s %cr %C(auto,#ffff55) %d' --date=relative --all --remotes=* -n 100" ../graph.txt && \
ansi2html < ../graph.txt > ../graph.html
@stand-sure
stand-sure / TypeMaker.cs
Created August 3, 2022 21:04
Make a .net type by name
using System;
using System.Reflection.Emit;
using System.Reflection;
internal static class TypeMaker
{
private const string AssemblyNameForType = "DynamicAssemblyExample";
public static Type? Make(string typeName)
{
@stand-sure
stand-sure / make-gitgnore.sh
Created December 15, 2022 12:52
make .gitignore from untracked
#! /bin/bash
# NB the result will need cleaned
# ADVICE run this from another directory and edit the pathing
git ls-files --others --exclude-standard --directory ./YOUR/PATH > .gitignore
#! /bin/bash
# Make a copy of your existing config
cp ~/.kube/config ~/.kube/config.bak
# Merge the two config files together into a new config file
KUBECONFIG=~/.kube/config:/path/to/new/config kubectl config view --flatten > /tmp/config
# TEST
@stand-sure
stand-sure / AnonymousTypeToExpando.cs
Created February 21, 2023 21:42
C# Anonymous Type To Expando
public class ObjectExtensions
{
public static IDictionary<string, object> AnonymousTypeToExpando( this object obj )
{
IDictionary<string, object> retVal = new ExpandoObject( );
if ( obj != null )
{
foreach ( PropertyDescriptor prop in TypeDescriptor.GetProperties( obj.GetType( ) ) )
{
@stand-sure
stand-sure / CheckInitOnly.cs
Created February 21, 2023 21:45
Verify that a property is Init Only
public static class PropertyChecker
{
// usage: PropertyChecker.CheckInitOnly(() => foo.Bar);
public static void CheckInitOnly(Expression<Func<object>> expression, bool allowEmptyStrings = false)
{
if (expression.Body is not UnaryExpression { Operand: MemberExpression memberExpression })
{
if (expression.Body is not MemberExpression tmp)
{
throw new InvalidOperationException($"Expected a {nameof(MemberExpression)}.");
#! /bin/bash
# remove kubernetes CRDs matching a certain string
#
for crd in `k get crds -oname | grep PUT_FRAGMENT_HERE | awk -F / '{print $2}'`; do kubectl delete crd $crd; done
#! /bin/bash
kubectl label --overwrite ns --all pod-security.kubernetes.io/audit=baseline pod-security.kubernetes.io/warn=baseline
@stand-sure
stand-sure / brew-upgrade-svc-restart.sh
Created May 17, 2023 22:44
upgrades brew packages and restarts the services that were updated
#! /usr/bin/env bash
brew upgrade | tee /tmp/brew.log
cat /tmp/brew.log | grep "brew services restart" | xargs -n 4 -L 1 -I {} sh -c "{}"