This file contains hidden or 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 Req { | |
| imagePath?: string; // path to an image on the server. take precedence over image when both present. should be mutually exclusive. | |
| image?: Uint8Array; // image as bytes. either imagePath or image should present. saved to fs and db. | |
| args?: string[]; // the concatenation of imagePath args is passed to shell commands. saved in db | |
| meta?: string; // metadata of this request, e.g., camera ID. a JSON string. saved in db. | |
| lang?: string; // the type of the underling shell command. defaults to python for now. can be bash with a straight forward extension. can be any language to support various plugins. | |
| } | |
| interface Res { | |
| outputImage?: Uint8Array; // image as bytes. |
This file contains hidden or 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
| ; exp ::= (exp exp) ; function application | |
| ; | (lambda (var) exp) ; anonymous function | |
| ; | var ; variable reference | |
| (define (cps-convert term cont) | |
| (match term | |
| [`(,f ,e) | |
| ; (exp exp) => (exp-cps exp-cps cont) | |
| (let (($f (gensym 'f)) | |
| ($e (gensym 'e))) |
This file contains hidden or 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 strict'; | |
| function paint(grid, x, y, colr = nextColr()) { | |
| grid.push([x, y, colr]); | |
| } | |
| // generate a random color | |
| let colr = -1; | |
| function nextColr() { | |
| colr++; | |
| return colr; |
This file contains hidden or 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 dgtFib(n) { | |
| const phi = (1 + Math.sqrt(5)) / 2; | |
| return Math.ceil(n * Math.log10(phi) - Math.log10(5) / 2); | |
| } |
This file contains hidden or 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* oddGen() { | |
| var n = 3; | |
| while (true) { | |
| yield n; | |
| n += 2; | |
| } | |
| } | |
| function streamfy(gen) { | |
| var iter = gen(); |
This file contains hidden or 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 diff(S, L) { | |
| var N = S.length, | |
| M = L.length; | |
| var V = []; | |
| // virtual point (0, -1) for computing 0-path | |
| V[1] = { | |
| x: 0, | |
| parent: null | |
| }; |
This file contains hidden or 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 inc(x) { | |
| return x & 1 ? inc(x >> 1) << 1 : x | 1; | |
| } | |
| function dec(x) { | |
| return x & 1 ? x ^ 1 : dec(x >> 1) << 1 | 1; | |
| } | |
| function add(x, y) { | |
| return x ? add(dec(x), inc(y)) : y; |
This file contains hidden or 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
| /** | |
| * A so-called pseduo recursive function that calculates | |
| * factorials with the assistance of a recursive function | |
| * @param {function} fact, a function that recursively | |
| * calculate factorials | |
| */ | |
| let f = function (fact) { | |
| return function (n) { | |
| return n <= 2 ? n : n * fact(n - 1); | |
| }; |