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
// 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 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 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 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 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 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 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 |
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 readline = require("readline") | |
!(async () => { | |
const stream = fs.createReadStream("path/to/file") | |
const rl = readline.createInterface({ | |
input: stream, | |
crlfDelay: Infinity, | |
}) |
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
# 8" x 4.5" | |
plot.rcParams["figure.figsize"] = 8, 4.5 |
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
function deepSort(x, fn) { | |
fn = fn || ((a, b) => (a < b ? -1 : 1)) | |
if (typeof x === "object") { | |
if (x === null) return x | |
if (x instanceof Array) { | |
return x.map(v => deepSort(v, fn)).sort(fn) | |
} | |
NewerOlder