Skip to content

Instantly share code, notes, and snippets.

View mnvr's full-sized avatar
☀️

Manav Rathi mnvr

☀️
View GitHub Profile
@mnvr
mnvr / pq.js
Created November 22, 2024 06:05
A simple promise queue in JavaScript to serialize the execution of a bunch of promises
// A promise queue
const q = []
const add = (task) => {
let handlers;
const p = new Promise((...args) => (handlers = args));
q.push({task, handlers});
if (q.length == 1) next();
return p;
@mnvr
mnvr / pre-commit
Created July 12, 2025 05:33
A pre commit hook that prevents committing on main
#!/bin/sh
if test "$(git rev-parse --abbrev-ref HEAD)" = "main"
then
echo "error: cannot commit to main"
exit 1
fi