Skip to content

Instantly share code, notes, and snippets.

View jherr's full-sized avatar
💭
Making a bunch of videos for the coming weeks

Jack Herrington jherr

💭
Making a bunch of videos for the coming weeks
View GitHub Profile
@jherr
jherr / .eslint.json
Last active December 30, 2023 23:52
Walkthrough of massive lint experiment
{
"root": true,
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"standard",
"plugin:no-unsanitized/DOM",
@jherr
jherr / runify.js
Created September 22, 2023 21:54
runify.js
export function runify(obj) {
if(Array.isArray(obj)) {
return obj.map(runify);
} else if(typeof obj === 'object') {
let rune = $state(obj);
let output = {};
for(let key in rune) {
if(typeof obj[key] === 'object') {
obj[key] = runify(obj[key]);
}
@jherr
jherr / middleware.ts
Created July 27, 2023 15:43
Astro HTMX Middleware
/*
There is currently no way to get a `.astro` route to just return the HTML
without the CSS and JS. This is a workaround to remove the CSS and JS from
the HTML response of HTMX fragment routes.
The premise here is that HTMX fragments won't required additional styles because
the Tailwind for the entire experience is alreay precomputed. And second that it will
not require additional JS because ... HTMX.
*/
const HTMX_FRAGMENT_ROUTES = ["/prompt"];

Frameworks like React require that when you change the contents of an array or object you change its reference. Or push another way that you don't change arrays but instead create new arrays with updated values (i.e. immutability).

There are older array methods that are incompatible with immutability because they alter the array in place and don't change the array reference. These are mutable (or destructive) methods.

Shown below are replacements for the array destructive methods (e.g. push, pop, splice, sort, etc.) that will create new array references with the updated data.

Solutions are provided using the spread operator and also the newer "change array by copy" methods (toSpliced, toSorted, toReversed and with).

Setting Value At Index

@jherr
jherr / spreadTest.js
Created April 24, 2023 14:41
Basic performance tests of the spread operator
const numberFormat = new Intl.NumberFormat("en-US", { style: "decimal" });
const TEST_ARRAY_SIZE = 1000;
const TEST_COUNT = 1000;
const pushUsingPush = (arr) => {
arr.push(5);
return arr;
};
@jherr
jherr / package.json
Created January 27, 2022 23:27
Simple monorepo starter
{
"name": "packages",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"start": "concurrently \"wsrun --parallel start\""
},
"workspaces": [
@jherr
jherr / Setup.md
Last active January 1, 2024 06:06
Jack's Setup
@jherr
jherr / ang-pokemon-mfe.md
Last active July 20, 2021 16:14
ang-pokemon-mfe process

Original article

First create the NX workspace and the initial application named search:

npx create-nx-workspace@latest ang-pokemon-mfe

Set it up as angular, with the name search and SCSS for the styling:

@jherr
jherr / index.ts
Last active July 5, 2021 14:43
Decorator starting point
const delay = <T>(time: number, data: T): Promise<T> =>
new Promise((resolve) =>
setTimeout(() => {
resolve(data);
}, time)
);
class Users {
async getUsers() {
return await delay(1000, []);
@jherr
jherr / advanced-event-handler.ts
Created May 17, 2021 14:29
Code for No BT TS - Challenge 3
class EventProcessor {
handleEvent(eventName: ..., data: ...): void {
}
addHandler(handler: ...) {
}
getProcessedEvents(): ...[] {
}
}