Skip to content

Instantly share code, notes, and snippets.

@wosephjeber
wosephjeber / getAllColors.js
Created October 15, 2020 22:19
Quick and dirty function for scraping colors from web page
function getAllColors() {
const COLOR_CONTAINING_PROPERTIES = ["backgroundColor", "borderTopColor", "borderRightColor", "borderLeftColor", "borderBottomColor", "color"]
let colors = []
let elements = document.querySelectorAll('*')
elements.forEach(element => {
const styles = window.getComputedStyle(element)
COLOR_CONTAINING_PROPERTIES.forEach(property => {
@wosephjeber
wosephjeber / get_all_regex_matches.ts
Created March 17, 2023 13:03
Get all regex matches in a string
function getAllRegexMatches(regex: RegExp, string: string) {
if (regex.constructor !== RegExp) {
throw new Error('not RegExp');
}
const matches = [];
let match = regex.exec(string);
if (regex.global) {
while (match) {
@wosephjeber
wosephjeber / index.js
Last active September 11, 2023 19:02
Quick Node script to find largest dependency in package.json
const { dependencies } = require('../package.json');
const deps = Object.keys(dependencies).map((p) => `${p}@${dependencies[p]}`);
function pluralize(count, singular, plural) {
if (count === 1) return `${count} ${singular}`;
return `${count} ${plural}`;
}
@wosephjeber
wosephjeber / notes.md
Created September 13, 2023 18:19
Notes from learning SolidJS

I'm learning SolidJS coming from React. I'm taking notes here on things that trip me up in the process.

  • Don't destructure props. It breaks reactivity with signals passed down as props.
  • Use untrack() to reference signal values in an effect without rerunning the effect when those signals change. Might be a less common use case? (Mine was referencing updated signal values in an interval started by the effect).
@wosephjeber
wosephjeber / waitFor.js
Created November 29, 2023 21:06
[WIP] An RTL-like `waitFor` utility, without the DOM stuff
export default async function waitFor(callback, { timeout = 1000 } = {}) {
let intervalTimer;
let lastError = null;
let pending = false;
let timeoutTimer;
return new Promise((resolve, reject) => {
function onDone(result) {
clearInterval(intervalTimer);
clearTimeout(timeoutTimer);