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
/* eslint-disable no-var, vars-on-top, no-param-reassign */ | |
function redirect(uri) { | |
// remove repeated slashes | |
uri = uri.replace(/\/+/g, "/"); | |
// remove trailing slash | |
if (uri !== "/" && uri.endsWith("/")) { | |
uri = uri.slice(0, -1); | |
} | |
return uri; |
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
// Type-level Brainfuck interpreter in TypeScript | |
// Copyright (c) 2020 Susisu ([email protected]) | |
type State<P, M, I, O, R, K> = { | |
program: P, | |
memory: M, | |
input: I, | |
output: O, | |
return: R, | |
skip: K, |
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 * as lq from "@loquat/simple"; | |
const key = Symbol("handle"); | |
type PerformFunc = <U>(parser: lq.Parser<U>) => U; | |
export function handle<T>(func: (perform: PerformFunc) => T): lq.Parser<T> { | |
return new lq.StrictParser(state => { | |
let currentState = state; | |
let currentErr = lq.ParseError.unknown(state.pos); |
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
const ref = <T>(f: (x: T) => T) => { | |
const r = { val: f }; | |
return () => r; | |
}; | |
const id = <T>(x: T) => x; | |
// r: <T>() => { val: (x: T) => T } | |
const r = ref(id); | |
// unsafe instantiations of r | |
const r1 = r<number>(); |
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
const apply = <T, U>(f: (x: T) => U) => (x: T) => f(x); | |
const foo = <T extends { foo: number }>(x: T) => x.foo; | |
const foo2 = apply(foo); // : (x: {}) => number; | |
foo({ foo: 1, bar: 2 }); // OK | |
foo({}); // error | |
foo2({ foo: 1, bar: 2 }); // OK | |
foo2({}); // OK??? |
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
-- tf-random 0.5 | |
import System.Random.TF.Gen | |
-- Utility functions to choose one of splitted generators. | |
left g = let (g', _) = split g in g' | |
right g = let (_, g') = split g in g' | |
-- Initialize a generator (the seed is not relevant). | |
gen = seedTFGen (0, 0, 0, 0) | |
-- Let `b` be the tree position bits of a generator and `bi` the index in it. Now `b` and `bi` of |
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
λ bin/bench ./gists.json 10000 pegjs | |
Node.js version: 10.9.0 | |
JSON file: ./gists.json | |
Loops: 10000 | |
pegjs: 56181.985ms | |
λ bin/bench ./gists.json 10000 parsimmon | |
Node.js version: 10.9.0 | |
JSON file: ./gists.json | |
Loops: 10000 |
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
module Iterator: sig | |
type 'a t | |
type 'a result = | |
| Done | |
| Continue of 'a | |
val next: 'a t -> 'a result | |
end |
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
interface IParser<T> { } | |
declare class Opt<K extends string, T> { | |
constructor(key: K, parser: IParser<T>); | |
} | |
declare const string: IParser<string>; | |
declare const number: IParser<number>; | |
declare class OptParser<P extends {}> { |
NewerOlder