Skip to content

Instantly share code, notes, and snippets.

View johnhpatton's full-sized avatar

John H Patton johnhpatton

View GitHub Profile
@johnhpatton
johnhpatton / .bashrc
Last active January 6, 2025 20:17
Aries bashrc for working with various projects
[[ $- =~ i ]] && INTERACTIVE=1
# enum()
# Creates an enum from passed in list variable name.
# Usage:
# STATUS=(
# OK
# FAIL
# ) && enum "${STATUS[@]}"
# echo "$OK is 0"
@johnhpatton
johnhpatton / Dockerfile
Created July 11, 2024 19:03
MySQL Dockerfile
FROM bitnami/mysql:5.7 AS initial
ENV ALLOW_EMPTY_PASSWORD=yes
ENV MYSQL_MODE=""
USER root
RUN apt update && \
apt install -y unzip && \
apt-get clean && \
@johnhpatton
johnhpatton / install-latest-docker-compose.sh
Last active July 8, 2024 22:21
Install latest docker compose
UNAME_M=$(uname -m)
UNAME_S=$(uname -s)
UNAME_S=${UNAME_S,,}
[[ $UNAME_M =~ amd64|x86_64 ]] && ARCH=x86_64 || ARCH=aarch64
URL_GITHUB_DOCKER_COMPOSE_RELEASES_API="https://api.github.com/repos/docker/compose/releases/latest"
URL_GITHUB_DOCKER_COMPOSE_RELEASES_DOWNLOAD_PREFIX="https://github.com/docker/compose/releases/download"
DOCKER_COMPOSE_LATEST_VERSION=$(curl -s "${URL_GITHUB_DOCKER_COMPOSE_RELEASES_API}" | grep '.tag_name' | sed -r 's/^[^:]*:.*\"(.*)\".*/\1/')
URL_GITHUB_DOCKER_COMPOSE_DOWNLOAD="${URL_GITHUB_DOCKER_COMPOSE_RELEASES_DOWNLOAD_PREFIX}/${DOCKER_COMPOSE_LATEST_VERSION}/docker-compose-${UNAME_S}-${ARCH}"
BIN_DOCKER_COMPOSE=${DOCKER_CONFIG:-$HOME/.docker/cli-plugins/docker-compose}
@johnhpatton
johnhpatton / build-loki-docker-driver
Created July 8, 2024 15:58
Build loki docker driver
cd ~/src
git clone git@github.com:grafana/loki.git
cd loki
make LOKI_DOCKER_DRIVER=loki PLUGIN_TAG=latest docker-driver
make LOKI_DOCKER_DRIVER=loki PLUGIN_TAG=latest docker-driver-enable
function logbashrc() {
[[ $- =~ i ]] && echo "$1"
return 0
}
function pathadd() {
local option=""
local retval=0
if [[ "${1:0:1}" = "-" ]]; then
option=$1 && shift
logbashrc() {
[[ $- =~ i ]] && echo "$1"
return 0
}
pathadd() {
local option=""
local retval=0
if [[ "${1:0:1}" = "-" ]]; then
option=$1 && shift
#!/bin/bash
# May be required to avoid SSL certificate validation.
# NOTE: manually validate the CA in this case.
export INSECURE=${INSECURE:-true}
# Set to user id for access:
OPENCONNECT_USER="USERNAME"
# Set to server without scheme, use what's configured in client config:
@johnhpatton
johnhpatton / ephemeral-port-details.sh
Created January 29, 2020 15:18
Get TCP ephemeral port details to validate ephemeral port exhaustion.
#!/bin/bash
#
# REQUIRES
# - netstat - to retrieve network stack details
# - sysctl - to retrieve/modify kernel settings
# - bc - for math
#
# MIT License
#
# Copyright 2020 John H Patton, JH Patton Consulting, LLC
@johnhpatton
johnhpatton / cve_2021_44228.lua
Created December 15, 2021 12:59
Nginx + Lua to mitigate CVE-2021-44228
-- -*- location: /etc/nginx/conf.d/cve_2021_44228.lua; -*-
-- -*- mode: lua; -*-
-- -*- author: John H Patton; -*-
-- -*- email: jhpattonconsulting@gmail.com; -*-
-- -*- license: MIT License; -*-
--
-- Copyright 2021 JH Patton Consulting, LLC
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this
-- software and associated documentation files (the "Software"), to deal in the Software
@johnhpatton
johnhpatton / bashrc
Created June 22, 2022 11:38
a pretty good .bashrc
logbashrc() {
(( INTERACTIVE )) && echo "$1"
return 0
}
pathdedup() {
local retval=0
local opt= dir= deduped=
# default to PATH