Skip to content

Instantly share code, notes, and snippets.

@jclosure
jclosure / PC_setup.md
Last active January 30, 2023 16:58
Notes: Windows Setup recipe for Linux Cloud Development

PC Setup notes

Enable CPU virtualization in the BIOS

After reboot continue

Turn off firewall

Install wsl

Open a CMD session as Administrator

@jclosure
jclosure / count_commits.sh
Last active January 19, 2023 17:56
Count the commits and lines modified by a user, from a start date, across a bunch of projects.
#!/bin/bash
## usage: just run script (relative file paths to project adjusted)
# $ count_commits.sh
## array of project dirs
declare -a project_dirs=("./foo" "./bar" "./qux")
# ignore files with these extensions
excludes="':!*.ipynb' ':!*.json' ':!*.log' ':!*.pb' ':!*.fb' ':!*.bin'"
@jclosure
jclosure / gorm_cascading.go
Created August 17, 2022 05:24
Cascade UPDATES and DELETES from parent to child table relations. Golang - Gorm
// HOW TO EXPRESSS CASCADING RELATIONS BETWEEN RELATED GORM MODELS
// if you update the server_id, it updates the server_id on sessions with old server_id
// if you delete the server, it deletes all sessions with same server_id
type Server struct {
Model
ServerID uuid.UUID `gorm:"type:uuid; primaryKey"`
# ...
Sessions []Session `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}
@jclosure
jclosure / python_inotify_fs_watcher.py
Last active January 23, 2024 11:16
Using watchdog to inspect all changes for a dir + pattern. Useful for seeing all activity during debugging inotify handlers.
import logging
import os
import time
import traceback
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
MAP_DATA_DIR = "/tmp/foo"
@jclosure
jclosure / my-clipboard-plugin.zsh
Created February 16, 2022 05:52
Perfect blend of system clipboard with zsh killring
cutbuffer () {
emulate -L zsh
zle kill-region
zle set-mark-command -n -1
killring=("$CUTBUFFER" "${(@)killring[1,-2]}")
if which clipcopy &>/dev/null; then
printf "%s" "$CUTBUFFER" | clipcopy
else
echo "clipcopy function not found. Please make sure you have Oh My Zsh installed correctly."
@jclosure
jclosure / history_tracking.sql
Created January 31, 2022 08:57
Automatic history tracking in postgres.
-- create a separate schema to hold our history table
CREATE SCHEMA IF NOT EXISTS logging;
CREATE TABLE IF NOT EXISTS logging.t_history (
id serial,
tstamp timestamp DEFAULT now(),
schemaname text,
tabname text,
operation text,
who text DEFAULT current_user,
new_val json,
@jclosure
jclosure / logstash.conf
Created January 25, 2022 05:00
Logstash parsing json string fields, merging, and replacing event
# test as follows:
# 1. start logstash:
# logstash -f ~/logstash.conf --config.reload.automatic
# 2. send it data:
# echo '{"container": "/spiff", "bleh": "blah"}' | nc localhost 6060
input {
tcp {
@jclosure
jclosure / Makefile
Created January 8, 2022 02:30
modify yaml on the fly as part of a make task
UNAME := $(shell uname)
###
#
# assuming a yaml like this:
# main:
# device: 21
#
###
@jclosure
jclosure / README.md
Created September 27, 2021 05:14 — forked from ReSTARTR/README.md
ZeroMQ sample in Go and Python. (with MonitoredQueue)

Versions

  • zeromq: stable 3.2.2
  • go: 1.0.3
    • gozmq: zmq_3_x
  • python: 2.7.3
    • pyzmq: 13.0.2

Usage