Skip to content

Instantly share code, notes, and snippets.

View shollingsworth's full-sized avatar

Steven Hollingsworth shollingsworth

View GitHub Profile
@shollingsworth
shollingsworth / uv_script_shebang.py
Created February 7, 2025 15:40
demo of how you can write a shebang that utilizes uv run with automatic dependency resolution
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "boto3",
# ]
# ///
"""UV Script Demo."""
@shollingsworth
shollingsworth / chromeopen.py
Created February 7, 2025 15:24
open a file in chrome on a mac, sometimes the open command doesn't open some files in a web browser, this helps with that
#!/usr/bin/env python3
"""Open a file in a web browser."""
import argparse
from pathlib import Path
from subprocess import check_call
def main() -> None:
"""Run main function."""
@shollingsworth
shollingsworth / rec.py
Created February 7, 2025 15:22
script to automate creating asciinema gifs
#!/usr/bin/env python3
"""Record terminal session to gif."""
import argparse
import datetime
import shutil
from pathlib import Path
from subprocess import check_call
from tempfile import TemporaryDirectory
@shollingsworth
shollingsworth / wait-for-it.py
Created January 10, 2025 19:45
native python tcp socket checker similar to the bash wait-for-it project. https://github.com/vishnubob/wait-for-it
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Wait for a tcp network port to become open."""
import argparse
import socket
import sys
import time
from argparse import Namespace
SLEEP_SECONDS = 1
@shollingsworth
shollingsworth / postfix_iter_queue_delete.sh
Last active September 11, 2023 16:49
iterate through postfix queue and selectively delete entries
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
mapfile -t ids < <(mailq | grep -E '^[0-9A-F]' | awk '{print $1}')
for id in "${ids[@]}"; do
postcat -q "${id}" | less
echo "Remove? (y)"
read -r RM
@shollingsworth
shollingsworth / getuserdata.sh
Created June 29, 2023 20:27
retrieve aws ec2 instance userdata script
#!/usr/bin/env bash
curl -q http://169.254.169.254/latest/user-data
@shollingsworth
shollingsworth / dockerclean.sh
Created May 10, 2023 16:54
run through all the commands to prune unused resources in docker
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# prune stale containers/images
docker image prune -f
# prune stale volumes
docker volume prune -f
@shollingsworth
shollingsworth / ghstars.sh
Created May 9, 2023 18:07
output all of a users github starred repositories using gh api graphql call
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# get all my starred repos
getstars() {
query="query(\$endCursor: String) {
viewer {
starredRepositories(first: 100, after: \$endCursor) {
@shollingsworth
shollingsworth / mtr.sh
Created May 9, 2023 17:46
realtime traceroute like utility to troubleshoot network connection issues
# normal mtr with icmp
mtr $1
# tcp
mtr -T -P 443 $1
@shollingsworth
shollingsworth / awssso.sh
Created May 9, 2023 17:10
bash source file for using yawsso and aws sso login to set your current environment to make aws sso transparent with whatever tooling you are using
#!/usr/bin/env bash
# install yawsso https://github.com/victorskl/yawsso
# make sure aws cli is installed
# call with `sso`
################################################################################
# when calling these functions make sure AWS_PROFILE is set
################################################################################