Skip to content

Instantly share code, notes, and snippets.

View examosa's full-sized avatar

Jules Amonith examosa

View GitHub Profile
@examosa
examosa / fetch-instances.js
Last active January 8, 2026 15:42
Userscripts
const gh = (path) => new URL(path, 'https://nobsdelivr.private.coffee/gh');
const getJson = (url) =>
fetch(url, { headers: { Accept: "application/json" } })
.then((response) => response.json())
.catch((error) => {
console.error(error);
});
async function fetchInstances() {
@examosa
examosa / loader.mjs
Last active July 27, 2026 14:48
Node.js HTTPS ESM Loader
import { registerHooks } from "node:module";
import {
Worker,
MessageChannel,
receiveMessageOnPort,
} from "node:worker_threads";
const channel = new MessageChannel();
const { port1: mainPort, port2: workerPort } = channel;
mainPort.unref();
@examosa
examosa / useSharedState.ts
Created February 12, 2026 04:40
React useSharedState hook
import { useCallback, useEffect, useMemo, useState } from "react";
const store = new Map<symbol, unknown>();
const listeners = new Map<symbol, Set<(value: any) => void>>();
function useSharedState<T>(key: symbol, initialValue?: T) {
const [state, setState] = useState(() =>
store.has(key) ? (store.get(key) as T) : initialValue,
);
@examosa
examosa / make-launch-agent.sh
Last active July 2, 2026 15:49
Shell scripts
#!/usr/bin/env nix
#! nix shell nixpkgs#argc nixpkgs#jq --command bash
# shellcheck shell=bash
# vim: filetype=bash
# @describe Bootstrap a launch agent plist
# @option -c --command! Command to run
# @option -C --cwd <DIR> Working directory
# @option -e --env*, Environment variables
# @option -l --label! Launch agent label
# @option -n --name! Program name
@examosa
examosa / spawn-async.mjs
Last active July 23, 2026 18:20
JS Snippets
import { spawn } from "node:child_process";
import { on, once } from "node:events";
async function spawnAsync(...args) {
const subprocess = spawn(...args);
/** @see https://github.com/sindresorhus/nano-spawn/blob/cc231e2c7/source/spawn.js#L24-L26 */
subprocess.once("error", () => {});
const until = ["spawn", "close"].reduce((out, event) => {
out[event] = once(subprocess, event);