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 / .tmux.conf
Created October 12, 2021 15:59
My personal tmux.conf I like to start with when setting up new systems.
# 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 October 2, 2021 11:21
stateful embedded postgres python functions
#
# 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 July 23, 2021 16:22
how to turn off hyperthreading from a vm with no bios privs
#!/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 July 15, 2021 14:24
iterate stdin lines in golang
// by: Cody Kochmann
// this iterates stdin lines to a golang channel
package main
import (
"os"
"bufio"
)
@CodyKochmann
CodyKochmann / backup-docker-volumes.sh
Created July 11, 2021 15:45
How to backup docker volumes on a docker host.
#!/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 July 2, 2021 15:52
join two json objects with jq
➜ tmp.QicwwydLd3 cat a.json
{
"name": "Cody Kochmann",
"flags": [
"engineer",
"scientist"
],
"stats": {
"commits": 45
}
@CodyKochmann
CodyKochmann / docker_flatten.sh
Created July 1, 2021 00:21
bash script to flatten docker images down to one layer of files
#!/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 June 18, 2021 13:26
functions to generate random cron schedules for different common intervals in python
#!/usr/bin/env python
# Author: Cody Kochmann
# Created: 2021-06-18
# License: MIT
from random import randint
class cron():
@property
def hourly(self):
@CodyKochmann
CodyKochmann / gitlab_project_variables.py
Created June 14, 2021 14:01
api for accessing gitlab project environment variables as a python dictionary
#!/usr/bin/env python
# author: Cody Kochmann
# created: 2021-06-13
# license: MIT
from functools import partial
import json, logging
import requests
@CodyKochmann
CodyKochmann / sqlite_essentials.py
Last active June 13, 2021 19:44
My essentials for interactively working with sqlite in python.
#!/usr/bin/env python
# by: Cody Kochmann
# license: MIT
# created: 2021-06-13
import sqlite3, sys
from sqlite3 import Cursor
''' My essentials for interactively working with sqlite in python. '''