Skip to content

Instantly share code, notes, and snippets.

View ATGardner's full-sized avatar

Noam Gal ATGardner

View GitHub Profile
@ATGardner
ATGardner / read-write-lock.spec.ts
Last active October 13, 2024 13:16
this is a simple Node.js TypeScript implementation of a read-write-lock using a queue, without the need for any mutex or other synchronization mechanism.
import { setTimeout } from 'node:timers/promises'
import { ReadWriteLock, ReadWriteQueueLock } from './read-write-lock'
describe('ReadWriteQueueLock', () => {
// copied test code from https://eli.thegreenplace.net/2019/implementing-reader-writer-locks/
// console.logs are useful for understanding what happens when, and making sure the lock works as expected
async function reader(lock: ReadWriteLock, id: number, data: number[]) {
await setTimeout(Math.random() * 100)
console.log(`reader ${id} locking`)
@ATGardner
ATGardner / master2main.sh
Last active June 21, 2020 06:08
A script to convert all personal GitHub repos' default branch from 'master' to 'main'
#! /bin/bash
# The script requires jq (https://stedolan.github.io/jq/) and gh-cli (https://cli.github.com/) > 0.10
# It assumes the current user is already logged into their GitHub account, and that they have SSH access set up
# with `gh config set git_protocol ssh`
#
# The script goes over all (up to 100) personal, non-archived, non-forked repositories, that currently has 'master' as
# their default branch and replaces it with NEW_DEFAULT (defined as 'main', but can be easily changed)
#
# It clones a new local repo from each one, creates a NEW_DEFAULT branch in it, pushes it, and also sets it as the
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function alg(n) {
const array = [...Array(n).keys()];
shuffleArray(array);

Keybase proof

I hereby claim:

  • I am atgardner on github.
  • I am noamg (https://keybase.io/noamg) on keybase.
  • I have a public key ASA-95PEdmS2ayMKme0vb9_-MbiYLnZ65fcN5vzsi108jwo

To claim this, I am signing this object:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="cache-control" content="max-age=0"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
<meta http-equiv="pragma" content="no-cache"/>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
// placed in /src folder
import 'babel-polyfill';
const rsLowerC = `[a-c\\xdf-\\xf6]`;
const rsUpperC = `[A-C\\xc0-\\xd6]`;
const working1 = rsLowerC + '+' + '(?=' + rsUpperC + ')';
const reWorking1 = RegExp(working1, 'g');
const rsLowerZ = `[a-z\\xdf-\\xf6]`;
const rsUpperZ = `[A-Z\\xc0-\\xd6]`;