Skip to content

Instantly share code, notes, and snippets.

View gibson042's full-sized avatar

Richard Gibson gibson042

View GitHub Profile
@gibson042
gibson042 / editor-tweaks.user.js
Last active November 25, 2024 16:13
Editor Tweaks user script
// ==UserScript==
// @name Editor Tweaks
// @namespace https://github.com/gibson042
// @description <{Command,Ctrl}+[;BIK…]> commands to control Markdown inside textareas, {Command,Ctrl}+Alt+mousedown to toggle monospace.
// @source https://gist.github.com/gibson042/13f4bf8ee4c0905c0abcb0f4edbcf55f
// @updateURL https://gist.github.com/gibson042/13f4bf8ee4c0905c0abcb0f4edbcf55f/raw/editor-tweaks.user.js
// @downloadURL https://gist.github.com/gibson042/13f4bf8ee4c0905c0abcb0f4edbcf55f/raw/editor-tweaks.user.js
// @version 0.6.1
// @date 2024-11-25
// @author Richard Gibson <@gmail.com>
#!/usr/bin/env python
description = """
Replaces JSON Schema/OpenAPI "allOf" arrays with an expansion of their contents.
An "allOf" array containing a reference to its parent schema is not replaced,
although the self-reference is removed.
"description" and "summary" are not copied from a $ref target unless it is
a duplicate of the previous $ref target.
@gibson042
gibson042 / od.sh
Created January 6, 2021 19:48
Use gawk to implement `od`-like behavior for system recovery
#!/bin/sh
# Explanation:
# * `-v CHUNK_SIZE=128 -v CHUNK_OFFSET=0 -v CHUNK_COUNT=32` configures the process:
# * 128 octets per chunk
# * don't skip any leading chunks
# * stop after outputting data for 32 chunks (i.e., 128×32=4 KiB of data)
# * `LC_ALL=C` makes sure that numbers above 127 don't get transformed into multi-octet sequences.
# * `--re-interval` and `RS=".{" CHUNK_SIZE "}"` expresses fixed-length records of CHUNK_SIZE octets.
# * `OCTETS` is a string of all possible octets 0x00 through 0xFF in numerical order.
# * `NR>CHUNK_OFFSET` only matches after the first CHUNK_OFFSET records.
@gibson042
gibson042 / route.sh
Created January 14, 2021 00:21
Use awk to implement `ip route`-like behavior
#!/bin/sh
awk '
BEGIN { OFS="\t"; HEX_LOWER="0123456789abcdef" }
FILENAME ~ /trie$/ { if($0 ~ "/32 host") ADDRS[ipv4_decimal_to_bits(prev)]=prev; prev=$2; next }
FNR==1 { print $1, $2, $3, $8, "Source"; next }
{
iface=$1; dest=hex_reverse_octets($2); gateway=hex_reverse_octets($3); mask=hex_reverse_octets($8);
source_guess=lookup_by_longest_prefix(ADDRS, apply_bitmask(hex_to_bits(dest), hex_to_bits(mask)));
print iface, ipv4_hex_to_decimal(dest), ipv4_hex_to_decimal(gateway), ipv4_hex_to_decimal(mask), source_guess;
}
@gibson042
gibson042 / highlight.awk
Last active March 10, 2022 15:28
highlight.awk - ANSI-format matching input (e.g. to supplement grep)
#!/usr/bin/awk -f
BEGIN {
USAGE="Usage: %s rule=<awk ERE pattern>/<ANSI SGR format>[.<extra format>]... [rule=...]...";
EXAMPLE="Example: </etc/resolv.conf %s rule='#.*'/dim rule='([0-9]+[.]){3}[0-9]+'/bold.red";
CMD=ENVIRON["_"];
if(!CMD) CMD="$0";
USAGE=sprintf(USAGE, CMD) "\n" sprintf(EXAMPLE, CMD);
}
function usage(msg, code) {
if(msg!="") print "[ERROR] " msg > "/dev/stderr";
@gibson042
gibson042 / 2021.19.js
Last active December 23, 2021 22:42 — forked from gnarf/2021.19.js
Advent of Code 2021 - Day 19 Part 2 - Console Golfing
(await(await fetch("https://adventofcode.com/2021/day/19/input")).text(Q=[])).replace(r=/.*,.*|(\d+)/g,(d,s)=>(s?Q:q).push(s?q=[]:eval(`[${d}]`)))
T=[],[...'+3+6!-!+5-7-6!+!-8-5!+8+6+8+5!-8-6-!-7-7+-7!-!-1--7!+!+8+!-7!+8+-7-8-!-7!-8-2-!+!+3+6!+!-5-7-6!-!-!-7-7+-7!+!0--8'.replace(r,t=>'+!-!!!+!!!'.slice(t))][F="flatMap"]((s,i)=>((T[i/9|0]??=[])[i%9/3|0]??=[])[i%3]=s+1|0)
M=(t,m)=>t.map(o=>m?o[D]((s,p,i)=>s+m[i]*p,0):t[F](p=>m+1?N=(n=o.l[D]((s,o,i)=>s+A(o-p.l[i]),0))>N?n:N:p[D="reduce"]((s,p,i)=>s+A(o[i]-p)**2,0)))
for(A=Math.abs,S=JSON.stringify,R=Q[N=0],R.l=[0,0,0];Q.find(q=>(t=(H=q.l?0:M(R)[F]((e,x)=>M(q)[F]((d,B)=>d[D]((c,a)=>c+e.includes(a),0)>11?[[x,B]]:[]))).length>11&&T.find(t=>H.find(([r,u])=>(V[r=S(u=R[r][F]((p,i)=>p-M(t,q[u])[i]))]|=0,++V[r]>11?U=q.l=u:0),V={})))&&q[F](P=>S(P=M(t,P)[F]((p,i)=>U[i]+p))in R[F](S)||R.push(P))););M(Q,0)
N

Keybase proof

I hereby claim:

  • I am gibson042 on github.
  • I am gibson042 (https://keybase.io/gibson042) on keybase.
  • I have a public key ASCRNcg7OOoL54GcUj1bi8I32hMOhyM4J5at14t33fj_6go

To claim this, I am signing this object:

@gibson042
gibson042 / emoji-spy.user.js
Last active October 15, 2023 18:20
Emoji Spy user script
// ==UserScript==
// @name Emoji Spy
// @namespace https://github.com/gibson042
// @description Add tooltips describing emoji sequence and symbol code points.
// @source https://gist.github.com/gibson042/5495b65eed0d8e371c155c0dd91262b1
// @updateURL https://gist.github.com/gibson042/5495b65eed0d8e371c155c0dd91262b1/raw/emoji-spy.user.js
// @downloadURL https://gist.github.com/gibson042/5495b65eed0d8e371c155c0dd91262b1/raw/emoji-spy.user.js
// @version 0.3.0
// @date 2023-10-15
// @author Richard Gibson <@gmail.com>
@gibson042
gibson042 / anchors-up.user.js
Last active March 20, 2025 16:26
Anchors Up user script
// ==UserScript==
// @name Anchors Up
// @namespace https://github.com/gibson042
// @description Navigates to in-page anchors upon {Command,Ctrl}+click or (with Shift) scrolls to arbitrary elements.
// @source https://gist.github.com/gibson042/73dfb17bfa7d35a9fb2e4c396365c321
// @updateURL https://gist.github.com/gibson042/73dfb17bfa7d35a9fb2e4c396365c321/raw/anchors-up.user.js
// @downloadURL https://gist.github.com/gibson042/73dfb17bfa7d35a9fb2e4c396365c321/raw/anchors-up.user.js
// @version 0.5.0
// @date 2023-09-08
// @author Richard Gibson <@gmail.com>
@gibson042
gibson042 / confluence-fixer.user.js
Last active March 5, 2025 06:17
Confluence Fixer user script
// ==UserScript==
// @name Confluence Fixer
// @namespace https://github.com/gibson042
// @description Fixes Confluence annoyances (inline comment jumps and page reloads, stacked notifications, hidden anchors and excerpts, etc.).
// @source https://gist.github.com/gibson042/6e42cb4341f6a308af5e8515cceb3d5a
// @updateURL https://gist.github.com/gibson042/6e42cb4341f6a308af5e8515cceb3d5a/raw/confluence-fixer.user.js
// @downloadURL https://gist.github.com/gibson042/6e42cb4341f6a308af5e8515cceb3d5a/raw/confluence-fixer.user.js
// @version 0.6.0
// @date 2023-09-08
// @author Richard Gibson <@gmail.com>