Skip to content

Instantly share code, notes, and snippets.

View kt3k's full-sized avatar

Yoshiya Hinosawa kt3k

View GitHub Profile
import * as remix from "https://cdn.skypack.dev/@remix-run/server-runtime";
console.log(remix);
@kt3k
kt3k / dl.sh
Last active December 9, 2021 05:47
#!/bin/sh +x
VERSION=a1d6b53acd05ae0c598f13c0e597b9daa342d35b
TARGET=x86_64-apple-darwin
curl -o deno.zip https://dl.deno.land/canary/$VERSION/deno-$TARGET.zip
rm -rf ./deno
unzip deno.zip
./deno --version
cp deno deno-$VERSION
@kt3k
kt3k / main.ts
Last active September 23, 2021 09:04
import { delay } from "https://deno.land/[email protected]/async/delay.ts";
import { listenAndServe } from "https://deno.land/[email protected]/http/server.ts";
listenAndServe("", async () => {
console.log("Got request", req.url);
await delay(5000);
new Response("Hello World\n");
});
@kt3k
kt3k / main.js
Created September 23, 2021 07:58
addEventListener("fetch", (event) => {
const x = event.respondWith(new Promise((resolve) => {
setTimeout(() => {
resolve(new Response(`${typeof x} ${x.constructor.name}`));
}, 300);
}));
});
@kt3k
kt3k / analyze-deps.ts
Last active July 2, 2021 05:37
Analyze deps of JavaScript/TypesScript
import { transform } from "https://esm.sh/sucrase";
import { init, parse } from "https://unpkg.com/[email protected]/dist/lexer.js";
(async () => {
await init;
const pathToAnalyze = "https://esm.sh/react";
const resp = await fetch(pathToAnalyze);
console.log("Analyzing", resp.url);
import { JSDOM } from "https://jspm.dev/jsdom";
const doc = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(doc.window.document.querySelector("p").textContent);
@kt3k
kt3k / std-collections-part1.d.ts
Last active June 30, 2021 12:58
std/collections proposal
type Predicate<T> = (item: T) => boolean
type Selector<T, O = unknown> = (item: T) => O
type Grouping<V> = Record<string, Array<V>>
// 17 items
// ARRAYS (11)
// [Array] Transformations to Array
declare function distinct<T>(collection: Array<T>): Array<T>
declare function distinctBy<T>(collection: Array<T>, selector: Selector<T>): Array<T>
type Predicate<T> = (item: T) => boolean
type Selector<T, O = unknown> = (item: T) => O
type Grouping<V> = Record<string, Array<V>>
// ARRAYS
// [Array] Transformations to Array
declare function mapNotNullish<T, O>(collection: Array<T>, transformer: Selector<T, O>): Array<NonNullable<O>>
declare function takeFirstWhile<T>(collection: Array<T>, predicate: Predicate<T>): Array<T>
declare function takeLastWhile<T>(collection: Array<T>, predicate: Predicate<T>): Array<T>
declare function dropFirstWhile<T>(collection: Array<T>, predicate: Predicate<T>): Array<T>
type Predicate<T> = (item: T) => boolean
type Selector<T, O = unknown> = (item: T) => O
type Grouping<V> = Record<string, Array<V>>
// 6 Array predicates
// 19 Array transformations to Array
// 14 Array transformations to value
// 9 Array transformations to other formats
// 2 Record Predicates
// 9 Record Transformations to Records
import { hmac } from "https://deno.land/x/[email protected]/mod.ts";
addEventListener("fetch", (e) => {
e.respondWith(new Response(hmac("sha256", "key", "msg", "utf8", "base64")));
})