Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / example-relay-http2p.mjs
Created November 17, 2022 13:51
[ipfs][nodejs] HTTP like messaging for PeerID via libp2p in IPFS node
#!/usr/bin/env node
import * as fs from "node:fs";
// IPFS
import * as IPFS from "ipfs-core";
// WebRTCStar
import wrtc from "@koush/wrtc";
import {sigServer} from "@libp2p/webrtc-star-signalling-server";
import {webRTCStar} from "@libp2p/webrtc-star";
// pubsub peerDiscovery
//import {floodsub} from "@libp2p/floodsub";
@bellbind
bellbind / index.html
Last active October 11, 2022 00:28
[CSS]Tree view with :has and :not selector
<!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>
@bellbind
bellbind / index.html
Last active October 5, 2022 22:29
[HTML][JavaScript] Origin Private File Systrem Viewer
<!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 () => {
@bellbind
bellbind / async-timeout-interval.js
Created September 5, 2022 02:16
[ecmascript] timeout promise and inverval async iterator
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() {
@bellbind
bellbind / clock.html
Last active August 22, 2023 12:30
[SVG][JavaScript] SVG Analog Clock
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="user-scalable=no" />
<link rel="icon" href="././clock.svg" />
<link rel="manifest" href="./manifest.json" />
<title>SVG Clock</title>
<style>
html {height: 100%;}
@bellbind
bellbind / index.html
Created July 29, 2022 14:13
[JavaScript][HTML] run es modules in iframe context
<!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 June 8, 2022 13:07
[css] shadow button example
<!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 15:28
[browser][deno] Example registration page and its server of API: navigator.registerProtocolHandler()
#!/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-fps60.js
Last active October 25, 2023 08:49
[deno]10M bps video files concation with x4 speed and x2 volume with ffmpeg command
#!/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);
@bellbind
bellbind / concat.mjs
Last active May 21, 2022 09:23
[nodejs][macos] 10M bps video files concation with x4 speed and x2 volume with ffmpeg command
#!/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);