Skip to content

Instantly share code, notes, and snippets.

View kgriffs's full-sized avatar

Kurt Griffiths kgriffs

View GitHub Profile
kgriffs /
Last active March 19, 2024 17:28
Bash script to trip mp3s to one hour in length and convert to AAC
# Set the directory where your MP3 files are located
# Set the desired output bitrate (in bits per second)
output_bitrate="192k" # Adjust this value as needed
# Loop through each MP3 file in the directory
for file in "$input_dir"/*.mp3; do
kgriffs /
Last active February 13, 2024 19:22
Python TZ Aware datetime and DST Conversion Example
import datetime
import pytz
tz_ny = pytz.timezone('America/New_York')
dt_aware_dst_active = tz_ny.localize(datetime.datetime(2023, 5, 1, 12, 0))
dt_aware_dst_inactive = tz_ny.localize(datetime.datetime(2023, 12, 1, 12, 0))
print("Original DST Active Offset (America/New_York):", dt_aware_dst_active.dst())
print("Original DST Active (America/New_York):", dt_aware_dst_active)
kgriffs / example.yml
Created January 16, 2024 17:04
Github Action (GHA) caching a downloaded file example
- name: Cache downloaded file
id: cache-some-file
uses: actions/cache@v3
path: some-file
key: ${{ runner.os }}-downloaded-file-${{ hashFiles('some-file') }}
- name: Fetch smctl MSI
if: steps.cache-some-file.outputs.cache-hit != 'true'
shell: pwsh
run: |
kgriffs /
Last active November 27, 2023 17:26
DataDog Download Logs Example
import requests
import time
class DatadogLogIterator:
_MAX_LIMIT = 1_000
def __init__(self, query, start, end, api_key, app_key):
self._cursor = None
kgriffs /
Last active November 18, 2022 21:22
Example demonstrating how a synchronous control flow never yields to tasks on the event loop, starving them.
import asyncio
import httpx
import time
async def do_work_async():
http = httpx.AsyncClient()
while True:
resp = await http.get('')
kgriffs /
Last active November 2, 2022 01:52
Example showing how to trap a signal with a Python asyncio coroutine function and exit cleanly without logging an error.
import asyncio
import functools
import signal
import sys
import time
async def worker(shutdown_event):
while True:
kgriffs /
Last active November 7, 2022 16:39
aiobotocore config example (vs. boto3) for setting connect_timeout and usign the standard retries mode
import asyncio
import aiobotocore.session
import aiobotocore.config
async def example():
# Equivalent to boto3.client('s3', config=botocore.client.Config(**kwargs))
# See also for available options:
# *
kgriffs /
Last active October 4, 2023 14:47
asyncio boto3 wrapper to run boto3 client methods in a thread pool executor as an alternative to aiobotocore
# =============================================================================
# Copyright 2022 by Rafid Al-Humaimidi. All rights reserved.
# Licensed via Apache 2.0 (
# Forked from:
# =============================================================================
"""Adds simple async wrappers around boto3 client methods.
This module adds async methods to the stock boto3 clients. The async versions of
kgriffs /
Last active August 24, 2022 03:18
Start redis server without disk persistence; memory only for testing (avoids having to clean up a dump.rdb file)
redis-server --save "" --appendonly no
kgriffs /
Created July 29, 2022 22:01
macOS port listening bash
listening() {
if [ $# -eq 0 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P
elif [ $# -eq 1 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
echo "Usage: listening [pattern]"