Skip to content

Instantly share code, notes, and snippets.

View cometkim's full-sized avatar

Hyeseong Kim cometkim

View GitHub Profile
@cometkim
cometkim / early-hints-test.mjs
Last active November 26, 2024 17:02
Do your infra hops respect HTTP 103 Early Hints?
import * as http from 'node:http';
import { Readable } from 'node:stream';
import { setInterval } from 'node:timers/promises';
async function* chunksWhile(ms) {
let count = 0;
for await (const startTime of setInterval(1000, Date.now())) {
yield `<div>Looking for your cat... (n=${++count})</div>`;
if (Date.now() - startTime > ms) {
return;
@cometkim
cometkim / README.md
Last active November 21, 2024 03:20
There are too many LRU implementations in JS...

JavaScript LRU library benchmark

There are too many LRU(Least Recently Used) implementations in JS.

I recommend to use [flru] which is the smallest one and fast enough. Unless you need more rich functionality.

However, it's performance is vary depend on the host environment. For example, flru loses on Bun.

If you need micro-optimization on it, measure it yourself in your environment.

@cometkim
cometkim / cfs-streaming-graphql.md
Last active July 9, 2024 03:47
Call for study: Streaming runtime for GraphQL

Call for study: Streaming runtime for GraphQL

Topics

  1. Design format as a compact binary representation of the GraphQL trusted documents
    • The decoder should interface as a ReadableStream
    • It aligns the execution order of resolvers ahead-of-time
  2. Pipe-able execute which compatible with exsting GraphQL resolvers
    • It should support e.g unpack(docs).pipe(executeStream)
  3. Implement stream acceptance from the client
@cometkim
cometkim / dns-healthcheck.sh
Last active May 5, 2024 04:05
Healthcheck an anycast DNS
#!/bin/bash
function healthcheck() {
local domain=$1
local total_tests=$2
local total_failed_count=0
local ip_list=()
for ((i = 0; i < total_tests; i++)); do
@cometkim
cometkim / curl-bench.mjs
Last active April 19, 2024 14:29
HTTP protocol version test via cURL (not a good way)
import { parseArgs } from 'node:util';
import { spawn } from 'node:child_process';
import { setTimeout } from 'node:timers/promises';
import prettyBytes from 'pretty-bytes';
import prettyMilliseconds from 'pretty-ms';
let { values, positionals } = parseArgs({
args: process.argv.slice(2),
allowPositionals: true,
@cometkim
cometkim / report.mjs
Created April 11, 2024 07:04
Analytics GitHub billing by SKU and repository name
#!/usr/bin/env node
import * as fs from 'node:fs';
import csvParser from 'csv-parser';
const [csvFile, sku] = process.argv.slice(2);
if (!fs.existsSync(csvFile) || !sku) {
console.error('Usage: ./report.mjs [CSV file] [SKU]');
process.exit(1);
}
@cometkim
cometkim / progress.ts
Created March 28, 2024 06:53
Fake progress number, use the number with spring animation
const nextProgress = (progress: number) => {
switch (true) {
case progress < 40: {
return progress + 40 + Math.random() * 10;
}
case progress < 60: {
return progress + 8 + Math.random() * 2;
}
case progress < 80: {
return progress + 3 + Math.random() * 2;
@cometkim
cometkim / node-pm-globals.md
Last active July 30, 2024 13:59
How package managers dealing with binaries from transitive dependencies
$pm add vite

# should be success
$pm run vite --version

# shoud be fail
$pm run esbuild --version
@cometkim
cometkim / convert.mjs
Last active July 21, 2023 12:36
Convert Wikipedia page-articles data (XML) into a text dataset (NDJSON)
// Convert Wikipedia page articles dump (XML) into a stream of JSON
// { id: 0, "title": "...", "text": "..." }
// The "text" field format will also be converted into plain text
import * as path from 'node:path';
import * as fs from 'node:fs';
import XMLParser from 'node-xml-stream';
import ndjson from 'ndjson';
import instaview from 'instaview';
import htmlEntities from 'html-entities';
@cometkim
cometkim / index.html
Created May 24, 2023 06:18
Is growable SAB GC-able?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>SharedArrayBuffer GC test</title>
</head>
<body>
<div id="root"></div>
<script type="module">