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 October 10, 2026 12:41
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 / claude_red_green.md
Created July 17, 2026 23:10
Claude Red-Green TDD

The red-green testing technique has payed dividends for me over the years. Now I'm having Claude do it for me.

## When testing a new feature or bug fix

Work test-first. When fixing a bug, write or update a test that reproduces the
broken behavior and watch it fail (red) before you touch the implementation.
Apply the fix, then re-run and watch it turn green. Without seeing red first,
you can't tell a real guard from a test that would pass either way.
@kgriffs
kgriffs / util.py
Created December 31, 2013 20:49
Deprecated decorator for Python. Uses clever introspection to set a helpful filename and lineno in the warning message.
import functools
import inspect
import warnings
# NOTE(kgriffs): We don't want our deprecations to be ignored by default,
# so create our own type.
class DeprecatedWarning(UserWarning):
pass
@kgriffs
kgriffs / results.py
Created May 21, 2021 23:05
Benchmarking Python JSON libs: std vs. orjson vs. simdjson - simple encode/decode tests
# ----------------------------------------------------------------------------
import json
import simdjson
import libpy_simdjson
decoder_std = json.JSONDecoder()
encoder_std = json.JSONEncoder(ensure_ascii=False)
p = simdjson.Parser()
p2 = libpy_simdjson.Parser()
@kgriffs
kgriffs / disable_echo.py
Created June 7, 2013 00:52
Disable echo in Python
def enable_echo(enable):
fd = sys.stdin.fileno()
new = termios.tcgetattr(fd)
if enable:
new[3] |= termios.ECHO
else:
new[3] &= ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, new)
@kgriffs
kgriffs / rdpy_demo.py
Last active October 1, 2025 18:16
RDP Automation Hack
import time
from rdpy.protocol.rdp import rdp
from twisted.internet import reactor
class MyRDPFactory(rdp.ClientFactory):
def clientConnectionLost(self, connector, reason):
reactor.stop()
@kgriffs
kgriffs / vlc
Last active May 9, 2025 02:41
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 / 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 / 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)