Skip to content

Instantly share code, notes, and snippets.

View CodyKochmann's full-sized avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / shrink-postgres-table-disk-usage-with-full-disks.sh
Created February 25, 2024 12:53
This script contains the steps needed to shrink a massive table on postgres when disks did not have enough room to run a VACUUM FULL after major deletions.
#!/bin/bash
# This script contains the steps needed to shrink a massive table on postgres
# when disks did not have enough room to run a VACUUM FULL after major deletions.
# by: Cody Kochmann
# NOTE - These commands were run manually and will need situation specific
# options added if they were ever to be reused. This gist was only to
# capture the gist of the steps needed.
# set a date to clear logs to
@CodyKochmann
CodyKochmann / json-to-directory.py
Created October 4, 2023 13:29
This script takes a json object from stdin and turns it into a directory tree of files.
#!/usr/bin/env python3
# by: Cody Kochmann
# created: 2023-10-01
# license: MIT
'''
This script takes a json object from stdin and turns it into a directory tree of files.
'''
import sys, json, os, contextlib
@CodyKochmann
CodyKochmann / linux-gui-user-sandbox-demo.sh
Created September 24, 2023 11:40
how to run an interactive gui program from another user on debian 12
#!/bin/bash
# by: Cody Kochmann
# how to run an interactive gui program from another user on debian 12
# inspired by https://gist.github.com/kasunbg/5502cb630429819d07b5dc0cfa26813c
export NEW_USER_NAME=cody-facebook
#---------------------------------
# step 1 - create a new user
#---------------------------------
@CodyKochmann
CodyKochmann / fstab
Created September 24, 2023 11:38
how I keep cache to per boot lifetimes
# file /etc/fstab
# by: Cody Kochmann
# license: MIT
# description: how I keep cache to per boot lifetimes
# Note - pull the uid and gid from /etc/fstab to ensure correct permissions
# Note - the "size" can be defined as units like "1G" or percentages like "10%"
# configuration for per user cache
tmpfs /home/cody/.cache tmpfs defaults,uid=1000,gid=1000,mode=0700,size=10% 0 0
@CodyKochmann
CodyKochmann / Makefile
Last active September 16, 2023 16:35
Makefile for managing a directory of .magnet files for isolated parallel torrenting sessions using aria2c
# Author: Cody Kochmann
# Date Created: 2023-09-16
# Last Modified: 2023-09-16
# License: MIT
#
# This makefile spins up an aria2c process for every .magnet file in the current directory.
#
# It assumes it will be only one magnet link per each .magnet file.
#
# The benefit of this over just having a single aria2c call pull multiple magnet links from
@CodyKochmann
CodyKochmann / demo-sqlite-over-ssh-user.sh
Created March 6, 2023 13:41
dedicated db user that has a login shell of sqlite for a sqlite over ssh interface
➜ ~ ssh [email protected] cat /usr/local/bin/sqlite3-user-db
[email protected]'s password:
#!/bin/bash
/usr/bin/sqlite3 "$HOME/$USER.db"
➜ ~ ssh [email protected]
[email protected]'s password:
Linux kali 6.0.0-kali3-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.0.7-1kali1 (2022-11-07) x86_64
@CodyKochmann
CodyKochmann / ocr_remote_image.py
Created February 17, 2023 13:27
python ocr conversion of an image from a url
# by: Cody Kochmann
# this script pulls the contents of $TARGET_IMAGE
# and uses pytesseract against it to output the
# text contents of the image to stdout
import os, sys, functools
import requests
try:
from PIL import Image
except ImportError:
@CodyKochmann
CodyKochmann / cicd-life-advice.md
Created February 5, 2023 17:18
CICD life advice inspired by reddit.

I need scripts to run on github webhooks just as bad as you do. But this one-size-fits-all "lets make scripts but in yaml" shit has got to go.

Yaml acts as the "purely ci details". Script logic goes in... SCRIPTS!

Every CI/CD engine has a million different 'input' layers - environment variables, repo variables, workflows from various branches, maybe the git commit object. Oftentimes your scripts will have the ability to jam more variables into the 'input' layer for later scripts - such as in the case of the github environment variables. UNFORTUNATELY, it's never clear WHICH input layers are available to WHICH parts of the script. "Oh, no, you can't use outputs from this script to as arguments for something in our yaml, because the yaml is calculated first." Well thanks, Mr Nadella, I'll just torch my entire pipeline and start over.

My form of dynamic ci materializes all variables into logged and exam-able ci code. Hidden ci assembly magic was one of the first things I got rid of because life triggered

@CodyKochmann
CodyKochmann / pg_kv_store_functions.sql
Last active April 6, 2022 23:17
postgres function based kv storage for sql algorithms.
-- -------------------------------------------
-- This is an implementation of a key, value
-- store for function based kv storage for
-- different sql based algorithms to utilize
-- in postgres.
-- -------------------------------------------
-- Author: Cody Kochmann
-- license: MIT
-- -------------------------------------------
from functools import wraps
from threading import Timer, Semaphore
import requests
def service_request_rate_limit(per_minute: int):
assert isinstance(per_minute, int), per_minute
assert per_minute > 0, per_minute
lock = Semaphore(per_minute)