Skip to content

Instantly share code, notes, and snippets.

@nicwolff
nicwolff / custom.css
Last active December 12, 2023 15:58
CSS user stylesheet to fix new JIRA idiocy
div:has(> div[role="presentation"] > div[aria-label="Status"]), .ebGQhf, .css-1eekove,
div:has(> div > button[aria-label="Open workload by assignee summary modal"]) {
display: none !important;
}
.erfPIV {
height: auto !important;
}
.ikRSVX, .gQAHKO {
grid-template-rows: [start card-detail] 40px [end] !important;
height: 41px !important;
@nicwolff
nicwolff / redis-pipe.sh
Last active November 9, 2023 22:59
Pipe commands in Redis format
#!/usr/bin/env bash
while read CMD; do
# each command begins with *{number arguments in command}\r\n
XS=($CMD); printf "*${#XS[@]}\r\n"
# for each argument, we append ${length}\r\n{argument}\r\n
for X in $CMD; do printf "\$${#X}\r\n$X\r\n"; done
done
@nicwolff
nicwolff / pipster.sh
Created August 14, 2023 15:20
Pipster – update PyPI dependencies
#!/usr/bin/env bash
# Update the Python packages listed in requirements.top and their dependencies, then "freeze"
# those versions into requirements.txt. If anything has changed, push a branch and open or update
# a pull request.
set -evo pipefail
GITHUB_AUTH_URL="https://$GITHUB_TOKEN:[email protected]/"
WORKDIR="/tmp/pipster-work"
@nicwolff
nicwolff / init.lua
Last active February 8, 2021 00:00
Hammerspoon script to move/resize window under mouse cursor with modifier keys
function get_window_under_mouse()
-- Invoke `hs.application` because `hs.window.orderedWindows()` doesn't do it
-- and breaks itself
local _ = hs.application
local my_pos = hs.geometry.new(hs.mouse.getAbsolutePosition())
local my_screen = hs.mouse.getCurrentScreen()
return hs.fnutils.find(hs.window.orderedWindows(), function(w)
return my_screen == w:screen() and my_pos:inside(w:frame())
@nicwolff
nicwolff / assert_contains.py
Created August 28, 2018 22:22
assert_contains: Is every value in nested data structure p at the same path in f?
def assert_contains(full, partial):
"""Is every value in nested data structure p at the same path in f?"""
assert isinstance(full, type(partial)), '{} != {}'.format(full, partial)
if isinstance(partial, dict):
for k, v in partial.items():
assert k in full, "No key '{}' in {}".format(k, dict(full))
assert_contains(full[k], v)
return True
if isinstance(partial, (list, tuple)):
for i, partial_item in enumerate(partial):
@nicwolff
nicwolff / cacheops.md
Created September 28, 2017 19:42
Cacheops EVALSHA storms – causes and fixes

What cacheops does

  1. cacheops watches Django make database queries, and caches the resultsets

  2. When a record is created or updated, cacheops invalidates all the cached resultsets that might have included that record

How cacheops does that

cacheops operates on the Django ORM's QuerySet objects. When a QuerySet is executed, cacheops analyzes its where structure to build and cache a simplified list of the fields that were filtered on. Then after it caches the resultset itself, it adds the resultset's cache key to a list of queries that used those filter fields with the same values.

@nicwolff
nicwolff / bloat.sql
Created September 18, 2017 14:48
Pg index bloat
WITH btree_index_atts AS (
SELECT nspname, relname, reltuples, relpages, indrelid, relam,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
FROM pg_index
JOIN pg_class ON pg_class.oid=pg_index.indexrelid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN pg_am ON pg_class.relam = pg_am.oid
WHERE pg_am.amname = 'btree'
),
@nicwolff
nicwolff / test-server.pl
Created December 15, 2016 23:37
Simple Perl test TCP server
#!/usr/bin/perl
use Socket;
# Set up listener
$on_port = $ARGV[0] || 25;
$proto = getprotobyname("tcp");
socket (Server, PF_INET, SOCK_STREAM, $proto) || die ("socket");
setsockopt(Server, SOL_SOCKET,SO_REUSEADDR,1) || die ("setsockopt");
import boto3
from base64 import b64decode
import json
from urllib2 import urlopen, Request
ENCRYPTED_GITHUB_TOKEN = (
# aws kms encrypt --profile <PROFILE_NAME> --region <REGION>
# --key-id <KMS_KEY_ID> --plaintext <GITHUB_ACCESS_TOKEN>
# --query CiphertextBlob --output text
)
@nicwolff
nicwolff / .bashrc
Created February 9, 2016 22:29
Pass password and command to PSSH sudo
( echo "PASSWORD" ; echo "COMMAND" ) | pssh -t 1 -h ~/host_list -P -I "sudo -S su -"