Skip to content

Instantly share code, notes, and snippets.

@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

@jclosure
jclosure / init.el
Created July 14, 2021 03:57
Emacs set font-size based on monitor size.
;; set some defaults
(setq my-font-name "monospace")
(setq my-font-size 10)
;; this method seems to work on gui systems only
(when window-system
(if (eq system-type 'darwin)
(setq my-font-name "Meslo"))
(if (eq system-type 'gnu/linux)
(setq my-font-name "FiraCode"))
@jclosure
jclosure / flatten_nested_dict_paths.py
Created April 6, 2021 02:27
Generator for flattening nested dicts into a lists of path parts and value at the end
def dict_generator(indict, pre=None):
pre = pre[:] if pre else []
if isinstance(indict, dict):
for key, value in indict.items():
if isinstance(value, dict):
for d in dict_generator(value, pre + [key]):
yield d
elif isinstance(value, list) or isinstance(value, tuple):
for v in value:
for d in dict_generator(v, pre + [key]):
@jclosure
jclosure / global-gitignore.md
Created April 3, 2021 08:18 — forked from subfuzion/global-gitignore.md
Global gitignore

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

git config --global core.excludesfile ~/.gitignore

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore