Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
var hypercore = require('hypercore')
var ram = require('random-access-memory')
var feed = hypercore(ram)
feed.append('hello world')
@mafintosh
mafintosh / node-tar.js
Last active December 7, 2023 12:59
tar-fs vs node-tar benchmarks
var tar = require('tar');
var fstream = require('fstream');
var input = '/Users/maf/Downloads';
var reader = fstream.Reader({type: "Directory", path: input});
var pack = tar.Pack();
reader.pipe(pack).pipe(tar.Extract({path: '/tmp/destination-node-tar'}));
yrb9it8e6yzrxcxm48xbihewqh1zca9i93t3gc4scccgz11y6e69yr3ss1be6ksuacbopt66wrw4rtpq1k8gqihykshqqg1dznydnkjheafyotmf
@mafintosh
mafintosh / bitcoin-for-voksne.md
Last active October 17, 2023 20:39
Blog post about how Bitcoin works in a way non computer people can understand it (Danish)

Bitcoin for voksne

(Chinese version available here)

(English version available here)

Bitcoin er en digital valuta, som ikke har nogen central autoritet. Det er en valuta hvor du ikke behøver at stole på nogen som helst for at vide at den er noget værd. Som begreb minder det meget om guld. Guld har en værdi i sig selv, i modsætning til en 100 kr seddel som kun har værdi hvis den danske stat siger den har værdi. På samme måde er ideen omkring Bitcoins at de har en værdi i sig selv.

Lad os prøve at forstå hvordan Bitcoin fungerer.

{
"since": 7380137,
"addresses": [
"0x8c6b04da932d1151e0e1c65f3d8b12a971e02b17",
"0xd04a779f681014832013a5cc58bfafafa26cbaf5",
"0x439aa60d35338b01e7ce16b98469c26dd8a79b52",
"0x904224d70521a09aC117CD499F6B4A68aBc5B852"
],
"transactions": [
{
@mafintosh
mafintosh / app.js
Last active November 26, 2022 00:03
Showcasing bundled prebuilds with different runtimes
var electron = require('electron')
electron.app.on('ready', function () {
var win = new electron.BrowserWindow({
width: 800,
height: 600
})
win.loadURL('file://' + __dirname + '/index.html')
win.toggleDevTools()
@mafintosh
mafintosh / uint64.js
Last active November 26, 2022 00:01
var v0 = 0 // represent the first 24bit of an uint64
var v1 = 0 // next 8bit
var v2 = 0 // final 32bit
function addUint64 (b0, b1, b2) {
v0 = (v0 & 0xffffff) + b0 // cast to 24bit and add b0
v1 = (v1 & 0xff) + b1 + (v0 >>> 24) // cast to 8bit, add b1 one plus the carry from v0
v2 = (v2 + b2 + (v1 >>> 8)) | 0 // add b2 and carry from v1. cast to int to make v8 happy
}
var hyperdrive = require('./')
var ram = require('random-access-memory')
var drive = hyperdrive(ram)
drive.history({live: true}).on('data', console.log)
drive.writeFile('/hello', 'world', function () {
drive.writeFile('/hello', 'verden', function () {
replicate()
var archive = hyperdrive(datStorage('/..../..../'), key, {latest: true})
var hyperdiscovery = require('hyperdiscovery')
archive.on('ready', function () {
console.log('ready...')
hyperdiscovery(archive)
})
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')