Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
const p = Promise.reject()
p.catch(() => {})
function destroy () {
return p
}
const another = Promise.reject()
{
"since": 7380137,
"addresses": [
"0x8c6b04da932d1151e0e1c65f3d8b12a971e02b17",
"0xd04a779f681014832013a5cc58bfafafa26cbaf5",
"0x439aa60d35338b01e7ce16b98469c26dd8a79b52",
"0x904224d70521a09aC117CD499F6B4A68aBc5B852"
],
"transactions": [
{
const Corestore = require('corestore')
const SwarmNetworker = require('corestore-swarm-networking')
const store = new Corestore('./path-1')
store.ready(function () {
const swarm = new SwarmNetworker(store)
const feed = store.default()
swarm.listen()
await trie.symlink('bb/b','c')
await trie.symlink('../dd','b')
await trie.put('dd/c/bc/b','dsiypoxbuo') // dd/c/bc/b --> dsiypoxbuo
await trie.put('b/d/c/c','ljbdomybyu') // dd/d/c/c --> ljbdomybyu
await trie.rename('dd','c/db') // dd/c/bc/b --> dd/b/db/c/bc/b, dd/d/c/c --> dd/b/db/d/c/c
await trie.put('c/db/c/b/bc','nlcmgluggs')
// reference says bb/b/db/c/bc/b -> dsiypoxbuo
const streamx = require('streamx')
const stream = require('stream')
let count = 2 * 1024 * 1024
const srcCore = new stream.Readable({
objectMode: true,
read () {
this.push('tick ' + count--)
if (!count) this.push(null)
const Button = require('./button')
vhs.delay(1000)('button works', async (t) => {
const btn = new Button('click me!', {
onclick () {
t.pass('i should get nere')
t.end()
}
})

Hyperswarm DHT setup

Checking your network for P2Pness

Running a node

Running a dht node is as simple as installing the DHT cli.

npm i -g @hyperswarm/cli
const tracking = new WeakMap()
const clz = 'onload-' + Math.random().toString(36).slice(2)
const observer = new MutationObserver(function (mutations) {
for (let j = 0; j < mutations.length; j++) {
const { addedNodes, removedNodes, target } = mutations[j]
for (let i = 0; i < addedNodes.length; i++) {
if (!addedNodes[i].classList) continue
if (addedNodes[i].classList.contains(clz)) tracking.get(addedNodes[i]).onload(target)
const fastify = require('fastify')
const assert = require('assert')
const app = fastify()
app.get('/', async (req, reply) => {
assert.fail('sup')
reply.send('hi')
})
function thunkyPromise (worker) {
let current = null
return function () {
if (!current) current = worker().catch(onerror)
return current
}
function onerror () {
current = null
}