View 01-object-readable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i web-streams-polyfill | |
const streams = require("web-streams-polyfill"); | |
const {ReadableStream, WritableStream, TransformStream} = streams; | |
// (default) object stream | |
const rs1 = new ReadableStream({ | |
async start(controller) { | |
// called by constructor | |
console.log("[start]"); | |
controller.enqueue("a"); |
View main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node.js worker_threads module example: main thread side | |
//$ node --exprimental-worker main.js | |
const path = require("path"); | |
const {Worker, MessageChannel} = require("worker_threads"); | |
//NOTE: worker code accepts only absolute file path | |
// not URLs includes "data:" URL | |
const w = new Worker(path.resolve(__dirname, "./worker.js")); | |
(async () => { | |
console.log(await send(w, "Hello")); |
View index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="./tree.css" /> | |
</head> | |
<body> | |
<label class="css-tree"><input type="checkbox" checked="checked">Tree (root)</label> | |
<ul> | |
<li> | |
<label class="css-tree"><input type="checkbox">Tree 1</label> |
View index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Origin Private File System Viewer</title> | |
<script type="module"> | |
// see https://fs.spec.whatwg.org/ | |
const showDir = (dir, check, ul) => { | |
check.addEventListener("change", ev => { | |
if (check.checked) (async () => { |
View cpuinfo.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// intel CPUID opcode | |
// see: https://en.wikipedia.org/wiki/CPUID | |
// clang -Wall -Wextra -std=c11 cpuinfo.c -o cpuinfo | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <cpuid.h> //macro __cpuid(eaxin, eaxout, ebx, ecx, edx) | |
int main() { | |
{ |
View fragment.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 300 es | |
precision highp float; | |
//invariant gl_FragCoord; | |
uniform Screen { | |
vec2 wh; | |
} screen; | |
uniform Timer { | |
int count; |
View main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// [run the app] | |
// $ npm install electron | |
// $ ./node_modules/.bin/electron . | |
const {app, nativeImage, Tray, Menu, BrowserWindow} = require("electron"); | |
let top = {}; // prevent gc to keep windows |
View movconcat-fps60.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S deno run --allow-read --allow-run | |
// usage: deno run --allow-read --allow-run movconcat.js /Volumes/UNTITLED/Normal/F/ result.mp4 | |
import * as path from "https://deno.land/std/path/mod.ts"; | |
import * as flags from "https://deno.land/std/flags/mod.ts"; | |
const parsed = flags.parse(Deno.args); | |
const sources = parsed._.at(-2); | |
const output = parsed._.at(-1); | |
const inputs = []; | |
for await (const {name} of Deno.readDir(sources)) inputs.push(name); |
View async-timeout-interval.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const timeout = (msec, ...args) => new Promise(f => setTimeout(f, msec, args)); | |
export const interval = (msec, ...args) => ({ | |
[Symbol.asyncIterator]() { | |
const rs = []; | |
const id = setInterval(() => rs.shift()?.call(undefined, {value: args, done: false}), msec); | |
return { | |
next() { | |
return new Promise(f => rs.push(f)); | |
}, | |
throw() { |
View main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node.js worker_threads module example with for-await loop: main thread side | |
//$ node --exprimental-worker main.js | |
const path = require("path"); | |
const {Worker, MessageChannel} = require("worker_threads"); | |
// async queue as "asyncIterator" in ES2018 | |
class Queue { | |
constructor() { | |
this.polls = []; | |
this.gets = []; |