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 / piper-web-speech-api.md
Created July 14, 2024 19:48
Adding piper module and voices to Speech Dispatcher for Web Speech API

An option for using piper and onnx voices in the browser is through Speech Dispatcher, which Chromium-based browsers (Chrome, Brave, Opera, Edge) and Firefox use for Web Speech API.

I have added the piper module to Speech Dispatcher following the instructions here module request: piper #866.

Tested on Chromium Version 128.0.6586.0 (Developer Build) (64-bit) and Firefox Nightly 130.0a1. Chromium works. Firefox does not load the piper voices.

In pertinent part.

Download the piper executable from releases, extract the contents and save to ~/.local/opt/piper.

// deno-fmt-ignore-file
// deno-lint-ignore-file
// This code was bundled using `deno bundle` and it's not recommended to edit it manually
var createPiperPhonemize = (()=>{
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
return function(moduleArg = {}) {
var Module = moduleArg;
var readyPromiseResolve, readyPromiseReject;
@guest271314
guest271314 / uint8_uint32.md
Last active July 6, 2024 01:52
Uint32Array to Uint8Array, Uint8Array to Uint32Array

In some environments and contexts the processing model is based on UTF-8. In those same environments the processing model can be strings and not ArrayBuffer or TypedArray.

When the data includes Uint32Array it could become necessary to convert Uint32Array to Uint8Array, Uint32Array to Uint8Array.

Here are some approaches I have used to convert between Uint32Array (4 bytes per element) and Uint8Array (1 byte per element).

See 23.2 TypedArray Objects.

Encode the length of 1 MB of JSON into a Uint32Array

@guest271314
guest271314 / read_stdin_to_a_different_process_with_quickjs.md
Last active July 1, 2024 01:29
How to read stardard input to a different process using QuickJS

Occasionally we might be experimenting inside a JavaScript or other engine, runtime, interpreter, or context where reading the standard input stream to the current process is either unintentionally or deliberately restricted.

The V8 JavaScript/WebAssembly engine has a developer shell called d8. d8 has a readline() function that in general expects input from a TTY. Further, the expectation is generally that the input will be evaluated as a script. See Using d8. v8 is about 37.6 MB.

What this means is that if d8 is launched by a different process reading stardard input to d8 is not straightforward where the input is not necessarily UTF-8.

@guest271314
guest271314 / file-to-arraybuffer.md
Last active June 11, 2024 00:55
File to ArrayBuffer with attributes, ArrayBuffer to File with attributes

File interface

Blob and File (which inherits from Blob) have an arrayBuffer() method, e.g.,

const file = new File(
  [
    new Float32Array(Array.from({
      length: 1000,
@guest271314
guest271314 / parse-chromium-default-file-system.js
Created June 2, 2024 22:40
Parse leveldb in Chromium configuration folder containing Origin Private File System written by navigator.storage.getDirectory()
async function parseChromeDefaultFileSystem(path) {
try {
const set = new Set([
32, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 64, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 113, 114, 115, 116, 117, 118,
@guest271314
guest271314 / 000003.log
Created June 2, 2024 15:18
Default/File System/.../Paths/000003.log
rM0Ux/LAST_FILE_ID0LAST_INTEGER-1FCHILD_OF:0:persistent-serviceworker1140persistent-serviceworkerUx/LAST_FILE_ID100Ux/TLAST_INTEGER0ZlCHILD_OF:1:README.md224000/00000000README.mdLAST_FILE_ID2KMD140persistent-serviceworkerUx/LAST_INTEGER1fVwCHILD_OF:1:README.md.crswap338400/00000001README.md.crswapLAST_FILE_ID3D140persistent-serviceworkerUx/dCHILD_OF:1:README.md.crswap324000/00000001README.mdInD140persistent-serviceworkerUx/D140persistent-serviceworkerUx/UeKCHILD_OF:1:chromium_extension_web_accessible_resources_iframe_message_event44X@chromium_extension_web_accessible_resources_iframe_message_eventUx/LAST_FILE_ID4TD140persistent-serviceworkerUx/HLAST_INTEGER2.tCHILD_OF:4:background.js558400/00000002background.jsLAST_FILE_ID5:l4X@chromium_extension_web_accessible_resources_iframe_message_eventUx/QL LAST_INTEGER3NwCHILD_OF:4:background.js.crswap66800/00000003background.js.crswapLAST_FILE_ID6l4X@chromium_extension_web_accessible_resources_iframe_message_eventUx/blCHILD_OF:4:background.js.crswap658400/00000003back
@guest271314
guest271314 / createReadWriteDirectoriesInBrowser.js
Last active June 5, 2024 02:50
How to create, recreate, and transfer directories to peers in the browser. Part 1: Creating directories in the local filesystem using HTML
// *Mostly* specfication conformant
// <input type="file" webkitdirectory> does not upload empty directories
// drop event with DataTransfer.item.getAsFileSystemDirectory() *does*
// list empty folders.
// W3C File API does not have a way to represent an empty directory.
// We use a File with type set to "inode/directory".
try {
// HTMLInputElement.webkitdirectory
// https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory
var html = `<form
@guest271314
guest271314 / sha1-uint8array.min.js
Last active May 21, 2024 19:58 — forked from robertrypula/web-socket-server.js
WebSocket - binary broadcast example (JavaScript runtime agnostic implementation without any dependency)
// 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 / upFetch.js
Created April 21, 2024 18:11
L-Blondy up-fetch bundled with bun buil
// response-error.ts
class ResponseError extends Error {
name;
response;
options;
data;
constructor(res, data, options) {
super(`Request failed with status ${res.status}`);
this.data = data;
this.name = "ResponseError";