This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* range(start: number, stop?: number, step = 1): Generator<number> { | |
if (stop == null) { | |
stop = start; | |
start = 0; | |
} | |
for (let i = start; step > 0 ? i < stop : i > stop; i += step) { | |
yield i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mutex, MutexInterface } from 'async-mutex'; | |
type ObjectId = string; | |
type Object = number; | |
type ObjectMap = Map<ObjectId, { | |
object?: Object; | |
lock: MutexInterface; | |
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { MutexInterface } from 'async-mutex'; | |
import { Mutex } from 'async-mutex'; | |
/** | |
* Single threaded read-preferring read write lock | |
*/ | |
class RWLock { | |
protected _readerCount: number = 0; | |
protected _writerCount: number = 0; | |
protected lock: Mutex = new Mutex(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mutex, MutexInterface } from 'async-mutex'; | |
type ObjectId = string; | |
type Object = number; | |
type ObjectMap = Map<ObjectId, { | |
object?: Object; | |
lock: MutexInterface; | |
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import callbackify from 'util-callbackify'; | |
type Callback<P extends Array<any> = [], R = any, E extends Error = Error> = { | |
(e: E, ...params: Partial<P>): R; | |
(e?: null | undefined, ...params: P): R; | |
}; | |
async function maybeCallback<T>( | |
f: () => Promise<T>, | |
callback?: Callback<[T]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use this when object lifetime matches object "readiness" | |
*/ | |
class X { | |
protected _destroyed: boolean = false; | |
public static async createX(): Promise<X> { | |
return new X; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mutating input and output | |
const rec = (inputs: Array<number>, outputs: Array<number> = []) => { | |
if (!inputs.length) { | |
return outputs; | |
} else { | |
const input = inputs.shift()!; | |
outputs.push(input + 1); | |
return rec(inputs, outputs); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sh | |
aws ecr get-login-password --region ap-southeast-2 | docker login --username AWS --password-stdin <ENTERID>.dkr.ecr.ap-southeast-2.amazonaws.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pickle | |
import numpy as np | |
from pathlib import Path | |
from typing import List, Tuple | |
# expect CIFAR10 to point to a directory like | |
# . | |
# ├── batches.meta | |
# ├── data_batch_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fcntl | |
import contextlib | |
import time | |
@contextlib.contextmanager | |
def lockpidfile(filepath): | |
with os.fdopen( | |
os.open(filepath, os.O_RDWR | os.O_CREAT, mode=0o666), |