Skip to content

Instantly share code, notes, and snippets.

@benstannard
benstannard / diagnose-vm.sh
Last active October 6, 2025 15:14
diagnose disk space on a Linux VM
# List files recursively with Human-readable size
ls -lhR
# Human-readable with filesystem type
df -hT
# Show top-level directory sizes
du -h --max-depth=1 / | sort -hr | head -20
# Current directory breakdown
# https://kubernetes.io/docs/reference/kubectl/quick-reference/
# use k for shorthand alias
alias k=kubectl
# context and configuration
kubectl config view
kubectl config get-contexts
kubectl config set-cluster my-cluster-name # set a cluster entry in the kubeconfig
@benstannard
benstannard / helm-cheatsheet.sh
Last active December 19, 2024 15:51
helm-cheatsheet
# https://helm.sh/docs/intro/cheatsheet/
# Chart Management
helm create <name> # Creates a chart directory along with the common files and directories used in a chart.
helm package <chart-path> # Packages a chart into a versioned chart archive file.
helm lint <chart> # Run tests to examine a chart and identify possible issues:
helm show all <chart> # Inspect a chart and list its contents:
helm show values <chart> # Displays the contents of the values.yaml file
helm pull <chart> # Download/pull chart
helm pull <chart> --untar=true # If set to true, will untar the chart after downloading it
@benstannard
benstannard / sql
Created December 11, 2017 23:20
PostgreSQL Commands
/* create, delete, rename a user without privileges*/
CREATE ROLE ben;
DROP ROLE ben;
ALTER ROLE ben RENAME TO benji;
/* create a user with privileges*/
CREATE ROLE ben LOGIN CREATEDB CREATEROLE REPLICATION;
/* Add privileges to existing user*/
ALTER ROLE ben WITH LOGIN CREATEROLE CREATEDB REPLICATION;
def chunks(seq, n=5):
"""apply to users hotelcode. 'aaaaabbbbb' becomes ('aaaaa', 'bbbbb')"""
return tuple((seq[i:i+n] for i in range(0, len(seq), n)))
@app.route("/search", methods=["GET", "POST"])
@login_required
def search():
# test/check for access
if "BB" not in chunks(current_user.access, n=2): abort(401)
@benstannard
benstannard / commands2know
Last active February 25, 2025 18:10
commands2know
cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'cat >> .ssh/authorized_keys && echo "Key copied"'
# Debug Docker Container
run --rm -it --entrypoint /bin/bash <image>
@benstannard
benstannard / hipandas.py
Last active March 7, 2025 13:49
pandas cheatsheet
# hipandas.py
"""Useful Tips
column: axis=1
rough rule: back-to-back ][ square brackets, you're asking for trouble
Replace that with a .loc[..., ...] and you'll be set.
.loc label-based indexing
.iloc for positional indexing
"""
import os
import pandas as pd