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 December 1, 2021 12:25
.bashrc with Active prompt
# To get the most out of this .bashrc, install bash 4.x or higher along with the following tools:
# figlet
# screenfetch
#
# On Mac, install bash via brew and update the shell for the user:
#
# brew install bash
# sudo echo /usr/local/bin/bash >> /etc/shells
# chsh -s /usr/local/bin/bash
#
@johnhpatton
johnhpatton / simple-local-ca-cert.sh
Created April 3, 2021 22:10
Create a Local CA root certificate.
#!/usr/bin/env bash
# Create the CA root signing key
openssl genrsa -out "./ca.key" 2048
# Create the CA root certificate
openssl req -x509 -new -nodes \
-days 3650 \
-reqexts v3_req \
-extensions v3_ca \
#!/usr/bin/env bash
get_bg_color() {
local -n bg_color="$1"
local ansi_sequence_query_bg='\e]11;?\e\'
local cur_stty=$(stty -g)
# enable stty raw echo
stty raw -echo min 0 time 0
@johnhpatton
johnhpatton / terminal-get-bg-luminosity.sh
Created April 1, 2021 12:54
Gets terminal background luminosity with ANSI escape sequence to help select a foreground color palette
#!/usr/bin/env bash
get_bg_color() {
local -n bg_color="$1"
local ansi_sequence_query_bg='\e]11;?\e\'
local cur_stty=$(stty -g)
stty raw -echo min 0 time 0
printf "%b" "${ansi_sequence_query_bg}"
if ($shun_mismatched_payload = 1) {
return 403 'You shall not pass!!!';
}
@johnhpatton
johnhpatton / nginx-compare-two-request-variables.conf
Created March 19, 2021 12:24
Nginx comparison of two nginx request variables
map $arg_FOO:$http_x_bar $shun_mismatched_payload {
"~^([^:]+):\1$" 1;
default 0;
}
if ($shun_if_client_is_a_baddy = 1) {
return 403 'You shall not pass!!!';
}
@johnhpatton
johnhpatton / nginx-maps-malformed-uri.conf
Created March 19, 2021 11:44
Nginx Maps Malformed URI
map $request_uri $uri_only {
"~^(?<u>[^\?]+)\?(?:.*)?" $u;
default $request_uri;
}
map $uri_only $shun_if_client_is_a_baddy {
"~\/\/" 1;
"~*%2f" 1;
default 0;
}
@johnhpatton
johnhpatton / nginx-compare-two-variables.conf
Created March 19, 2021 01:09
Nginx comparison of two variables
# if delimeter between two variables is ':'
map $thing1:$thing2 $do_things_match {
"~^([^:]+):\1$" 1;
default 0;
}
@johnhpatton
johnhpatton / nginx-compare-two-vars-not-possible.conf
Created March 19, 2021 01:06
Example of nginx comparison configuration that is not possible
if ($thing1 = $thing2) {
return 301 "{'Error': 'Things don't match!'}";
}