Skip to content

Instantly share code, notes, and snippets.

View mttjohnson's full-sized avatar

Matt Johnson mttjohnson

View GitHub Profile
@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 / 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 / phpfpm_reload_and_watch.md
Created March 30, 2023 20:19
Reloading PHP-FPM and Watching Processes

Monitor php-fpm processes

This shows the master processes and 1 child from each pool and refreshes every 5 seconds

WATCH_COMMAND=$(cat <<'COMMAND_CONTENT'
sudo ps afxo pid,user,command --sort command | perl -ne 'print if /^\s*$/ || /^\s*\d+(.+)$/ && ! $SEEN{$1}++' | grep -i '[p]hp-fpm'
COMMAND_CONTENT
)
watch -n 5 "${WATCH_COMMAND}"
@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 / .env-1password
Last active March 5, 2023 07:02
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 / postgres_testing.sh
Last active June 21, 2022 13:09
PostgreSQL Testing
# https://www.postgresql.org/download/linux/debian/
# Installing Postgres Client on Debian
apt-get update && apt-get install -y lsb-release && apt-get clean all
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
apt-get update
apt-get -y install postgresql-client-13
# List available packages
@mttjohnson
mttjohnson / filebackup.sh
Created April 7, 2022 15:05
file backup script
#!/usr/bin/env bash
# Simple file backup script
# This can be easily put into a cron job to automatically maintain a rolling 7 day backup of specified
# paths tarred and gzipped accessible to the user running the script.
#
# Usage:
# filebackup.sh <backup_name> <directory_to_backup> <backup_storage_directory>
#
# Reference: https://github.com/classyllama/ansible-role-filebackup/blob/master/templates/filebackup.sh.j2
@mttjohnson
mttjohnson / dbbackup.sh
Created April 7, 2022 15:02
mysql database backup script
#!/usr/bin/env bash
# Simple mysql database backup script
# This can be easily put into a cron job to automatically maintain a rolling 7 day backup of all
# databases accessible to the user running the mysql command. Ensure a ~/.my.cnf file exists in order
# for the script to be able to authenticate to mysql.
#
# Usage with optional destination path as the only parameter:
# dbbackup.sh
# dbbackup.sh /data/dbbackup
@mttjohnson
mttjohnson / ansible_inventory.tf
Created March 29, 2022 16:27
Generating Ansible Inventory YAML file from Terraform
resource "local_file" "ansible_inventory" {
content = yamlencode(
{
"all": {
"vars": {
"infrastructure": "${local.x_inf_tag}"
"implementation": "${var.implementation_tag}"
"implementation_id": "${random_id.implementation.hex}"
}
"children": {
@mttjohnson
mttjohnson / postgresql_testing.sh
Created March 23, 2022 20:21
PosgreSQL Testing
# Testing SSL connection to PostgreSQL database
psql -h testpg.555555555555.us-east-1.rds.amazonaws.com -p 5432 \
"dbname=testpg user=testuser sslrootcert=rds-ca-2019-root.pem sslmode=verify-full"