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-wss-server.js
Last active May 21, 2025 18:29
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 typescript@5.8.0-dev.20250129 with binaries:
 - tsc
@guest271314
guest271314 / bench.js
Last active January 20, 2025 12:39
TypeScript .ts file execution benchmarks for Deno, Bun, Node.js
Deno.bench("Deno, Bun, Node.js TypeScript Benchmarks", async (b) => {
// Open a file that we will act upon.
// using file = await Deno.open("a_big_data_file.txt");
// Tell the benchmarking tool that this is the only section you want
// to measure.
b.start();
// Now let's measure how long it takes to read all of the data from the file.
// await new Response(file.readable).arrayBuffer();
@guest271314
guest271314 / no-monopoly.md
Last active January 12, 2025 00:06
How to set a user-defined default search engine (and custom new tab page) in Chromium browser

In Chromium or Chrome browsers navigate to chrome://settings/searchEngines. The page looks something like this. Here I'm showing what Chromium Version 134.0.6949.0 (Developer Build) (64-bit). On Linux.

Screenshot_2025-01-11_14-45-55

Notice that ".(Default)".

@guest271314
guest271314 / shermes-stdin.md
Created January 7, 2025 08:24
Reading stdin in Static Hermes
@guest271314
guest271314 / high-skill-cheap-labor.md
Last active January 4, 2025 15:25
"Highly skilled" programmers for "high-tech" or capitalism working as expected?

"Highly skilled" programmers for "high-tech" or capitalism working as expected?

I'm currently domiciled in the U.S. I don't watch or listen to "the news". I don't support Democrats or Republicans.

The other day somebody told me there's an H-1B visa schism within the Republican Party.

I said, alright, show me what "the left" says, and show me

@guest271314
guest271314 / shermes-wasi.md
Last active May 1, 2026 06:06
Compiling JavaScript to WASM with WASI support using Static Hermes
@guest271314
guest271314 / fsopen-wasm-esbuild.js
Created December 29, 2024 17:58
CommonJS to ECMAScript Module - deno produces incorrect result unless parsed as CommonJS
var Module = typeof Module != "undefined" ? Module : {};
var ENVIRONMENT_IS_WEB = typeof window == "object";
var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
var ENVIRONMENT_IS_NODE = typeof process == "object" &&
typeof process.versions == "object" &&
typeof process.versions.node == "string" && process.type != "renderer";
if (ENVIRONMENT_IS_NODE) {}
var moduleOverrides = Object.assign({}, Module);
var arguments_ = [];
var thisProgram = "./this.program";