Skip to content

Instantly share code, notes, and snippets.

View vergenzt's full-sized avatar

Tim Vergenz vergenzt

  • Jacksonville, FL
  • 05:02 (UTC -04:00)
View GitHub Profile
@vergenzt
vergenzt / update_head_revision_file.py
Created March 24, 2025 15:10
Fast Python script to write Alembic heads to file (for git conflicts on multiple heads)
#!/usr/bin/env python3
import ast
import os
import sys
from argparse import ArgumentParser, FileType
from collections import defaultdict
from configparser import ConfigParser
from graphlib import TopologicalSorter
from subprocess import check_call, check_output
from typing import Any, Iterable, Iterator, Tuple
@vergenzt
vergenzt / update_head_revision_file.py
Last active November 13, 2024 19:46
Python script to write alembic migration head(s) to head_revision.txt file
#!/usr/bin/env python3
import ast
import os
import sys
from collections import defaultdict
from graphlib import TopologicalSorter
from pathlib import Path
from subprocess import check_call, check_output
from typing import Any, Iterable, Iterator, Tuple, Union
@vergenzt
vergenzt / py-requirements-to-json
Last active May 7, 2024 18:30
Parse Python requirements files into AST JSON representation via tree-sitter-requirements
#!/usr/bin/env pip-run
"""
Parse Python requirements files into AST JSON representation
"""
# /// script
# dependencies = ['tree-sitter-requirements']
# ///
import json

If you have a command line that can generate a result, and you want to test whether successive results are statistically indepenent of each other, you can use the following:

seq <N_TESTS> \
| parallel -n0 <COMMAND...> \
| uniq -c \
| awk '{ NR%2 ? n1+=$1 : n2+=$1 } END { print NR, n1, n2 }' \
| python -c 'from statistics import NormalDist as N; import math; n_runs, n1, n2 = map(int, input().split()); n = n1+n2; μ=1.0*(2*n1*n2)/n + 1; σ=math.sqrt(1.0*(μ-1)*(μ-2)/(n-1)); Z = (n_runs-μ)/σ; p = N().cdf(-abs(Z)); p_two_tailed = p*2; print(); print(*list(vars().items())[-9:], sep="\n")'
@vergenzt
vergenzt / jwt-future-iat-should-not-be-rejected.md
Last active December 14, 2023 01:18
Discussion: JWT tokens containing `iat` values in the future should not be rejected

Previous discussion elsewhere on Github

Comments by me

Y'all this was litigated previously at #190. The JWT spec does NOT say to reject tokens with iat ("issued at") in the future, so this behavior goes beyond the spec and is inconsistent with many other JWT libraries.

4.1.6. "iat" (Issued At) Claim The "iat" (issued at) claim identifies the time at which the JWT was

@vergenzt
vergenzt / .parallelrc
Last active October 10, 2024 15:42
GNU parallel - easy JSON processing placeholder via jq expression
--rpl '{[(.*?)]} $Global::use{"IPC::Open2"} ||= eval "use IPC::Open2; 1;"; my $jq = open2(my $jq_out, my $jq_in, "jq", "-Rrc", "[ try(fromjson) // . | $$1 | tostring | \@sh] | join(\" \")") or die "Could not open pipe to jq!"; print $jq_in $_; close $jq_in; $_ = <$jq_out>; chomp $_; uq(); waitpid $jq, 0; $? && die'
!include _header.puml
group #lightblue "Parse phase"
dbt -> project ++: //read all yaml and SQL files//
return
rnote right of dbt #white: Evalute config
rnote right of dbt #white
Evalute ""generate_schema_name""
on all nodes to determine
#!/usr/bin/env bash
set -euf -o pipefail # https://sipb.mit.edu/doc/safe-shell/
# https://medium.com/@LihauTan/2f87c770ea9c
find . -name .gitignore \
-exec awk '
FNR==1 { print "\n## " FILENAME } \
FNR==1 { cmd = "dirname " FILENAME; cmd | getline DIRNAME; close(cmd) } \
/^ *#/ { print $0; next } \
/^[^!]/ { print DIRNAME "/" $0 } \
#!/usr/bin/env python3
'''
Parses current directory's git configuration + optional environment vars into a
list of strings suitable for tagging Docker images.
Outputs the computed image name(s) to stdout, separated by newlines.
'''
import os
import re
@vergenzt
vergenzt / aws_op_auto_reauth.sh
Last active May 31, 2022 19:22
aws_op_auto_reauth.sh
#!/usr/bin/env python3
: "${AWS_ADFS_HOST:?}"
: "${AWS_ADFS_REGION:?}"
: "${AWS_ADFS_OP_ITEM_UUID:?}"
# op session expires after 30 minutes of inactivity, so reauth every 25 minutes by default
: "${AUTH_INTERVAL:=+25 minutes}"