Skip to content

Instantly share code, notes, and snippets.

@lyind
lyind / project-migration.mjs
Last active July 4, 2025 23:27
Dump, load and copy items and custom fields between GitHub ProjectV2 projects and local files
#!/usr/bin/env node
import fs from 'fs';
/**
* Copy GitHub ProjectV2 items and custom fields from one project to another, dump or load them from a file.
*
* The project configuration isn't modified and fields are mapped by *exact* name.
*
* Usage:
@lyind
lyind / html-to-markdown.js
Last active May 13, 2025 23:08
Standalone ES6 function to convert HTML to Markdown in a single pass
/** Convert HTML to Markdown in a single pass.
*
* @param html The HTML document as a string.
* @param headingOffset The heading level offset (0-6).
* @return {string} The converted Markdown document.
*/
function htmlToMarkdown(html, headingOffset = 0) {
const isSpace = c => c === ' ' || c === '\n' || c === '\r' || c === '\t' || c === '\f'
const STATE_TEXT_UNINDENT = 0
@lyind
lyind / analyze-drive-files.mjs
Last active March 20, 2025 00:39
NodeJS script to extract external Google Drive access permissions from data exported using GAM
// Prepare a CSV file with Google Drive file information for analysis of externally accessible files
//
// Requires Node.js 22 or later
//
// USAGE:
// gam all users print filelist allfields formatjson | node analyze-drive-files.mjs 'EMAIL_DOMAIN_1|EMAIL_DOMAIN_n' > external-drivefiles.csv
//
// EMAIL_DOMAIN are own domain names of the organization (e.g. example.com), with matching records filtered out.
//
// The CSV file can then be uploaded to Google Drive.
@lyind
lyind / personio-clear-inbox.js
Last active February 19, 2025 16:36
Script to clear all messages from the Personio UI's inbox
/** Script to clear all messages from the Personio UI's inbox
*
* USAGE:
* 1. Open Personio Inbox
* 2. (optionally) Select filters (to only clear certain messages)
* 3. Open the browser's console (F12)
* 4. Paste this script and run it
*/
let count = 0;
let lastClickMillies = 0
@lyind
lyind / parse-csv-stream.js
Last active October 5, 2024 21:39
Parse a CSV (RFC4180) file stream (without loading the whole file) in modern JavaScript
/**
* From https://github.com/MattMorgis/async-stream-generator
*/
async function* nodeStreamToIterator(stream) {
for await (const chunk of stream) {
yield chunk;
}
}
/**
@lyind
lyind / main.py
Last active March 13, 2024 17:15
Convert PlantUML (sequence) diagram source to Mermaid syntax
#!/usr/bin/env python3
"""
main.py: Convert PlantUML diagram source code to Mermaid source.
Based on this StackOverflow answer: https://stackoverflow.com/a/76625003
"""
import sys
import re
@lyind
lyind / alarm.py
Created March 2, 2022 22:45
Real-time Helper for GeigerLog - Perform actions (like alarm) when certain CPM/CPS values are exceeded
#!/usr/bin/env python3
#
# Instant alarming script for monitoring current CPM/CPS value in GeigerLog DB
# author: Jonas Zeiger <jonas.zeiger@talpidae.net>
#
# The variables ALARM_CPM and ALARM_CPS are going to be set in the shell executing ACTION_COMMAND.
#
# Examples:
#
# $ ./alarm.py data/gmc300e.logdb 4 50 /bin/bash -c 'echo $ALARM_CPS $ALARM_CPM'
# btrfs fi usage /
Overall:
Device size: 953.88GiB
Device allocated: 436.08GiB
Device unallocated: 517.80GiB
Device missing: 0.00B
Used: 250.72GiB
Free (estimated): 345.39GiB (min: 345.39GiB)
Free (statfs, df): 345.39GiB
function dunzip()
{
path="$(dirname "$1")"
if [ -n "$path" ] && [[ "$path" != */ ]]
then
path="$path/"
fi
new_name="$(basename -s ".gz" "$1")"
gunzip -d -c "$1" | gunzip -d -c > "$new_name"
@lyind
lyind / crypo-digest.js
Created November 27, 2019 14:12
Web Crypto API digest() Wrapper
'use strict';
/* Implement basic wrappers around crypto.subtle API.
* see: https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
*/
const getDigest = () =>
{
if (crypto)
{