Skip to content

Instantly share code, notes, and snippets.

View kgriffs's full-sized avatar

Kurt Griffiths kgriffs

View GitHub Profile
@kgriffs
kgriffs / sysctl.conf
Last active April 6, 2024 19:40
Linux Web Server Kernel Tuning
# Configuration file for runtime kernel parameters.
# See sysctl.conf(5) for more information.
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for
# an explanation about some of these parameters, and instructions for
# a few other tweaks outside this file.
#
# See also: https://gist.github.com/kgriffs/4027835
#
# Assumes a beefy machine with lots of network bandwidth
@kgriffs
kgriffs / string_util.lua
Created May 27, 2020 17:41
Lua string utilities (contains, startswith, endswith, replace, insert)
function string:contains(sub)
return self:find(sub, 1, true) ~= nil
end
function string:startswith(start)
return self:sub(1, #start) == start
end
function string:endswith(ending)
@kgriffs
kgriffs / trim_mp3s.sh
Last active March 19, 2024 17:28
Bash script to trip mp3s to one hour in length and convert to AAC
#!/bin/bash
# Set the directory where your MP3 files are located
input_dir="."
# 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
kgriffs / vlc
Last active February 23, 2024 17:57
Run VLC from the command line on Mac OS X and stream internet radio (such as Radio Paradise).
#!/usr/bin/env bash
/Applications/VLC.app/Contents/MacOS/VLC -I rc "$@"
@kgriffs
kgriffs / example.py
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
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
with:
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
kgriffs / datadog_fetch_logs.py
Last active November 27, 2023 17:26
DataDog Download Logs Example
import requests
import time
class DatadogLogIterator:
_MAX_LIMIT = 1_000
_FETCH_LIMIT = _MAX_LIMIT
def __init__(self, query, start, end, api_key, app_key):
self._cursor = None
@kgriffs
kgriffs / boto3async.py
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 (https://www.apache.org/licenses/LICENSE-2.0)
#
# Forked from: https://github.com/rafidka/boto3async
# =============================================================================
"""Adds simple async wrappers around boto3 client methods.
This module adds async methods to the stock boto3 clients. The async versions of
@kgriffs
kgriffs / uuid_regex.py
Last active September 28, 2023 19:03
UUID regular expressions (regex) with usage examples in Python
import re
# RFC 4122 states that the characters should be output as lowercase, but
# that input is case-insensitive. When validating input strings,
# include re.I or re.IGNORECASE per below:
def _create_pattern(version):
return re.compile(
(
'[a-f0-9]{8}-' +
@kgriffs
kgriffs / lru_cache_ttl.py
Created July 18, 2022 20:29
Grant Jenks' LRU Cache with TTL for Python
# Grant Jenks' LRU Cache with TTL for Python
#
# https://stackoverflow.com/questions/31771286/python-in-memory-cache-with-time-to-live/71634221#71634221
from functools import lru_cache, wraps
from time import monotonic
def lru_cache_with_ttl(maxsize=128, typed=False, ttl=60):
"""Least-recently used cache with time-to-live (ttl) limit."""