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 / gitlab-group-ci-exporter.sh
Created January 24, 2021 18:44
gitlab ci group exporter
#!/bin/bash
# spins up a new gitlab ci group exporter given a token to monitor ci pipelines for a gitlab group
# by: Cody Kochmann
GROUP_NAME=icody
CONTAINER_NAME=$GROUP_NAME-ci-exporter
CONFIG_DIR=/etc/gitlab-ci-pipelines-exporter
CONFIG_PATH=$CONFIG_DIR/config.yml
# by: Cody Kochmann
import queue
def pop_min(*iterators):
q = queue.PriorityQueue()
for i in iterators:
normalized_i = iter(i)
q.put((next(normalized_i), normalized_i))
@CodyKochmann
CodyKochmann / priority_queue_as_sorted_collection.py
Created January 9, 2021 19:57
priority queue can be a sorted collection?
>>> # by: Cody Kochmann
>>> import random, string, queue
>>> pq = queue.PriorityQueue()
>>> chars = list(string.ascii_letters)
>>> chars
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
>>> random.shuffle(chars)
>>> chars
['a', 'f', 'Y', 'h', 's', 'r', 'T', 'N', 'H', 'e', 'c', 'n', 'd', 'v', 'S', 'U', 'z', 'j', 'Q', 'x', 'J', 'p', 'E', 'm', 'C', 'u', 'V', 'F', 'D', 'P', 'k', 'y', 'X', 'L', 'w', 'G', 'i', 'W', 'I', 't', 'o', 'b', 'B', 'R', 'A', 'K', 'M', 'l', 'Z', 'O', 'g', 'q']
>>> for c in chars: # put the chars as the priority
@CodyKochmann
CodyKochmann / pop_min.py
Created January 9, 2021 19:40
pop_min 1
'''
example input
[1, 3, 5, 9]
[2, 4, 4, 8]
output
[1, 2, 3, 4, 4, 5, 8, 9]
@CodyKochmann
CodyKochmann / set-up-weekly-cleanup.sh
Created January 1, 2021 18:21
systemd cleanup files older than a week
#!/bin/bash
# by: Cody Kochmann
# set up auto cleanup of files in gitlab-runner's home that are older than 1 week
echo 'D /home/gitlab-runner 0755 gitlab-runner gitlab-runner 1w -' | tee -a /usr/lib/tmpfiles.d/home.conf
@CodyKochmann
CodyKochmann / fix-openssl-dev.sh
Created December 30, 2020 19:24
if you need openssl dev packages to work with debian, the following fixed a cargo compile for openssl
#!/bin/bash
sudo apt-get install pkg-config libssl-dev
@CodyKochmann
CodyKochmann / flash-debian-daily-for-raspberry-pi-4.sh
Last active December 30, 2020 19:59
flashes official debian daily build to sd card for raspberry pi 4
#!/bin/bash
# flashes sd cards with debian testing's daily build for raspberry pi 4
# by: Cody Kochmann
for i in "$@"
do
echo "about to flash - $i" >&2
wget -qO- 'https://raspi.debian.net/daily/raspi_4.img' | sudo dd "of=$i" bs=1M oflag=dsync status=progress
echo "done flashing - $i" >&2
done
@CodyKochmann
CodyKochmann / grafana.service
Last active December 29, 2020 20:18
how I had prometheus and grafana set up
# /etc/systemd/system/grafana.service
[Unit]
Description=grafana
Requires=syslog.service
After=syslog.service
[Service]
User=cody
Restart=always
RestartSec=10
@CodyKochmann
CodyKochmann / rsyslog.service
Last active December 26, 2020 10:40
rsyslog as a low priv user with no capabilities other than listen and log
[Unit]
# by: Cody Kochmann
# describe the service so journald logs make sense
Description=System Logging Service
# mandate that systemd ensures syslog socket is created first
Requires=syslog.socket systemd-journald.service
# note that there is a local manual
Documentation=man:rsyslogd(8)
# link to official docs online
Documentation=https://www.rsyslog.com/doc/
@CodyKochmann
CodyKochmann / systemd-socket-demo.sh
Created December 25, 2020 14:48
systemd socket testing
# for a tcp socket
systemd-socket-activate -l 2000 --inetd tee /tmp/test-tcp.log
# for a udp socket
systemd-socket-activate -l 2000 --inetd -d tee /tmp/test-udp.log