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
preact 4.2kB (minified + gzipped) | |
@preact/compat 0.2kB (minified + gzipped) | |
react 2.5kB (minified + gzipped) | |
react-dom 42.0kB (minified + gzipped) | |
vite (react-ts): built index-xxx.js 143.55kB (gzip: 46.17kB) | |
vite (react-ts w/ @preact/compat) built index-xxx.js 24.24kB (gzip: 9.36kB) | |
vite (preact-ts): built index-xxx.js 13.53kB (gzip: 5.48kB) |
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
SELECT users.*, posts.* | |
FROM users | |
INNER JOIN posts ON posts.user_id = users.id; |
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
# see: https://nodejs.org/api/crypto.html#cryptoscryptpassword-salt-keylen-options-callback | |
import { scrypt as _scrypt } from "node:crypto"; | |
import { promisify } from "node:util"; | |
const scrypt = promisify(_scrypt); | |
// e.g.) crypto.ramdomUUID().replace(/-/g, "") | |
const SALT = "random chars at least 16 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
type TaskFn<T> = () => Promise<T>; | |
// see: https://maximorlov.com/parallel-tasks-with-pure-javascript/ | |
async function limit<T>(tasks: TaskFn<T>[], concurrency: number) { | |
const results: (T | Error)[] = []; | |
async function run(iterator: IterableIterator<[number, TaskFn<T>]>) { | |
for (const [index, task] of iterator) { | |
try { | |
results[index] = await task(); |
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
// https://florian.github.io/xor-trick/ | |
function swap(a: number, b: number): [number, number] { | |
a ^= b; | |
b ^= a; | |
a ^= b; | |
return [a, b]; | |
} | |
/** |
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
import "colors"; | |
import * as Diff from "diff"; | |
const one = "こんにちは、きょうはいい天気ですね。"; | |
const other = "こんばんは。今日は良い天気だね。"; | |
const diff = Diff.diffChars(one, other); | |
function log(word) { |
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
SELECT * | |
FROM orgs | |
INNER JOIN users | |
ON users.org_id = orgs.id | |
AND users.active = true | |
INNER JOIN users_tasks | |
ON users_tasks.user_id = users.id | |
AND users_tasks.status = "active" | |
INNER JOIN tasks | |
ON tasks.id = users_tasks.task_id |
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
class User { | |
name: string; | |
age: number; | |
#createdAt: Date; | |
constructor(name: string, age: number) { | |
this.name = name; | |
this.age = age; |
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 Post { | |
title: string; | |
} | |
interface FetchPostsArgs { | |
skip: number; | |
limit: number; | |
} | |
const BATCH_SIZE = 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
// src/index.ts | |
async function main() { | |
const tmpFile = new TmpFile(); | |
const data = { name: "foo", age: 30 }; | |
await tmpFile.write("users/1.json", JSON.stringify(data)); | |
console.log(await tmpFile.read("users/1.json")); |