Skip to content

Instantly share code, notes, and snippets.

Mathias Buus mafintosh

Block or report user

Report or block mafintosh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test.js
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
View readable-transform-bench.js
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)
View vhs.js
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()
}
})
View join-the-dht-cult.md

Hyperswarm DHT setup

Checking your network for P2Pness

First, it's a good idea to check if your network has good "holepunching" support. We can check that using the hyperdht cli

npm i -g @hyperswarm/cli
hyperswarm-discovery --ping
View onload.js
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)
View fastify-assertion.js
const fastify = require('fastify')
const assert = require('assert')
const app = fastify()
app.get('/', async (req, reply) => {
assert.fail('sup')
reply.send('hi')
})
View thunky-promise.js
function thunkyPromise (worker) {
let current = null
return function () {
if (!current) current = worker().catch(onerror)
return current
}
function onerror () {
current = null
}
View hypercore-2-brainstorm.txt
S
/ \
B - A
A requests 0 when there only one piece of data
A (0)
A goes offline
View mdn-bug.js
console.log(Math.clz32(42424), clz(42424))
function clz(x) {
// Let n be ToUint32(x).
// Let p be the number of leading zero bits in
// the 32-bit binary representation of n.
// Return p.
if (x == null || x === 0) {
return 32;
}
View npm-clone.sh
npm-clone () {
if echo $1 | grep '/' >/dev/null; then
git clone git@github.com:$1.git
else
git clone git@github.com:mafintosh/$1.git
fi
cd $(echo $1 | sed 's|.*/||')
[ -f "package.json" ] && npm install
cd ..
}
You can’t perform that action at this time.