Skip to content

Instantly share code, notes, and snippets.

git config --global core.untrackedCache true &&
git config --global core.fsmonitor true &&
git config --global feature.manyFiles true &&
git config --global core.preloadIndex true
core.untrackedCache=true
Caches untracked file info between commands
core.fsmonitor=true
Uses built-in filesystem monitor (watches for changes instead of scanning)
feature.manyFiles=true
map ::= map_name layer+ designer time_winner? EOF { ws=implicit }
map_name ::= identifier
layer ::= layer_id "=" layer_content
layer_id ::= 'layer' digit+
layer_content::= map_symbol*
designer ::= 'designer=' identifier
time_winner ::= 'time_winner=' ('allies' | 'centrals' | 'no')
map_symbol ::= terrain_char | special_symbol
// All parsers take in a string and return a tuple of [token, remainingString]
// If a parser fails to match, it should return null
const any = (parsers) => (str) => {
for (const parser of parsers) {
const result = parser(str);
if (result) return result;
}
return null;
};
function promiseAllLimitedConcurrency<A, B>(
maxConcurrency: number,
f: (x: A) => Promise<B>,
xs: A[]
): Promise<
[
fulfilledValues: Array<PromiseFulfilledResult<B>['value']>,
rejectedReasons: Array<PromiseRejectedResult['reason']>
]
> {
type NestedGeneratorReturnType<T> = NestedGenerator<T> | T
type NestedGenerator<T> = Generator<Promise<NestedGeneratorReturnType<T>>>
async function* collectNested<T>(gen: NestedGenerator<T>) {
const pool = new Map<number, Promise<readonly [number, NestedGeneratorReturnType<T>]>>()
let key = 0
for (const p of gen) {
const currentKey = key++
pool.set(currentKey, p.then(v => [currentKey, v] as const))
}
type TSettleResult<T> = [T, undefined] | [undefined, Error];
async function settle<T>(p: Promise<T>): Promise<TSettleResult<T>> {
try {
const x = await p;
return [x, undefined];
} catch (e) {
return [undefined, e];
}
};
type Pool<T> = Map<number, Promise<readonly [number, T]>>;
async function* raceAll<T>(promises: Iterable<Promise<T>>): AsyncGenerator<T> {
const pool: Pool<T> = new Map();
let key = 0;
for (const p of promises) {
const _key = key;
pool.set(
_key,
@pennane
pennane / markdown-details-collapsible.md
Created May 24, 2024 14:17 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux
@pennane
pennane / parse_csv.js
Created May 23, 2024 09:44
parse csv file with ramda
import * as R from 'ramda'
const parse_csv_file = R.pipe(
R.split('\n'),
R.when(R.pipe(R.last, R.isEmpty), R.init),
R.map(R.split(',')),
R.converge(
(headers: string[], rows: string[][]) => rows.map(R.zipObj(headers)),
[R.head, R.tail]
)
@pennane
pennane / combinators.js
Created May 19, 2024 00:21 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))