Skip to content

Instantly share code, notes, and snippets.

@HDegroote
HDegroote / tensorflowUploadServer.js
Last active September 10, 2021 09:51
Test server for uploading tensorflow models
const express = require('express')
var formidable = require('formidable')
util = require('util');
const app = express()
const port = 3000
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`)
@HDegroote
HDegroote / hyperbee-encoding-bug.js
Last active July 20, 2022 18:52
Illustration of a hyperbee-encoding bug in the browser
// See https://github.com/hypercore-protocol/hyperbee/issues/59
// The server code creates a dht-relay and shares a hyperbee
// The client code loads a hyperbee through the relay
// The client code can be executed both from the browser and form Node
// SERVER (see below for CLIENT code)
const DHT = require("@hyperswarm/dht");
@HDegroote
HDegroote / replicate-hyperbees.js
Last active November 20, 2022 20:54
Replicating hyperbees over hyperswarm
// Uses hypercore-next and hyperswarm V4
// Server
const Hyperswarm = require('hyperswarm')
const Hypercore = require("hypercore")
const Hyperbee = require("hyperbee")
const ram = require("random-access-memory")
async function runServer(){
@HDegroote
HDegroote / replicate-corestores.js
Created July 25, 2022 18:24
Replicate corestores example
// Tested on Hyperswarm V4, corestore V6, Hypercore V10
// Server
const Hyperswarm = require('hyperswarm')
const Corestore = require("corestore")
const ram = require("random-access-memory")
async function runServer(){
const corestore = new Corestore(ram)
@HDegroote
HDegroote / unique-hypercore-creation.js
Created August 30, 2022 07:48
Illustration of 2 approaches for a createUniqueCore function
const Corestore = require("corestore")
const ram = require("random-access-memory")
async function ensureIsNonExistingCoreName (name, corestore) {
try {
await (corestore.get({ name, createIfMissing: false })).ready()
} catch (e) {
return // Error confirms it is indeed missing
}
throw new Error(`A hypercore with name '${name}' already exists in the corestore`)
@HDegroote
HDegroote / illustration.js
Created January 19, 2023 11:20
Hypercore behaviour change 10.5.4->10.6.0
import Hyperswarm from 'hyperswarm'
import Corestore from 'corestore'
import ram from 'random-access-memory'
/*
With hypercore 10.5.4, the output is:
origCore lenght: 1
Replication with peer set up
Replication with peer set up
readCore length: 1
@HDegroote
HDegroote / index.js
Created March 14, 2024 09:21
Bare crash
/*
Node works as expected:
node index.js # Prints help and exits with 1 status ('done' never printed)
node index.js parse # prints 'done', 0 status
Bare works fine with the parse command:
./node_modules/bare-runtime/bin/bare ./index.js # prints 'done', 0 status code
But fails on:
./node_modules/bare-runtime/bin/bare ./index.js
@HDegroote
HDegroote / create.js
Last active November 7, 2024 11:18
Hypercore download speed
// npm i hypercore-id-encoding corestore hyperswarm b4a tiny-byte-size repl-swarm graceful-goodbye
// node create.js
// Change the constants to change the hypercore size
const idEnc = require('hypercore-id-encoding')
const Corestore = require('corestore')
const Hyperswarm = require('hyperswarm')
const b4a = require('b4a')
const formatBytes = require('tiny-byte-size')
const replSwarm = require('repl-swarm')
@HDegroote
HDegroote / make-drive.js
Created October 10, 2025 10:11
Creat drive with dummy files
const Corestore = require('corestore')
const Hyperdrive = require('hyperdrive')
const Hyperswarm = require('hyperswarm')
const byteSize = require('tiny-byte-size')
const IdEnc = require('hypercore-id-encoding')
async function main () {
const store = new Corestore('drive-create-store')
const drive = new Hyperdrive(store.namespace('drive'))
await drive.ready()