Skip to content

Instantly share code, notes, and snippets.

Avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / pg_kv_store_functions.sql
Last active Apr 6, 2022
postgres function based kv storage for sql algorithms.
View pg_kv_store_functions.sql
-- -------------------------------------------
-- 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
-- -------------------------------------------
View gitlab_request_rate_limit.py
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)
@CodyKochmann
CodyKochmann / .tmux.conf
Created Oct 12, 2021
My personal tmux.conf I like to start with when setting up new systems.
View .tmux.conf
# by: Cody Kochmann
# license: MIT
#
# This is my personal tmux.conf I like to start with when setting up new systems before I tune
# things for the specific monitors I need to work with.
#
# This has been a comfortable "starting point" for ultrawides, pocket laptops (like gpd pocket),
# and even iphones. (yes, I daily drive tmux on my iphone. I win the oddball fight.)
#
@CodyKochmann
CodyKochmann / stateful-embedded-postgres-python-functions.sh
Created Oct 2, 2021
stateful embedded postgres python functions
View stateful-embedded-postgres-python-functions.sh
#
# description: demo of shared data in plpython functions
# by: Cody Kochmann
# date: 2021-10-02
#
testdb=> -- pg has two magic vars for plpython3u functions
testdb=> -- SD | dict | per function memory
testsb=> -- GD | dict | global shared function memory
testdb=> CREATE FUNCTION state_test (t TEXT)
RETURNS TEXT[]
@CodyKochmann
CodyKochmann / disable_hyperthreading.sh
Created Jul 23, 2021
how to turn off hyperthreading from a vm with no bios privs
View disable_hyperthreading.sh
#!/bin/bash
# by: Cody Kochmann
#
# this program tells the kernel to turn off the
# odd cores on a host. This is useful when you
# want to disable hypertheading in an ec2
# instance and dont have bios access to do it
# at the chip level.
seq 0 127 | awk '{print "echo 0 > /sys/devices/system/cpu" $1 * 2 + 1 "/online"}' | bash -x
@CodyKochmann
CodyKochmann / iterate_stdin.go
Created Jul 15, 2021
iterate stdin lines in golang
View iterate_stdin.go
// by: Cody Kochmann
// this iterates stdin lines to a golang channel
package main
import (
"os"
"bufio"
)
@CodyKochmann
CodyKochmann / backup-docker-volumes.sh
Created Jul 11, 2021
How to backup docker volumes on a docker host.
View backup-docker-volumes.sh
#!/bin/bash
# this script backs up all existing docker volumes to archives
# by: Cody Kochmann
cd $(mktemp -d)
docker volume ls \
| grep -v 'volume-backups' \
| awk '/local/ {print "docker run -i --rm -v "$2":/outside:ro -v volume-backups:/bak --workdir /outside registry.gitlab.com/icody/containers/debian tar czfv /bak/"strftime("%Y.%m.%d.%H.%M.%S-",systime())$2".tar.gz ./"}' \
| tee backup-volumes.sh
bash -x backup-volumes.sh
@CodyKochmann
CodyKochmann / jq-join-objects-example.sh
Created Jul 2, 2021
join two json objects with jq
View jq-join-objects-example.sh
➜ tmp.QicwwydLd3 cat a.json
{
"name": "Cody Kochmann",
"flags": [
"engineer",
"scientist"
],
"stats": {
"commits": 45
}
@CodyKochmann
CodyKochmann / docker_flatten.sh
Created Jul 1, 2021
bash script to flatten docker images down to one layer of files
View docker_flatten.sh
#!/bin/bash
# by: Marcin Pohl
# created: 2021-06-30
# this bash script js used to flatten and optimize
# docker images for better file access times.
function docker_flatten() {
[[ $# -ne 2 ]] && ( echo "Example usage: docker_flatten python:3.7-slim python:3.7-slim-flat"; exit 255 )
local SRC="$1" # Name or SHA of the source image
@CodyKochmann
CodyKochmann / random_cron_schedules.py
Created Jun 18, 2021
functions to generate random cron schedules for different common intervals in python
View random_cron_schedules.py
#!/usr/bin/env python
# Author: Cody Kochmann
# Created: 2021-06-18
# License: MIT
from random import randint
class cron():
@property
def hourly(self):