Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / index.html
Created Jul 29, 2022
[JavaScript][HTML] run es modules in iframe context
View index.html
<!doctype html>
<html>
<head>
<script type="module">
document.querySelector("#run").addEventListener("click", async ev => {
const modUrl = new URL("./module.js", location.href).href;
//console.log(modUrl);
const iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.append(iframe);
@bellbind
bellbind / index.html
Last active Jun 8, 2022
[css] shadow button example
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
/* shadow button */
button {
border-style: none;
border-radius: 0.5em;
color: inherit;
@bellbind
bellbind / server.js
Last active May 27, 2022
[browser][deno] Example registration page and its server of API: navigator.registerProtocolHandler()
View server.js
#!/usr/bin/env -S deno run --allow-net
// Example registration page and its server of API: navigator.registerProtocolHandler()
import {serve} from "https://deno.land/std/http/server.ts";
// A pattern of protocol scheme name is limited with prefix "web+" as web+lowerletters ,
// or whitelisted names in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler
const protocol = "web+local";
// navigator.registerProtocolHandler() should be called in user inputs (e.g. button click)
// - forwarded url must be same origin of the location.href
@bellbind
bellbind / movconcat.js
Last active May 21, 2022
[deno]10M bps video files concation with x4 speed and x2 volume with ffmpeg command
View movconcat.js
#!/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";
const sources = Deno.args.at(-2);
const output = Deno.args.at(-1);
const inputs = [];
for await (const {name} of Deno.readDir(sources)) inputs.push(name);
inputs.sort();
const list = inputs.map(f => `file ${path.toFileUrl(path.join(sources, f))}\n`).join(``);
@bellbind
bellbind / concat.mjs
Last active May 21, 2022
[nodejs][macos] 10M bps video files concation with x4 speed and x2 volume with ffmpeg command
View concat.mjs
#!/usr/bin/env node
// usage: node concat.mjs /Volumes/UNTITLED/Normal/F/ result.mp4
import * as cp from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import * as process from "node:process";
import * as stream from "node:stream";
import * as url from "node:url";
//console.log(process.argv);
@bellbind
bellbind / example.js
Created Apr 26, 2022
[javascript] geodesic direct/inverse by Vincenty formulae
View example.js
import {inverse, direct} from "./vincenty.js";
{
// example from https://vldb.gsi.go.jp/sokuchi/surveycalc/surveycalc/bl2stf.html
const latlon1 = [36.10377477777778, 140.08785502777778], latlon2 = [35.65502847222223, 139.74475044444443];
console.log(inverse(latlon1, latlon2));
const s =58643.80450350114, a1to2 = 211.99252761069826;
console.log(direct(latlon1, a1to2, s));
console.log(latlon2);
}
@bellbind
bellbind / index.html
Created Apr 22, 2022
[browser] custmizing input range sliders
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<style>
.container {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
@bellbind
bellbind / example-ipfs.html
Last active Apr 23, 2022
[leaflet] Web Component for display GPX
View example-ipfs.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="data:img/x-icon," />
<script type="module" src="./leaflet-gpx.js"></script>
</head>
<body style="height: 100vh; display: flex; align-items: center; justify-content: center;">
<leaflet-gpx
style="width: 80vmin; height: 80vmin;"
@bellbind
bellbind / byob-transform.js
Last active Apr 10, 2022
[browser] Display MNIST images with Web API DecompressionStream
View byob-transform.js
// BYOB emulation as TransformStream for `u8readable.pipeThrough(new BYOBTransform())`
const newQueue = () => {
const [gets, polls] = [[], []];
const next = () => new Promise(get => polls.length > 0 ? polls.shift()(get) : gets.push(get));
const poll = () => new Promise(poll => gets.length > 0 ? poll(gets.shift()) : polls.push(poll));
const push = async value => (await poll())({value, done: false});
const close = async () => (await poll())({done: true});
return {next, push, close, [Symbol.asyncIterator]() {return this}};
};
@bellbind
bellbind / example.js
Last active Mar 18, 2022
[javascript] math functions for regular matrix as flat array
View example.js
import {det, adjugate as adj, inv, mulmm} from "./mat.js";
{
const a = [1, 2, 3, 4];
console.log(det(2, a));
console.log(adj(2, a));
console.log(inv(2, a));
console.log(mulmm(2, inv(2, a), a));
const b = [0, 1, 2, 7, 8, 3, 6, 5, 4];