Skip to content

Instantly share code, notes, and snippets.

View pwfcurry's full-sized avatar
😺

Patrick Curry pwfcurry

😺
View GitHub Profile
@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
@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 / 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 / sainsbury-receipt.js
Created October 20, 2020 09:24
Converts Sainsbury json receipt to csv
// node <this file.js> <sainsbury json receipt>
const fs = require("fs");
const file = process.argv[2];
const data = JSON.parse(fs.readFileSync(file, { encoding: "utf8", flag: "r" }));
console.log("name,qty,total");
data.order_items.map(item => {
const name = item.product.name.replace(",", "");
@pwfcurry
pwfcurry / hasKey.tsx
Created December 3, 2021 14:17
TypeScript: narrowing unknown
// https://stackoverflow.com/questions/70028907/narrowing-an-object-of-type-unknown
export const hasKey = <K extends string>(key: K, object: unknown): object is Record<K, unknown> =>
typeof object === "object" && object !== null && key in object;
@pwfcurry
pwfcurry / sem_workflows.js
Created June 3, 2021 11:37
Combine and print paginated semaphore workflow results
const fs = require("fs");
const pageCount = 69; // replace with actual page count
const workflows = [];
for (let i = 1; i < pageCount + 1; i++) {
const file = fs.readFileSync(`./sem_workflows_page_${i}.json`);
const page = JSON.parse(String(file));
page.forEach((w) => workflows.push(w));
@pwfcurry
pwfcurry / sem-workflows.sh
Created June 3, 2021 11:34
List all semaphore workflows for a project
#!/bin/bash
# Replace <API_TOKEN> with your token from https://me.semaphoreci.com/account
# Replace <PROJECT_ID> with the project ID (can get this by describing a job: https://docs.semaphoreci.com/reference/api-v1alpha/#describe-job)
# Run the following to get the page count (in the `link` header, rel=last) & replace 69 below with the value:
#
# curl -sIXGET -H "Authorization: Token <API_TOKEN>" \
# "https://countingup.semaphoreci.com/api/v1alpha/plumber-workflows?project_id=<PROJECT_ID>"
#
@pwfcurry
pwfcurry / prettify_detox.js
Created March 29, 2019 13:10
Hacky script to process Detox failure output
if (process.argv.length !== 3) {
console.error("Expects exactly one argument");
return;
}
const path = process.argv[2];
console.log(path + "\n");
const lineReader = require('readline').createInterface({
input: require('fs').createReadStream(path)
});
@pwfcurry
pwfcurry / example.sh
Last active February 27, 2019 13:44
Record iOS simulator & convert to gif
# Record Simulator screen - CTRL+C to finish
xcrun simctl io booted recordVideo appVideo.mov
# Optionally, convert to gif to attach to a GitHub PR:
# install dependencies
brew install ffmpeg -- --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265
brew install imagemagick
# convert .mov to a series of PNGs