Skip to content

Instantly share code, notes, and snippets.

View potch's full-sized avatar

Potch potch

View GitHub Profile
@potch
potch / blog.js
Created December 12, 2023 05:10
potch.me site generator 2023
// if one file is too unwieldy you probably shouldn't have rolled your own blog yet again, POTCH
const start = Date.now();
const fs = require("fs").promises;
const path = require("path");
const crypto = require("crypto");
const Handlebars = require("handlebars");
const markdown = require("markdown-it");
const frontmatter = require("front-matter");
const prism = require("markdown-it-prism");
@potch
potch / potchs-cool-framework.js
Created October 23, 2023 06:05
Potch's Cool Framework
// potch's cool framework!
export const signal = value => {
const subs = new Set();
const set = v => {
value = v;
subs.forEach(s => s(value));
};
return {
set value(v) { set(v) },
@potch
potch / ld-console-snippet.js
Created June 1, 2023 19:08
Web console snippet for capturing launchdarkly flag info out of the UI as a CSV
((s = (e, l) => e.querySelector(l)) =>
Array.from(document.querySelectorAll('[data-test-id="table-body"] tr'))
.map((e) =>
[
s(e, '[data-test-id="copy-code-button"]').innerText,
s(e, "a").href,
s(e, '[headers="FlagListTable-variation"]>div>span:last-child')
.innerText,
s(
e,
@potch
potch / dom.js
Created April 30, 2022 20:02
small dom generation code, compatible with htm
const set = (el, o) => {
if (o === null) return
if (typeof o === 'function') {
set(el, o(el))
} else if (o instanceof Array) {
el.append(...o)
} else if (o instanceof Promise) {
o.then(r => set(el, r))
} else if (typeof o === 'object' && !(o instanceof Node)) {
Object.entries(o).forEach(p => el.setAttribute(p[0], p[1]));
@potch
potch / listSelector.lua
Last active March 16, 2022 13:21
Playdate list item selector that unifies d-pad and crank input
-- listSelector.lua
-- by potch
-- MIT License
-- Playdate item selector that unifies d-pad and crank input
-- useful for menus where you want to allow either crank or arrow input.
-- First argument `count` is the number of items.
-- second argument `options` is a table with the following optional fields:
-- `initSelected`: the position of the item selected at start. default is 0.
-- `crankScale`: # of crank degrees for each item. default is 90.
@potch
potch / bayer.lua
Last active March 5, 2022 05:53
Small Lua library for working with bayer filters for use with playdate.graphics
-- bayer.lua v1.0
-- by Potch
-- MIT License
-- hard-code smallest bayer
local bayer2 = { [0] = 0x0, [1] = 0x2, [2] = 0x3, [3] = 0x1 }
-- t should be a 64 entry table of 1 and 0s, indexed at 0
-- returns a 1-indexed table of bytes for use with playdate.graphics.setPattern
local function toBytes(t)
@potch
potch / LICENSE
Created July 1, 2020 21:53
potch's static site generator. MIT license but I can't recommend it.
MIT License
Copyright (c) 2020 Potch
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@potch
potch / procedure-fuzzer.js
Created January 3, 2020 22:18
procedure solver for Advent of Code 2019's Day 17
let input = 'L,8,R,10,L,10,R,10,L,8,L,8,L,10,L,8,R,10,L,10,L,4,L,6,L,8,L,8,R,10,L,8,L,8,L,10,L,4,L,6,L,8,L,8,L,8,R,10,L,10,L,4,L,6,L,8,L,8,R,10,L,8,L,8,L,10,L,4,L,6,L,8,L,8,';
let out = [];
// convert every substr occurence in `arr` to a symbol in `str`
// toSymbols('12345123',['123','45']) yields 'ABA'
function toSymbols(str, arr) {
arr.forEach((s, i) => {
let re = new RegExp(s, 'g');
str = str.replace(re, String.fromCharCode(65 + i));
});
@potch
potch / tractorbeam.js
Created December 19, 2019 06:48
you really got a hold on me
const fs = require('fs');
const { IntCode, test } = require('../IntCode.js');
class Grid {
constructor({data, width, height}) {
if (data) {
this.data = data;
this.width = data[0].length;
this.height = data.length;
}
@potch
potch / findSubSequences.js
Last active December 17, 2019 08:28
Find the subsequences from Advent of Code 2019 Day 17 Part 2 by random sampling
let input = 'L,8,R,10,L,10,R,10,L,8,L,8,L,10,L,8,R,10,L,10,L,4,L,6,L,8,L,8,R,10,L,8,L,8,L,10,L,4,L,6,L,8,L,8,L,8,R,10,L,10,L,4,L,6,L,8,L,8,R,10,L,8,L,8,L,10,L,4,L,6,L,8,L,8,';
let out = [];
// convert every substr occurence in `arr` to a symbol in `str`
// toSymbols('12345123',['123','45']) yields 'ABA'
function toSymbols(str, arr) {
arr.forEach((s, i) => {
let re = new RegExp(s, 'g');
str = str.replace(re, String.fromCharCode(65 + i));
});