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 / brew-reinstall-all.sh
Created August 9, 2023 20:36
reinstall all brew apps -- useful if links get fouled up
#! /usr/bin/env bash
brew list | xargs brew reinstall
#! /usr/bin/env bash
brew services list | grep started | cut -f 1 -d ' ' | xargs -n 1 brew services restart
@stand-sure
stand-sure / route.ts
Created June 18, 2023 16:44
nextjs prometheus metrics
import {collectDefaultMetrics, register} from 'prom-client';
collectDefaultMetrics({ register });
export async function GET() {
const metrics : string = await register.metrics();
return new Response(metrics, {
status: 200,
headers: {
"Content-Type": register.contentType,
@stand-sure
stand-sure / get-server-cert-chain.sh
Created June 5, 2023 18:28
openssl s_client # get cert chain
openssl s_client -showcerts -connect SERVER_NAME:443 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM >mycertfile.pem
@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 "{}"
#! /bin/bash
kubectl label --overwrite ns --all pod-security.kubernetes.io/audit=baseline pod-security.kubernetes.io/warn=baseline
#! /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
@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)}.");
@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( ) ) )
{
#! /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