Skip to content

Instantly share code, notes, and snippets.

View TylerHendrickson's full-sized avatar

Tyler Hendrickson TylerHendrickson

View GitHub Profile
@TylerHendrickson
TylerHendrickson / main.go
Last active September 4, 2025 04:51
AfterFunc with synchronization guarantees (to prevent out-of-order logs / other delay-based activities)
// Example that demonstrates some action that executes after a timeout has elapsed, which can be canceled.
//
// Per this caveat noted in the comment for time.Timer.Stop() (in go 1.23.3)...
// For a func-based timer created with [AfterFunc](d, f), if t.Stop returns false, then the timer has already expired
// and the function f has been started in its own goroutine; Stop does not wait for f to complete before returning.
// If the caller needs to know whether f is completed, it must coordinate with f explicitly.
//
// ...the DoAfterUnlessCanceled function shown here satisfies "must coordinate with f explicitly" in a general-purpose way.
//
// The original inspiration for this solution was a need to prevent race conditions in logs that fire after a certain
@TylerHendrickson
TylerHendrickson / fancy_rich_progress.py
Created May 28, 2025 23:42
Some fancy columns to use when tracking progress with rich
import rich.progress
import rich.style
class ColorChangingBarColumn(rich.progress.BarColumn):
"""Like `rich.progress.BarColumn` but fades from red to green as progress moves from 0 to 100%"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.finished_style = rich.style.Style(color="rgb(0, 255, 0)")
@TylerHendrickson
TylerHendrickson / README.md
Created November 19, 2024 00:32
Example code: stream JSONL / NDJSON data from S3 with Node.js

Example for streaming line-delimited JSON (NDJSON / JSONL) data from S3 in Node.js

Demonstrates how to use stream-json and s3-readstream to handle a stream of line-delimited JSON data provided by an S3 object.

How it works

When the default function of jsonl-s3-stream.ts is run, it will fetch a configured amount of data (50 bytes in this example, which would be very slow in a real-world application) of data from the configured S3 object. The source S3 object is expected to contain a fully-formed, valid JSON value.

@TylerHendrickson
TylerHendrickson / README.md
Last active November 6, 2024 19:07
Tetris for zsh

Tetris for ZSH

My own customized version of tetriscurses.

Installation and usage

Download tetris.zsh and run zsh /path/to/downloaded/tetris.zsh to play. Arrow keys control the shapes. Press q to quit.

@TylerHendrickson
TylerHendrickson / parse-tf-fmt-diff.bash
Created November 16, 2023 00:00
Bash script for extracting PR suggestions from `terraform fmt` diffs
#!/bin/bash
# Parses terraform fmt diff and writes temp files that can be used to create suggestion comments
tmpdir=$(mktemp -d -t terraform-fmt-suggestions.XXXXX)
tmpfile=""
source_file=""
inchunk=false
regex_header_start='^[-]{3} old/(.*)$'
regex_chunk_start='^@@ [-]([0-9]+),([0-9]+) [+][0-9]+,[0-9]+ @@$' # Captures start line & total lines
@TylerHendrickson
TylerHendrickson / republish_dlq.py
Last active January 11, 2022 14:39
Republish SQS DLQ messages
"""Republishes messages in an AWS SQS dead-letter queue (DLQ)
Useful for moving messages in a DLQ back to a "normal" SQS queue
(e.g. once bugs are fixed or initial error is otherwise resolved).
Workflow:
1. Get a message from the configured source DLQ
2. Publish a new message to the configured destination queue,
using the body of the message from #1
3. After a successful publish, delete the message retrieved in #1 from the DLQ
@TylerHendrickson
TylerHendrickson / cli.go
Last active August 23, 2019 18:44
RRULE Tester (written in Go)
package main
import (
"flag"
"sort"
"strconv"
"strings"
"time"
"github.com/teambition/rrule-go"
@TylerHendrickson
TylerHendrickson / ddb_lock_example.py
Last active April 19, 2019 06:01
Distributed lock decorator backed by DynamoDB (or DLDBBDDB for short)
import functools
import sys
import time
import boto3
import botocore
from python_dynamodb_lock.python_dynamodb_lock import DynamoDBLockClient
lock_client = DynamoDBLockClient(boto3.resource('dynamodb'))
@TylerHendrickson
TylerHendrickson / serverless-plugins.md
Last active June 16, 2019 08:22
Useful Serverless Plugins

Useful Serverless Plugins

My curated list of Serverless Framework plugins

✓ = Seal of approval (I've used it extensively with success and/or consider it a matter of standard practice)

Helpers to cut down on CloudFormation (resources.Resources)

  • Make configuring API Gateway caching easier:
@TylerHendrickson
TylerHendrickson / unwatch_repos.py
Created September 30, 2018 19:18
Bulk-unwatch GitHub repositories using regular expressions
import re
import sys
try:
from github import Github
except ImportError:
print('You must install PyGithub in order to use this script!')
print('Example: `pip install pygithub`')
print('More info: https://github.com/PyGithub/PyGithub')
sys.exit(1)