This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); |
NewerOlder