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
// 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
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
# 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
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
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
// Chapter 6 | |
type NonEmptyArray<T> = [T, ...T[]]; |
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
// Suppose we have following code: | |
class APIError extends Error {} | |
function throwAPIError(message: string) { | |
// complicated logic... | |
throw new APIError(message); | |
} |
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://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern | |
# maybe settings are like the following: | |
- OriginSettings: | |
- OriginDomain: MY-EXAMPLE-BUCKET.s3.ap-northeast-1.amazonaws.com | |
OriginPath: /static | |
- OriginDomain: example-load-balancer-1234567890.ap-northeast-1.alb.amazonaws.com | |
OriginPath: * |
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
mysql> SELECT * FROM information_schema.SCHEMATA WHERE schema_name = "test"; | |
+--------------+-------------+----------------------------+------------------------+----------+ | |
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | | |
+--------------+-------------+----------------------------+------------------------+----------+ | |
| def | test | latin1 | latin1_swedish_ci | NULL | | |
+--------------+-------------+----------------------------+------------------------+----------+ | |
1 row in set (0.00 sec) | |
-- https://stackoverflow.com/a/6115705 | |
mysql> ALTER DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |