Avatar

@healeycodes

1 like17 public vals
Joined February 2, 2023
# hm
1
export const test = "test :)";
1
2
3
4
5
6
let { _hits } = await import("https://esm.town/v/healeycodes/_hits");
export const hitCounter = () => {
_hits++;
return `${_hits}`;
};
1
2
3
export let testHtml = function (req, res) {
res.send("<html><h1>hi!</h1></html>");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
// E.g. from a user's perspective (not the real execution time!)
export const measureValTownE2e = (async () => {
const count = 5;
let evalTimes = [];
for (let i = 0; i < count; i++) {
let start = Date.now();
await fetch("https://api.val.town/eval/(()=%3E1+1)()");
evalTimes.push(Date.now() - start);
}
console.log(
`average e2e eval time: ${(
evalTimes.reduce((a, b) => a + b, 0) / count
).toFixed(0)}ms (fastest was ${evalTimes
.sort((a, b) => a - b)[0]
.toFixed(0)}ms)`
);
let userFuncTimes = [];
for (let i = 0; i < count; i++) {
let start = Date.now();
await fetch("https://api.val.town/eval/@healeycodes.addOnes()");
userFuncTimes.push(Date.now() - start);
}
console.log(
`average e2e user function time: ${(
userFuncTimes.reduce((a, b) => a + b, 0) / count
).toFixed(0)}ms (fastest was ${userFuncTimes
.sort((a, b) => a - b)[0]
.toFixed(0)}ms)`
);
})();
1
export const addOnes = () => 1 + 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Input: `r1bk3r/p2pBpNp/n4n2/1p1NP2P/6P1/3P4/P1P1K3/q5b1`
Output: `
|♜| |♝|♚| | | |♜|
|♟︎| | |♟︎|♗|♟︎|♘|♟︎|
|♞| | | | |♞| | |
| |♟︎| |♘|♙| | |♙|
| | | | | | |♙| |
| | | |♙| | | | |
|♙| |♙| |♔| | | |
|♛| | | | | |♝| |`
*/
export let fenToASCIIboard = async function (fenString) {
// https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
const charToPiece = {
K: "♔",
Q: "♕",
R: "♖",
B: "♗",
N: "♘",
P: "♙",
k: "♚",
q: "♛",
r: "♜",
b: "♝",
n: "♞",
p: "♟︎",
};
// https://codegolf.stackexchange.com/a/78330
const fenToBoard = (a) =>
a.split`/`.map(
(x) =>
[
,
...x.replace(/\d/g, (t) => " ".repeat(t)),
`
`,
].join`|`
).join``;
return fenToBoard(fenString)
.split("")
.map((c) => charToPiece[c] || c)
.join("");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Is WebAssembly verboten?
/*
(module
(func (export let "addTwo") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add))
*/
export export let webassemblyExample = (async () => {
const source = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, 2, 1, 0,
7, 10, 1, 6, 97, 100, 100, 84, 119, 111, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1,
106, 11, 0, 10, 4, 110, 97, 109, 101, 2, 3, 1, 0, 0,
]);
const wasmModule = new WebAssembly.Module(source);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const { addTwo } = wasmInstance.exports;
for (let i = 0; i < 10; i++) {
console.log(addTwo(i, i));
}
})();
Next