Skip to content

Instantly share code, notes, and snippets.

@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 / spiral.html
Created Aug 15, 2014
[javascript][threejs] sphere spiral
View spiral.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/Trac
kballControls.js"
></script>
<script src="spiral.js"></script>
@bellbind
bellbind / index.html
Last active May 9, 2022
[WebGPU] Game of Life as Compute+Render example for Chrome-103
View index.html
<!doctype html>
<html>
<head>
<!-- IMPORTANT: The current Chrome requires some origin-trial token in <meta>.
To register origins at the last "WebGPU REGISTER" in https://developer.chrome.com/origintrials/
This token is for a Web Origin "https://gist.githack.com" (maybe expired at Mar 31, 2022)
It can register localhost origin as "http://localhost:8000"
-->
<meta http-equiv="origin-trial"
content="Akv07qcAop5MFaZYxJtHHjUuM8eV3GpbHkTeuhZo/4wsNjYnQ7GSGJyo7hRVZvpvyjYwilbJ8KbFVchI4O1DpA0AAABQeyJvcmlnaW4iOiJodHRwczovL2dpc3QuZ2l0aGFjay5jb206NDQzIiwiZmVhdHVyZSI6IldlYkdQVSIsImV4cGlyeSI6MTY1MjgzMTk5OX0=" />
@bellbind
bellbind / compute-example.js
Last active May 9, 2022
[WebGPU] Draw a square with WebGPU for chrome-103
View compute-example.js
// Compute example for WebGPU API for Chrome-103: https://www.w3.org/TR/webgpu/
// [Usage] Paste whole codes into Web Comsole of the WebGPU demo page, then output 1024 Float32Array of squares
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
// WGSL shaders: https://www.w3.org/TR/WGSL/
const workgroupSize = device.limits?.maxComputeInvocationsPerWorkgroup ?? 64;
const computeWgsl = `
struct IO {
values: array<i32>,
@bellbind
bellbind / index.html
Last active May 7, 2022
[WebGPU] Image texture example for WebGPU API for Chrome-100
View index.html
<!doctype html>
<html>
<head>
<!-- IMPORTANT: The current Chrome requires some origin-trial token in <meta>.
To register origins at the last "WebGPU REGISTER" in https://developer.chrome.com/origintrials/
This token is for a Web Origin "http://localhost:8000" (maybe expired at Mar 31, 2022)
-->
<meta http-equiv="origin-trial"
content="AkIL+/THBoi1QEsWbX5SOuMpL6+KGAXKrZE5Bz6yHTuijzvKz2MznuLqE+MH4YSqRi/v1fDK/6JyFzgibTTeNAsAAABJeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwMDAiLCJmZWF0dXJlIjoiV2ViR1BVIiwiZXhwaXJ5IjoxNjUyODMxOTk5fQ==" />
<meta http-equiv="origin-trial"
@bellbind
bellbind / loader.html
Last active May 3, 2022
[threejs][html5]STL File Viewer with HTML5 File API
View loader.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>STL File Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
<script src="loader.js"></script>
@bellbind
bellbind / base58.js
Last active Apr 27, 2022
[ECMAScript][BigInt] base58 encoder/decoder algorithm on JavaScript and base58check on node.js
View base58.js
// Bitcoin Base58 encoder/decoder algorithm
const btcTable = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
console.assert(btcTable.length === 58);
// Base58 decoder/encoder for BigInt
function b58ToBi(chars, table = btcTable) {
const carry = BigInt(table.length);
let total = 0n, base = 1n;
for (let i = chars.length - 1; i >= 0; i--) {
const n = table.indexOf(chars[i]);
@bellbind
bellbind / zip.js
Last active Apr 26, 2022
[es6] zip generator for ES6
View zip.js
"use strict";
const zip = function* () {
const its = Array.from(arguments, e => e[Symbol.iterator]());
while (true) {
const es = its.map(it => it.next());
if (es.some(e => e.done)) return;
yield es.map(e => e.value);
}
};
@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 / 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;"