Skip to content

Instantly share code, notes, and snippets.

View JamieMason's full-sized avatar

Jamie Mason JamieMason

View GitHub Profile
@JamieMason
JamieMason / mockPromise.ts
Created March 14, 2025 08:24
mockPromise
/** Create a mock promise whose lifecycle can be controlled */
const mockPromise = (mockFn: jest.Mock) => {
let resolve: (_: unknown) => void
let reject: (_?: unknown) => void
let promise: Promise<unknown>
mockFn.mockImplementation(() => {
promise = new Promise((_resolve, _reject) => {
resolve = _resolve
@JamieMason
JamieMason / get-github-reaction-usernames.md
Last active February 5, 2025 15:06
Get usernames of every GitHub user leaving a reaction to an issue or pull request

Get usernames of every GitHub user leaving a reaction to an issue or pull request

Anyone leaving a 👍, ❤️ etc.

Paste into the Browser console on the GitHub issue page.

Array.from(
  new Set(
 $$('[aria-label="Add or remove reactions"] + [role="tooltip"]')
@JamieMason
JamieMason / log-x-state-inspector-events-to-the-browser-console.md
Last active March 21, 2025 08:10
Log XState inspector events to the Browser Console

Log XState inspector events to the Browser Console

A small inspect function to log events to the browser console, when you expand a group you see a log of the full event object.

Screenshot

Screenshot

Usage

@JamieMason
JamieMason / easy-to-read-css-module-class-names-in-astro-or-vite.md
Last active January 8, 2025 12:27
Easy to read CSS module class names in Astro or Vite

Easy to read CSS module class names in Astro or Vite

You can use a custom generateScopedName function to generate class names, in development mode only, that are easier to read.

import path from "path";
import { defineConfig } from "astro/config";

export default defineConfig({
  vite: import.meta.env.PROD
@JamieMason
JamieMason / on-active-service-worker.md
Created December 16, 2024 13:53
on active service worker

onActiveServiceWorker

Abandoned this as being over the top, but saving it as this Gist.

import { isDev } from '@builder.io/qwik/build';

let memo: Promise<ServiceWorker> | null;

export async function getActiveServiceWorker(): Promise<ServiceWorker> {
@JamieMason
JamieMason / unfollow-everyone-on-bsky-app.md
Last active December 4, 2024 09:04
Unfollow everyone on bsky.app
@JamieMason
JamieMason / copy-versions.js
Created November 26, 2024 09:47
Use same versions as another local package.json
const from = require('/Users/foldleft/Dev/foo/bar/package.json');
const to = require('./package.json');
Object.entries(from.dependencies).forEach(([name, version]) => {
if (to.dependencies[name]) {
to.dependencies[name] = version;
}
});
Object.entries(from.devDependencies).forEach(([name, version]) => {
@JamieMason
JamieMason / create-syncpack-issue-reproduction.md
Created October 30, 2024 13:04
Create Syncpack Issue Reproduction

Create Syncpack Issue Reproduction

Delete all files in the current directory except for this script, lerna.json, package.json, pnpm-workspace.yaml, and syncpack.config.cjs. Also delete all empty directories except for the .git directory.

Put this script at create-syncpack-issue-reproduction.js in the root of the repo.

const child_process = require("child_process");
const fs = require("fs");
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"basics": {
"name": "Jamie Mason",
"label": "Contract Frontend Developer",
"image": "https://gravatar.com/userimage/16898393/f029df3d231c137b8aa1300b94aec33c.jpeg?size=300",
"email": "[email protected]",
"url": "https://github.com/JamieMason",
"summary": "Hi,\nI'm Jamie Mason from Leeds in England and I'm a Contract Front-End Developer. I help Companies of all shapes and sizes to create accessible, performant, engaging Applications in a sustainable and maintainable manner.\n\nAbout me and what I'm looking for:\n\n💼 Front-End focused, with 24 years experience building for the web.\n💅 A Senior Designer before switching fully to Front-End Development in 2011.\n🌎 Open to remote roles in UK or EU, or hybrid in Leeds.\n⭐ Previously at Sky Sports, Sky Bet, William Hill, and others.\n👔 Contract and Freelance experience with The Premier League, Betfair, and Shell.\n😄 Pretty friendly guy.\n\nOrigina