Skip to content

Instantly share code, notes, and snippets.

function foo () {
const log = () => console.log(a);
// log(); (1)
const a = 42;
log();
}
foo();
// https://twitter.com/thecat/status/1427419888650383364
const values = [
[1, 2, 3],
[4, 5],
[6, 7, 8],
];
console.log(values.reduce((xs, cs) => cs.flatMap(c => xs.map(x => [...x, c])), [[]]));
@redeyes2015
redeyes2015 / index.js
Last active August 20, 2021 02:46 — forked from jasnell/index.js
Getting loopy with JavaScript
'use strict';
const {
createHistogram,
performance: {
timerify
}
} = require('perf_hooks');
const users = [
// Copied from https://www.gss.com.tw/blog/parser-combinators
type Option<T> = T | undefined;
type Parser<T> = (input: string) => [Option<T>, string];
const str
: (s: string) => Parser<string>
= (s) => (input) => {
if (input.startsWith(s)) return [s, input.slice(s.length)];
return [, input];
};
test.only('Array of objects not parsed correctly #252', function (st) {
st.deepEqual(qs.parse('param[][id]=X&param[][id]=Y'), {
param: [
{ id: ['X', 'Y'] }
]
});
// the same as default
st.deepEqual(qs.parse('param[][id]=X&param[][id]=Y', { separateArrayItem: 'never' }), {
param: [
{ id: ['X', 'Y'] }
@redeyes2015
redeyes2015 / day_23.js
Last active December 23, 2020 06:23
Advent of Code 2020 Day 23: Poorman's singly-linked list
function round (state, current, max) {
const p1 = state[current];
const p2 = state[p1];
const p3 = state[p2];
state[current] = state[p3];
let dest = current - 1;
const pickuped = [p1, p2, p3];
while (dest == 0 || pickuped.includes(dest)) {
if (dest == 0) {
@redeyes2015
redeyes2015 / day_15.js
Created December 15, 2020 06:18
Advent of Code 2020 Day 15 .... naive
function solve (ns, end) {
const seenMap = new Map();
function say (n, idx) {
if (!seenMap.has(n)) {
seenMap.set(n, [idx]);
return;
}
const record = seenMap.get(n);
record[1] = record[0];
// ~/.deno/deno run --allow-net --allow-read ./deno-test-redirect-server.ts
import { serve } from "https://deno.land/std/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
console.log(req.url);
@redeyes2015
redeyes2015 / UseSendToBody.vue
Created July 26, 2019 05:07
Vue: append some rendered content at the end of body
<template>
<div>
<button role="button" @click="foo += 1" >Click me!</button>
<SendToBody >
<h1>Current Foo: {{ foo }}</h1>
</SendToBody>
</div>
</template>
<style scoped>
https://jstrieb.github.io/urlpages/#JTBBJTNDIURPQ1RZUEUlMjBodG1sJTNFJTBBJTNDaGVhZCUzRSUwQSUzQ3N0eWxlJTNFJTBBJTNBcm9vdCUyMCU3QiUwQSUyMG1heC13aWR0aCUzQSUyMDY0cmVtJTNCJTBBJTdEJTBBJTNDJTJGc3R5bGUlM0UlMEElM0NzY3JpcHQlMjB0eXBlJTNEJTIydGV4dCUyRmphdmFzY3JpcHQlMjIlM0UlMEElMEElM0MlMkZzY3JpcHQlM0UlMEElM0MlMkZoZWFkJTNFJTBBJTNDYm9keSUzRSUwQSUzQ2gxJTNFSGV5JTJDJTIwaG93JTIwaXMlMjB0aGlzJTIwcG9zc2libGUlM0YlM0MlMkZoMSUzRSUwQSUzQ3AlM0VMb3JlbSUyMGlwc3VtJTIwZG9sb3IlMjBzaXQlMjBhbWV0JTJDJTIwY29uc2VjdGV0dXIlMjBhZGlwaXNjaW5nJTIwZWxpdCUyQyUyMHNlZCUyMGRvJTIwZWl1c21vZCUyMHRlbXBvciUyMGluY2lkaWR1bnQlMjB1dCUyMGxhYm9yZSUyMGV0JTIwZG9sb3JlJTIwbWFnbmElMjBhbGlxdWEuJTIwQWRpcGlzY2luZyUyMGF0JTIwaW4lMjB0ZWxsdXMlMjBpbnRlZ2VyJTIwZmV1Z2lhdCUyMHNjZWxlcmlzcXVlJTIwdmFyaXVzLiUyMEV0JTIwbWFsZXN1YWRhJTIwZmFtZXMlMjBhYyUyMHR1cnBpcyUyMGVnZXN0YXMuJTIwRXJhdCUyMG5hbSUyMGF0JTIwbGVjdHVzJTIwdXJuYSUyMGR1aXMlMjBjb252YWxsaXMuJTIwQXQlMjBhdWd1ZSUyMGVnZXQlMjBhcmN1JTIwZGljdHVtJTIwdmFyaXVzLiUyMERvbmVjJTIwbWFzc2ElMjBzYXBpZW4lMjBmYXVjaWJ1cyUyMGV0JTIwbW9sZXN0aWUlMjBhYy4lMjBTY2Vs