Skip to content

Instantly share code, notes, and snippets.

View guest271314's full-sized avatar
💭
Fix WontFix

guest271314

💭
Fix WontFix
View GitHub Profile
@guest271314
guest271314 / node-ws-server.js
Created April 26, 2025 05:59
WebSocket server for Node.js
// Handles 16384*3 byte length input/output
import { createServer } from "node:net";
import { Duplex } from "node:stream";
// https://github.com/lsert/websocketparser
function wsparser(d) {
const tArr = d;
const group0 = tArr[0];
const FIN = group0 >> 7;
const RSV1 = (group0 & 64) >> 6;
@guest271314
guest271314 / how-to-curate.md
Created April 15, 2025 02:43
"curate", or not!

The workflow for salvaging a question

I still want answers, I do not want to just post my question again.

-24

I still want answers, I do not want to just post my I would just ask the question, again.

And ask the question in venues other than StackExchange. >

@guest271314
guest271314 / fetch-google-chrome-stable.sh
Last active April 6, 2025 01:30
Get, extract Google Chrome Stable from .deb
wget --show-progress --progress=bar https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
# https://askubuntu.com/a/1512766/92739
dpkg --fsys-tarfile google-chrome-stable_current_amd64.deb | tar -xv --strip-components=3 ./opt/google/chrome
rm -rf google-chrome-stable_current_amd64.deb
@guest271314
guest271314 / quickjs-ng-latest-releases.md
Created April 5, 2025 22:51
QuickJS NG Latest Releases
@guest271314
guest271314 / deno-wt-server.js
Last active March 11, 2025 03:07
Deno HTTP/3 WebTransport server
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// https://raw.githubusercontent.com/denoland/deno/dce204af32e4b56681be4f9a034256d979a3ce4b/tests/specs/run/webtransport/main.ts
const cert = Deno.readTextFileSync("./certificate.pem");
const key = Deno.readTextFileSync("./certificate.key");
const certBase64 = cert.split("\n").slice(1, -2).join("");
const certBytes =
await (await fetch(`data:application/octet-stream;base64,${certBase64}`))
.bytes();
const certHash = await crypto.subtle.digest("SHA-256", certBytes);
@guest271314
guest271314 / websocketstream-undici-bundle.js
Created March 8, 2025 03:11
Node.js Undici WebSocketStream bundled with bun build
// bun build undici/lib/web/websocket/stream/websocketstream.js --target=node --packages=external --format=esm --minify-syntax --outfile=websocketstream-undici-bundle.js
import { createRequire } from "node:module";
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __require = /* @__PURE__ */ createRequire(import.meta.url);
// undici/lib/web/fetch/constants.js
var require_constants = __commonJS((exports, module) => {
var corsSafeListedMethods = ["GET", "HEAD", "POST"], corsSafeListedMethodsSet = new Set(corsSafeListedMethods), nullBodyStatus = [101, 204, 205, 304], redirectStatus = [301, 302, 303, 307, 308], redirectStatusSet = new Set(redirectStatus), badPorts = [
"1",
@guest271314
guest271314 / node-wss-server.js
Last active April 3, 2025 21:03
WebSocket server using Node.js builtins and WHATWG Streams
#!/usr/bin/env -S node
// WebSocket server using Node.js builtins and WHATWG Streams
// https://gist.github.com/robertrypula/b813ffe23a9489bae1b677f1608676c8
// https://gist.github.com/guest271314/735377527389f1de6145f0ac71ca1e86
import { readFileSync } from "node:fs";
import { createServer } from "node:tls";
import { Duplex } from "node:stream";
const debugBuffer = (bufferName, buffer) => {
const length = buffer ? buffer.length : "---";
@guest271314
guest271314 / node-http2-server.js
Last active March 11, 2025 02:24
HTTP/2 server using Node.js builtins and WHATWG Streams
import { createSecureServer } from "node:http2";
import { createWriteStream, readFileSync } from "node:fs";
import { open, stat } from "node:fs/promises";
import { Readable, Writable } from "node:stream";
import process from "node:process";
const stdout = Writable.toWeb(process.stdout);
const encoder = new TextEncoder();
const headers = {
"Cache-Control": "no-cache",
"Content-Type": "text/plain; charset=UTF-8",
@guest271314
guest271314 / file-system-access-write.md
Created February 15, 2025 05:32
Write files with File System Access API without creating orphan .crswap files

The reason for using

await readable.pipeTo(writable)

is the .crswap file is automatically removed when the Promise fulfills.

Here's one way to write arbitrary volumes of data to the same file, without generating a bunch of orphan .crswap files.

The gist is

@guest271314
guest271314 / assemblyscript-deno-bun-node-js.md
Last active February 28, 2025 03:26
Executing AssemblyScript directly, and compiling to JavaScript with tsc, Deno, and Bun (and executing WASM directly with bun)

Executing AssemblyScript directly, and compiling to JavaScript with tsc, Deno, and Bun (and executing WASM directly with bun)

Installing

bun install typescript@next assemblyscript @types/node
bun add v1.2.1-canary.15 (5633ec43)

installed [email protected] with binaries:
 - tsc