Skip to content

Instantly share code, notes, and snippets.

@jrc03c
jrc03c / tfidf.py
Last active April 16, 2024 19:23
A quick-and-dirty tf-idf implementation in Python
# pyds: https://github.com/jrc03c/pyds
from numpy import log
from pyds import sort
alpha = "abcdefghijklmnopqrstuvwxyz "
quotes = "'\"‘’“”"
def clean(x):
@jrc03c
jrc03c / extended-build.js
Last active October 7, 2023 18:39
an updated default build script with more bells & whistles
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"
@jrc03c
jrc03c / temporarily-disable-page-scrolling.js
Created September 8, 2023 16:25
Temporarily disable page scrolling when modal or menu is open
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 = ""
@jrc03c
jrc03c / html-elements.txt
Created August 31, 2023 13:27
A list of all HTML elements (excluding deprecated elements)
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element
<a>
<abbr>
<address>
<area>
<article>
<aside>
<audio>
<b>
<base>
@jrc03c
jrc03c / file-stream-write.js
Last active August 23, 2023 16:30
Stream (write) a file to disk in Node
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
@jrc03c
jrc03c / file-stream-read.js
Last active August 23, 2023 16:31
Stream (read) a file from disk in Node
const fs = require("fs")
const readline = require("readline")
!(async () => {
const stream = fs.createReadStream("path/to/file")
const rl = readline.createInterface({
input: stream,
crlfDelay: Infinity,
})
@jrc03c
jrc03c / set_matplotlib_plot_size.py
Created June 28, 2023 22:06
set matplotlib plot size
# 8" x 4.5"
plot.rcParams["figure.figsize"] = 8, 4.5
@jrc03c
jrc03c / deep-sort.js
Last active May 29, 2023 01:07
Recursively / deeply sort an object or array in JS
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)
}
@jrc03c
jrc03c / point-is-in-triangle.js
Last active January 23, 2023 16:36
check to see if a point lies inside a triangle
const ABOVE = "above"
const BELOW = "below"
const EXACTLY_ON = "exactly_on"
function getPointRelationToLine(point, pair) {
const [p1, p2] = pair
// if the pair have the same x-values, then they either lie on a
// vertical line or are identical
if (p2[0] - p1[0] === 0) {
@jrc03c
jrc03c / build.js
Last active June 13, 2023 17:21
generic build script
const process = require("process")
const watch = require("@jrc03c/watch")
function rebuild() {
console.log("-----")
console.log(`Rebuilding... (${new Date().toLocaleString()})`)
try {
// do stuff...
console.log("Done! 🎉")