Skip to content

Snippets#

Import JSONL into PostgreSQL#

psql -d mydb -c "create table log ( id serial primary key, data jsonb not null);"

# escape the slashes and pipe it in (otherwise Postgres will drop drop slashes intended to escape quotation marks, etc)
sed 's/\\/\\\\/g' log.jsonl | psql -d mydb -c "copy log ( data ) FROM STDIN;"

Generate password#

tr -cd '[:alnum:]' < /dev/urandom | fold -w64 | head -n 1

Node check path exists#

import { stat } from 'fs/promises'

const exists = async (path) => {
  try {
    const fileInfo = await stat(path);
    if (!fileInfo.isFile() && !fileInfo.isDirectory()) { return false }
    return true;
  } catch (_e) {
    return false;
  }
};

DSLR webcam#

sudo apt-get install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg build-essential libelf-dev linux-headers-$(uname -r)
sudo bash -c 'modprobe v4l2loopback; gphoto2 --set-config-value whitebalance="Auto"; gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video*'

Test page: gUM Test Page

OpenSSL get ocsp for nginx stapling file#

SERVER_CER="" # Cert file
issuer_url=$(openssl x509 -noout -text -in $SERVER_CER | grep "CA Issuers - URI:" | cut -d: -f2,3)
curl -Lo $SERVER_CER.issuer.der $issuer_url
openssl x509 -inform DER -in $SERVER_CER.issuer.der -out $SERVER_CER.issuer.pem
URL=$(openssl x509 -in $SERVER_CER -text | grep "OCSP - URI:" | cut -d: -f2,3)
openssl ocsp -noverify -no_nonce -respout $SERVER_CER.ocsp -issuer $SERVER_CER.issuer.pem -cert $SERVER_CER -url $URL

gitls#

git ls-files --sparse --full-name -z | xargs -0 -I FILE -P 20 git log --date=iso-strict-local --format='%ad %>(14) %cr %<(5) %an  %h ./FILE' -- FILE | sort --general-numeric-sort

This lists the files and hashes for each git commit and file:

2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./index.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./out/index.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./out/xhr-sync-worker.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./package.json
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./package-lock.json

gitls1#

git ls-files --sparse --full-name -z | xargs -0 -I FILE -P 20 git log -1 --date=iso-strict-local --format='%ad %>(14) %cr %<(5) %an  %h ./FILE' -- FILE | sort --general-numeric-sort

Similar to the above but only showing the most recent hash for each file:

2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./index.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./out/index.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./out/xhr-sync-worker.js
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./package.json
2023-10-08T19:37:06+02:00     2 weeks ago  Svante Richter  ff0c3d7 ./package-lock.json

gitls-commits#

git log --pretty=format: --name-only | sed '/^$/d' | sort | uniq -c | sort -g

This shows which files have been in commits the most:

 7 mkdocs.yml
 8 .vscode/settings.json
14 index.js
19 bookmarks.md

git clean all untracked#

git clean -Xdf

Copy-paste stuff#

ಠ_ಠ
ಥ_ಥ
シ