Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / http_monitor.sh
Created November 20, 2025 06:41
http continuous ping script for monitoring an http service
#!/bin/bash
# Simple HTTP Monitor Script
URL="$1"
INTERVAL="${2:-5}"
if [ -z "$URL" ]; then
echo "Usage: $0 <URL> [interval_seconds]"
echo "Example: $0 https://google.com 2"
exit 1
@mttjohnson
mttjohnson / validate_ssh_key.sh
Last active August 18, 2025 16:01
Validating ssh keys
# When you SSH into a server for the first time it prompts you if you trust the remote server's host key
# To validate that they key you received is the same as the server you just logged into you can check
# the fingerprint of the host key on the remote server itself.
# Output fingerprint of system's host key
ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
# You can fingerprint both the private and public key from a file
# They should both produce the same fingerprint value.
ssh-keygen -l -f ~/.ssh/id_ed25519.pub
@mttjohnson
mttjohnson / .env-1password
Last active November 28, 2024 18:07
Load Secret Environment Variables from 1Password
# Load environment secrets with with 1Password CLI Injection
#
# Used with load_secrets.sh
# source load_secrets.sh
# AWS Service Account Credentials
AWS_ACCESS_KEY_ID={{ op://$OP_VAULT/$INF_PROJECT.aws_access_key/username }}
AWS_SECRET_ACCESS_KEY={{ op://$OP_VAULT/$INF_PROJECT.aws_access_key/password }}
# Project Secrets
@mttjohnson
mttjohnson / README.md
Last active September 8, 2024 14:09
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 / mysql-performance-tuning.sql
Last active August 23, 2024 17:54
MySQL Performance Tuning
-- Query the database to calculate a recommended innodb_buffer_pool_size
-- and get the currently configured value
-- The rollup as the bottom row gives the total for all DBs on the server, where each other row is recommendations per DB.
SELECT
TABLE_SCHEMA,
CONCAT(CEILING(RIBPS/POWER(1024,pw)),SUBSTR(' KMGT',pw+1,1))
Recommended_InnoDB_Buffer_Pool_Size,
(
SELECT CONCAT(CEILING(variable_value/POWER(1024,FLOOR(LOG(variable_value)/LOG(1024)))),SUBSTR(' KMGT',FLOOR(LOG(variable_value)/LOG(1024))+1,1))
@mttjohnson
mttjohnson / load_all_sitemap_urls.sh
Created March 1, 2019 20:10 — forked from erikhansen/load_all_sitemap_urls.sh
Load all urls from a sitemap.xml file
#!/bin/bash
# This script crawls all urls in a /sitemap.xml file and loads them, effectively priming the cache
# Usage: ./warm_cache.sh www.example.com
time wget --quiet https://$1/sitemap.xml --output-document - | \
egrep -o "https?://[^<]+" | \
grep $1 | \
grep -v "jpg" | \
xargs -i -d '\n' curl --output /dev/null --silent --write-out '%{http_code} %{time_total}ms %{url_effective} \n' {}
@mttjohnson
mttjohnson / web_request_performance_timing.sh
Last active May 14, 2024 08:00
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 / 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