Skip to content

Instantly share code, notes, and snippets.

View blakek's full-sized avatar
☦️

Blake Knight blakek

☦️
View GitHub Profile
@blakek
blakek / combine-audio
Last active May 14, 2024 13:08
Audio file tools
#!/usr/bin/env bash
set -eo pipefail
directory="$1"
cd "$directory"
files=()
# Get `wav` files, ignoring `other.wav`
for file in *.wav; do
if [[ $file != "other.wav" ]]; then
@blakek
blakek / fix-junk.js
Created October 28, 2023 00:41
Fix Node.js 17+ "digital envelope routines::initialization error"
const crypto = require("crypto");
// HACK: Fix Node.js 17+ "digital envelope routines::initialization error"
// https://stackoverflow.com/q/69692842/1130172
const origCreateHash = crypto.createHash;
crypto.createHash = (algorithm, options) => {
const newAlgorithm = algorithm === "md4" ? "md5" : algorithm;
return origCreateHash(newAlgorithm, options);
};
@blakek
blakek / fontElementMap.js
Created October 18, 2023 18:32
Find font usage on a page and what elements use it
function fontElementMap(selector = "*", onlyVisible = true) {
const allElements = document.querySelectorAll(selector);
const fontElements = {};
for (element of allElements) {
const style = window.getComputedStyle(element);
const fontFamily = style.getPropertyValue("font-family");
if (!fontFamily) {
continue;
@blakek
blakek / example-limit-stream-output.bash
Last active September 19, 2023 20:07
Stream output limit in Bash
#! /usr/bin/env bash
# Formatting helpers
bold() {
printf "\033[1m%s\033[0m\n" "$*"
}
dim() {
printf "\033[2m%s\033[0m\n" "$*"
}
@blakek
blakek / runtime.bash
Created September 15, 2023 21:07
Bash module idea
#!/usr/bin/env bash
declare -A IMPORTS
# Returns the path of the script of the caller
function relative_path() {
dirname "${BASH_SOURCE[1]}"
}
# Imports a module
export enum KnownPaths {
GetHelp = "/app/get-help",
RunDetail = "/app/history/:runId"
}
/** Parses a string type into an object of route params */
type ExtractRouteParams<T extends string> = string extends T
? Record<string, string>
: T extends `${infer _Start}:${infer Param}/${infer Rest}`
? { [K in Param | keyof ExtractRouteParams<Rest>]: string }
@blakek
blakek / import-url.js
Created April 10, 2023 19:14
Run basic external code from a Zapier code step
async function importURL(url) {
const vm = require("vm");
const res = await fetch(url).then((r) => r.text());
return vm.runInThisContext(res, { filename: url });
}
// Example usage:
//
// await importURL(
// "https://gist.githubusercontent.com/blakek/660a8881ae56641d8804971b848df17e/raw/0fb0ec0646d5c8dc353dd9dadc9f5d8ccb7821b2/queryStringParse.js"
@blakek
blakek / transpose.bash
Created March 30, 2023 14:43
Music file manipulation
#!/usr/bin/env bash
set -eo pipefail
##
# Transpose a song from one key to another.
##
version='0.0.1'
# Formatting functions
@blakek
blakek / math-homework-check.ts
Created March 3, 2023 02:13
7th grader homework checker - TypeScript functions that can be used to calculate the area and perimeter of a circle
const PI = 3.14;
const CircleSize = {
Quarter: 0.25,
Half: 0.5,
Full: 1,
};
type WithRadiusOrDiameter = { r?: number; d?: number };
type WithPercent = { percent: typeof CircleSize[keyof typeof CircleSize] };
@blakek
blakek / raspberry-pi-print-server.md
Created January 4, 2023 17:11
WIP: Setting up an ancient Dell 1130 printer using Samsung printer drivers

Raspberry Pi - Print Server

Installing print server and drivers.

Print Server

  1. Install CUPS:
sudo apt install cups