Skip to content

Instantly share code, notes, and snippets.

View examosa's full-sized avatar

Jules Amonith examosa

View GitHub Profile
@examosa
examosa / powerSetIterative.php
Last active September 28, 2026 16:46
PHP function to create the power set of a given array
function powerSetIterative(array $items): array {
$result = [[]];
foreach ($items as $item) {
$combinations = [];
foreach ($result as $combo) {
$combo[] = $item;
$combinations[] = $combo;
}
@examosa
examosa / add-zen-search.py
Last active August 13, 2026 20:53
Add search engines to Zen browser
#!/usr/bin/env python3
"""Add a search engine to Zen Browser's preferences plist."""
import argparse
import plistlib
import sys
from pathlib import Path
from typing import Never
DEFAULT_PLIST = Path.home() / "Library/Preferences/app.zen-browser.zen.plist"
@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);
@examosa
examosa / make-launch-agent.sh
Last active September 1, 2026 14:50
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 / 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 / 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 / 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() {