This file contains hidden or 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
| function getElementDepth(el) { | |
| return el.parentElement ? 1 + getElementDepth(el.parentElement) : 0 | |
| } |
This file contains hidden or 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
| function getAllElements(root) { | |
| root = root || document.body | |
| const out = [root] | |
| if (root.children) { | |
| Array.from(root.children).forEach(child => { | |
| out.push(...getAllElements(child)) | |
| }) | |
| } | |
This file contains hidden or 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
| function querySelectorAsync(selector, ttl, root) { | |
| return new Promise((resolve, reject) => { | |
| let interval, timeout | |
| ttl = ttl || 10000 | |
| root = root || document | |
| try { | |
| timeout = setTimeout(() => { | |
| clearInterval(interval) | |
| throw new Error(`Unable to find element with selector "${selector}"!`) |
This file contains hidden or 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
| // In CommonJS format: | |
| if (require.main === module) { | |
| console.log("Invoked directly!") | |
| } | |
| // In ES module format: | |
| if (import.meta.url.includes(process.argv[1])) { | |
| console.log("Invoked directly!") | |
| } |
This file contains hidden or 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
| # A JS-like object in Python is an object whose properties can be set on-the-fly as in | |
| # JS (i.e., without the need to define a class first). | |
| def JSObject(data={}): | |
| class JSObject: | |
| def __getattr__(self, name): | |
| return data[name] | |
| def __setattr__(self, name, value): | |
| data[name] = value |
This file contains hidden or 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
| # pyds: https://github.com/jrc03c/pyds | |
| from numpy import log | |
| from pyds import sort | |
| alpha = "abcdefghijklmnopqrstuvwxyz " | |
| quotes = "'\"‘’“”" | |
| def clean(x): |
This file contains hidden or 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 { execSync } = require("node:child_process") | |
| const { fg, fx } = require("@jrc03c/bash-colors") | |
| const { indent, unindent, wrap } = require("@jrc03c/js-text-tools") | |
| const express = require("express") | |
| const fs = require("node:fs") | |
| const path = require("node:path") | |
| const process = require("node:process") | |
| const watch = require("@jrc03c/watch") | |
| const OUT_DIR = "_site" |
This file contains hidden or 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 scrollY = 0 | |
| // to disable scrolling: | |
| scrollY = window.scrollY | |
| document.body.style.position = "fixed" | |
| document.body.style.top = `-${scrollY}px` | |
| // to enable scrolling again: | |
| document.body.style.position = "" | |
| document.body.style.top = "" |
This file contains hidden or 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
| # https://developer.mozilla.org/en-US/docs/Web/HTML/Element | |
| <a> | |
| <abbr> | |
| <address> | |
| <area> | |
| <article> | |
| <aside> | |
| <audio> | |
| <b> | |
| <base> |
This file contains hidden or 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") | |
| !(async () => { | |
| const stream = fs.createWriteStream("path/to/file") | |
| let canWrite = true | |
| let counter = 0 | |
| // optionally listen for errors | |
| stream.on("error", error => { | |
| throw error |
NewerOlder