Skip to content

Instantly share code, notes, and snippets.

@jacoscaz
jacoscaz / fix-esm-import-paths.cjs
Created September 12, 2022 07:21
A small Node.js script to fix ESM import/export paths as produced by the TypeScript compiler
// Script largely inspired by:
// - https://gist.github.com/silassare/cc3db860edeea07298cb03f64738c997
// - https://github.com/dsblv/string-replace-async/blob/7a7b1c6c5db728c298ac12df05c4eaf7e0ec8805/index.js
const fs = require('fs');
const path = require('path');
const { resolve, dirname, relative, extname } = path;
const { readFile, writeFile, stat, opendir } = fs.promises;
@jacoscaz
jacoscaz / sparql.js-skypack-require-fix.js
Last active August 30, 2022 15:17
SPARQL.js as served by Skypack.dev but with an added fix for require.main usage
import require$$2$1 from "https://cdn.skypack.dev/-/rdf-data-factory@v1.1.0-ZTi0caLaeyyL4GjQhZzX/dist=es2019,mode=imports/optimized/rdf-data-factory.js";
function defaultSetTimout() {
throw new Error("setTimeout has not been defined");
}
function defaultClearTimeout() {
throw new Error("clearTimeout has not been defined");
}
var cachedSetTimeout = defaultSetTimout;
var cachedClearTimeout = defaultClearTimeout;
var globalContext;
@jacoscaz
jacoscaz / SequentialLock.js
Last active June 6, 2022 08:22
Simple sequential lock
const STATE = {
RELEASED: 'released',
ACQUIRED: 'acquired',
};
class SequentialLock {
constructor() {
this.state = STATE.RELEASED;
this.queue = []; // TODO: use a linked list for better perf as Array.prototype.shift() is very expensive in V8
@jacoscaz
jacoscaz / linked-list-persistent-cursors.ts
Created April 20, 2022 11:08
Linked list with persistent cursors
interface LinkedNode<V> {
value: V;
next: LinkedNode<V> | null;
}
export class LinkedListCursor<V> {
private _curr: LinkedNode<V>;
constructor(list: LinkedList<V>) {
@jacoscaz
jacoscaz / index.js
Created August 8, 2017 04:11
Promise-based while
function whilst(condition, action) {
return P.resolve(condition())
.then(function (proceed) {
if (!proceed) return null;
return P.resolve(action())
.then(function () {
return whilst(condition, action);
});
});
};

Keybase proof

I hereby claim:

  • I am jacoscaz on github.
  • I am jacoscaz (https://keybase.io/jacoscaz) on keybase.
  • I have a public key whose fingerprint is F67A 98DE 5FCE DD0E 2EEA 76C8 0BF7 EC1D 98EF 8CAD

To claim this, I am signing this object: