Skip to content

Instantly share code, notes, and snippets.

View pwfcurry's full-sized avatar
😺

Patrick Curry pwfcurry

😺
View GitHub Profile
@pwfcurry
pwfcurry / useWhyDidYouUpdate.ts
Created September 22, 2022 09:39
'Why did you update' React hook with render count
import { useEffect, useMemo, useRef } from "react";
import { v4 as uuid } from "uuid";
const renderCounter: { [id: string]: number | undefined } = {};
const incrementRenderCount = (id: string) => {
const next = (renderCounter[id] ?? 0) + 1;
renderCounter[id] = next;
return next;
};
@pwfcurry
pwfcurry / slow-appium-commands.js
Last active October 3, 2022 11:49
Find slow appium commands
// Usage:
// node ./slow-appium-commands.js <log file>
//
// If your logs contain ANSI colour tags (ie downloaded from semaphore), first strip with
// sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" <log file>
const fs = require("fs");
// any webdriver commands which took longer than this will be logged
const THRESHOLD = 5000; // ms
@pwfcurry
pwfcurry / enhancedStackTraces.js
Created October 4, 2022 09:49
Enhance async stack traces
// Async stack traces are often a bit useless - there is a max depth after which context is lost.
// This is a rather hacky attempt to maintain the full stack.
// https://github.com/sindresorhus/got/blob/main/documentation/async-stack-traces.md
// https://github.com/nodejs/node/issues/36126
const asyncHooks = require("async_hooks");
const traces = new Map();
asyncHooks