Skip to content

Instantly share code, notes, and snippets.

View mttjohnson's full-sized avatar

Matt Johnson mttjohnson

View GitHub Profile
@mttjohnson
mttjohnson / test_http_redirects.sh
Last active January 31, 2024 22:31
Testing HTTP Redirects
# The check_url recursive function
check_url() {
THIS_URL="${1}"
HTTP_RESP_CODE=$(curl -ksI "${THIS_URL}" | grep -i 'HTTP/' | cut -d' ' -f 2)
echo "${THIS_URL} -> ${HTTP_RESP_CODE}"
if [ "${HTTP_RESP_CODE}" == "301" ] || [ "${HTTP_RESP_CODE}" == "302" ]
then
HTTP_LOC=$(curl -ksI ${1} | grep -i 'Location: ' | cut -d'_' -f 2)
HTTP_REDIRECT=$(echo "${HTTP_LOC}" | tail -c +11 | tr -d '\r' | tr -d '\n')
@mttjohnson
mttjohnson / macos_hostname.sh
Created December 4, 2023 03:53
change macos hostname
new_hostname="my-new-hostname"
sudo scutil --set HostName ${new_hostname}
sudo scutil --set LocalHostName ${new_hostname}
sudo scutil --set ComputerName ${new_hostname}
dscacheutil -flushcache
# reboot mac
@mttjohnson
mttjohnson / ssl_certificate_validation.sh
Last active October 17, 2023 16:01
SSL Certificate Validation
# Verify SSL
ssl_domain=mydomainnametotest.com
openssl rsa -noout -modulus -in $ssl_domain.key | openssl md5
openssl req -noout -modulus -in $ssl_domain.csr | openssl md5
openssl x509 -noout -modulus -in $ssl_domain.crt | openssl md5
# Output text of certificate
openssl x509 -text -in /etc/nginx/ssl/$ssl_domain.crt
# Get details of all certs in .crt bundle file to verify certificate chain
@mttjohnson
mttjohnson / README.md
Last active October 6, 2023 16:41
Add English subtitles to videos with Turkish language audio

Dependencies

Install the following dependencies

brew install pipenv
brew install ffmpeg
pipenv install --python 3.10

Instructions

@mttjohnson
mttjohnson / file-research.sh
Last active September 26, 2023 16:36
file recursive research
# find the biggest .png files in a sub directory
# referenced from https://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/
find . -type f -iname "*.png" -printf '%s %p\n'| sort -nr | head -25
# List all symlinks recursively in a directory
find ./ -type l -printf "%p -> %l\n"
find . -type l -ls
# List all broken symlinks
@mttjohnson
mttjohnson / filterstamp
Last active July 10, 2023 19:51
An inline input parser for timestamped and filtered output
#!/usr/bin/env bash
set -eu
########################################
## Introduction
########################################
HELP_INFO=$(cat <<'CONTENTS_HEREDOC'
input_filter v0.1
@mttjohnson
mttjohnson / web_request_performance_timing.sh
Last active July 6, 2023 22:37
Web (Curl) Request Performance Timing (with HTTPS DNS resolver caching to alternate hosts)
# Some output format parameters require newer versions of curl
# These examples were done with Curl 7.54.0 with HTTP/2 Support
# The kind of output you would expect to see with the two functions here (time_url and url_ping) would look like this:
[user@683dd22606f5 /]# URL_TO_CHECK="https://venia.magento.com/graphql?query=query+getProductDetailForProductPage..."
[user@683dd22606f5 /]# time_url "${URL_TO_CHECK}"
@mttjohnson
mttjohnson / genpasswd.sh
Last active June 25, 2023 15:27
Generate a password from the shell
# Defined function for generating random password
genpasswd() {
local l=$1
[ "$l" == "" ] && l=20
LC_CTYPE=C tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
NEW_PASSWORD=$(genpasswd 16)
echo $NEW_PASSWORD
@mttjohnson
mttjohnson / keygentest.sh
Created May 31, 2023 16:20
Testing SSH Keygen (rounds of key derivations)
#!/usr/bin/env bash
set -eu
## shellcheck ./keygentest.sh
for j in 16 32 64 100 150 256; do
echo -n "-a $j takes on average ";
# shellcheck disable=SC2034
for i in {1..20}; do
@mttjohnson
mttjohnson / bash_xml_edit.sh
Created November 7, 2019 20:41
Scripted XML Editing using XSLT and Xpath Expressions (xmllint xsltproc)
# Requirements
# yum install libxml2 libxslt
set +H # disable history expansion
XML_CONTENT=$(cat <<'XML_CONTENT_HD'
<?xml version="1.0" encoding="UTF-8"?>
<confluence-configuration>
<setupStep>complete</setupStep>