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 / sha1-uint8array.min.js
Last active May 1, 2025 06:30
JavaScript runtime agnostic WebSocket server
// deno bundle https://raw.githubusercontent.com/kawanet/sha1-uint8array/main/lib/sha1-uint8array.ts sha1-uint8array-bundle.js
// bun build --minify sha1-uint8array-bundle.js --outfile=sha1-uint8array.min.js
var z=function(t){if(t&&!w[t]&&!w[t.toLowerCase()])throw new Error("Digest method not supported");return new E},p=function(t,e,i,s){if(t===0)return e&i|~e&s;if(t===2)return e&i|e&s|i&s;return e^i^s},B=function(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254},y=[1518500249|0,1859775393|0,2400959708|0,3395469782|0],w={sha1:1};class E{A=1732584193|0;B=4023233417|0;C=2562383102|0;D=271733878|0;E=3285377520|0;_byte;_word;_size=0;_sp=0;constructor(){if(!u||_>=8000)u=new ArrayBuffer(8000),_=0;this._byte=new Uint8Array(u,_,80),this._word=new Int32Array(u,_,20),_+=80}update(t){if(typeof t==="string")return this._utf8(t);if(t==null)throw new TypeError("Invalid type: "+typeof t);const{byteOffset:e,byteLength:i}=t;let s=i/64|0,r=0;if(s&&!(e&3)&&!(this._size%64)){const h=new Int32Array(t.buffer,e,s*1
@guest271314
guest271314 / websocket-server.js
Created April 28, 2025 04:15 — forked from d0ruk/websocket-server.js
websocket server
/**
* Copyright (c) 2007-2013, Kaazing Corporation. All rights reserved.
*/
// The Definitive Guide to HTML5 WebSocket
// Example WebSocket server
// See The WebSocket Protocol for the official specification
// http://tools.ietf.org/html/rfc6455
@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",