View closable-stream.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
// wrapping libp2p stream (mplex/stream) | |
// - stream.source: AsyncIterable<Uint8Array> | |
// - stream.sink: (Iterable<Uint8Array> | AsyncIterable<Uint8Array>) => Promise<undefined> | |
// - stream.close, stream.closeRead, stream.closeWrite, stream.abort, stream.reset | |
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)); |
View cache-method.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
await caches.delete("tmp"); | |
const cache = await caches.open("tmp"); | |
const req1 = new Request("http://example.com/"); | |
const req2 = new Request("http://example.com/", {method: "head"}); | |
const req3 = new Request("http://example.com/", {method: "post"}); | |
const res1 = new Response("hello en-US", {headers: {"Content-Type": "text/plain;charset=utf-8"}}); | |
const res2 = new Response("", {headers: {}}); | |
await cache.put(req1, res1); // cache "http://example.com/ with res1 |
View example-relay-http2p.mjs
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 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"; |
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 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 clock.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> | |
<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%;} |
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> | |
<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); |
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> | |
<meta charset="utf-8"> | |
<style> | |
/* shadow button */ | |
button { | |
border-style: none; | |
border-radius: 0.5em; | |
color: inherit; |
View server.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-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 |
NewerOlder