Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / 00readme.md
Last active August 14, 2024 22:40
[helia] serving contents from browser to browser with nodejs helia as a bootstrap target

0. Setup

Clone this repo:

$ git clone https://gist.github.com/23ad8d6e3a1509335253ff074fcd3cb6.git helia-b2b-sharing
$ cd helia-b2b-sharing/

Generate npm-browser.js npm package bundle:

@bellbind
bellbind / 00readme.md
Last active September 4, 2023 11:46
[helia] direct connect case of 2 helia nodes between browser and nodejs

0. Setup

Clone this repo:

$ git clone https://gist.github.com/28021e2ff6c99251746a1a46d1a62f68.git helia-b2l-direct
$ cd helia-b2l-buggy/

Generate npm-browser.js npm package bundle:

This file has been truncated, but you can view the full file.
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
@bellbind
bellbind / 00readme.md
Last active August 22, 2024 14:55
[helia] halt access cid served on browser from nodejs

0. Setup

Clone this repo:

$ git clone https://gist.github.com/5565c22255ae87a3c8e9948b467ee894.git helia-b2l-buggy
$ cd helia-b2l-buggy/

Generate npm-browser.js npm package bundle:

@bellbind
bellbind / dep-bootstrap.js
Last active August 8, 2024 19:20
[helia] connect browser to server on localhost with archived webRTCStar
export * from "@libp2p/bootstrap";
@bellbind
bellbind / multi-nodes-cdn.html
Last active June 18, 2023 13:46
[helia][browser] Simple example of using Helia IPFS node on browser
<!doctype html>
<html>
<head>
<link rel="icon" href="data:image/x-icon," />
<script type="module" src="./multi-nodes-cdn.js"></script>
</head>
<body>
Open JavaScript console to check running logs
</body>
</html>
@bellbind
bellbind / helia-basics.mjs
Created May 30, 2023 13:43
[nodejs][IPFS] helia basic example
// npm i helia @helia/unixfs
import * as helia from "helia";
import {unixfs} from "@helia/unixfs"; // unixfs support for large bytes
import {CID} from "multiformats/cid"; // helia.pins not support string CID
const node1 = await helia.createHelia(); // tcp network, stored on memory (not use files)
const node2 = await helia.createHelia();
const node1fs = unixfs(node1);
const node2fs = unixfs(node2);
@bellbind
bellbind / index.html
Last active May 31, 2023 05:54
[JavaScript][browser] Epicycles of a single-stroke by DFT
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Epicycles of a single-stroke by DFT</title>
<script type="module" src="./main.js"></script>
</head>
<body style="display: flex; flex-direction: column; align-items: center; justify-content: center;">
<h1>Draw a line</h1>
<canvas id="canvas" style="border: solid; width: 75svmin; height: 75svmin; "></canvas>
@bellbind
bellbind / closable-stream.js
Last active December 11, 2022 14:46
[js-ipfs/libp2p] dial to read events from infinite sending from handler, then close read
// 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));
@bellbind
bellbind / cache-method.js
Last active November 19, 2022 14:46
[Web Cache API][browser][deno] Web Cache API basic examples
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