Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
S
/ \
B - A
A requests 0 when there only one piece of data
A (0)
A goes offline
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;
}
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 ..
}
const noise = require('noise-peer')
const network = require('@hyperswarm/network')
const jsonStream = require('duplex-json-stream')
const hypercore = require('hypercore')
const pump = require('pump')
const swarm = network()
const hyperswarm = network()
const publicKey = Buffer.from(process.argv[2], 'hex')
@mafintosh
mafintosh / package.json
Created November 6, 2018 09:52
p2p workshop
{
"name": "kappa-workshop",
"description": "P2P collaboration workshop",
"license": "MIT",
"dependencies": {
"chalk": "^2.4.1",
"discovery-swarm": "^5.1.2",
"hypercore": "^6.20.2",
"kappa-core": "^2.3.2",
"kappa-view-kv": "^2.0.1",
dat://a50ec5d10f61c2e6e4f7d8cd67324603052b0450dc187a86b1134c662a52599c
const zlib = require('zlib');
const { Writable } = require('stream');
const ts = zlib.createGzip();
const buf = Buffer.allocUnsafe(1024 * 1024 * 20);
ts.on('data', common.mustCall(() => ts.close()));
ts.end(buf);
const zlib = require('zlib')
const { Writable } = require('stream')
const ts = zlib.createGzip()
const ws = new Writable({
write (chunk, enc, cb) {
setImmediate(cb)
ts.close()
}
const hooks = require('async_hooks')
const promises = new Set()
const hook = hooks.createHook({
init (asyncId, type) {
if (type === 'PROMISE') {
promises.add(asyncId)
}
},
@mafintosh
mafintosh / find-my-way-new-bench.txt
Created August 29, 2018 23:49
updating find-my-way with a code generated prefix trie
lookup static route x 52,214,074 ops/sec ±0.49% (94 runs sampled)
lookup dynamic route x 11,251,578 ops/sec ±1.89% (89 runs sampled)
lookup dynamic multi-parametric route x 7,225,928 ops/sec ±2.04% (91 runs sampled)
find dynamic multi-parametric route with regex (NOT FULLY IMPLEMENTED, BUT FOLLOWING TREND SOFAR)
lookup long static route x 7,017,902 ops/sec ±0.75% (87 runs sampled)
lookup long dynamic route x 5,324,800 ops/sec ±1.48% (89 runs sampled)
find static route x 53,943,393 ops/sec ±1.72% (88 runs sampled)
find dynamic route x 15,433,000 ops/sec ±1.87% (89 runs sampled)
find dynamic multi-parametric route x 14,652,641 ops/sec ±1.00% (93 runs sampled)
find dynamic multi-parametric route with regex (NOT FULLY IMPLEMENTED, BUT FOLLOWING TREND SOFAR)