Skip to content

Instantly share code, notes, and snippets.

@thewhodidthis
thewhodidthis / Makefile
Last active February 28, 2023 17:15
Extremely random pixel sorted image maker
View Makefile
# The filenaming timestamp
D?=$$(date +"%Y%m%d%s")
# Width
W?=2
# Height
H?=8
# How many numbers total?
S?=$$(bc <<< "3 * $W * $H")
# How many random numbers?
G?=$$(bc <<< "3 * $H")
View Makefile
build:
@mkdir $$(date +"%Y%m%d%s"); cd $$_; echo "$$(date +"%Y%m%d%s")" > index.html; zip ../"$$(date +"%Y%m%d%s")".zip -r .
@thewhodidthis
thewhodidthis / main.js
Created December 6, 2022 09:32
Common hashing algorithms in JS
View main.js
export function crc32c(data, n = data.length, poly = 0xEDB88320) {
let crc = 0xFFFFFFFF
for (let i = 0; i < n; i += 1) {
crc = crc ^ data.charCodeAt(i)
for (let j = 0; j < 8; j += 1) {
crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1
}
}
@thewhodidthis
thewhodidthis / snippet.sh
Created February 15, 2022 04:54
Retouch image files to reflect EXIF dates
View snippet.sh
find ./*.jpg -exec sh -c 'touch -d $$(date -j -f "%Y:%m:%d %H:%M:%S" "$$(identify -format "%[EXIF:DateTimeOriginal]" {})" +%Y-%m-%dT%H:%M:%S) {}' \;
@thewhodidthis
thewhodidthis / README.md
Last active January 17, 2022 17:44
Draft SSG
View README.md

Poor man's static site builder

Basic,

\
redcarpet content.md |          # 1. Parse markdown
mustache - data.yaml.mustache | # 2. Save as unescaped HTML in proxy template
mustache - layout.mustache |    # 3. Fill in page layout
tidy # 4. Fix indentation
@thewhodidthis
thewhodidthis / links
Last active July 16, 2022 19:14
Helps extract Bookmarks.plist data into JSON
View links
View sleep.js
/*
const run = async () => {
await sleep(1000)
console.log("One")
await sleep(1000)
console.log("Two")
}
run()
*/
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:22
Numerical string to number convert
View index.js
// "1.2" -> 1.2
console.assert(convert('1.2') === 1.2)
// " " -> " " (not a number)
console.assert(isNaN(convert(' ')))
console.assert(isNaN(convert('')))
// "12a" -> "12a" (not a number)
console.assert(convert('12a') === '12a')
console.assert(isNaN(convert('12a')))
// null -> null (not a number)
console.assert(convert(null) === null)
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:22
Super basic text diff probe via terser
View index.js
'use strict'
const { exec } = require('child_process')
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const util = require('util')
const { minify } = require('terser')
const readFile = util.promisify(fs.readFile)
@thewhodidthis
thewhodidthis / index.js
Last active August 8, 2021 16:23
Find the median value in array of numbers
View index.js
const assert = require('assert')
// I'm trusting R's built in helper for calculating expected values
// https://repl.it/repls/IroncladLightpinkBookmark
const samples = [
{
input: [187],
expected: 187,
},
{