Skip to content

Instantly share code, notes, and snippets.

Hyper-dns and all the dns's

Martin Heidegger martinheidegger

Hyper-dns and all the dns's
View GitHub Profile
View index.js
const Corestore = require('corestore')
const Networker = require('@corestore/networker')
const { mkdir } = require('fs/promises')
let index = 0
async function create () {
index += 1
const dir = `.tmp/${index}`
await mkdir(dir, { recursive: true })
const store = new Corestore(dir)
martinheidegger /
Last active Oct 9, 2019
Self-healing hypercores

Self Healing Hypercores

In DAT, append-only logs addressable by a key are called hypercores. When you copy one such log to another computer and write to it, there are suddenly two logs in two different locations. The new location being a fork of the first log. Both logs can be found under the same ID, making it impossible to distinguish them from another.

DAT mitigates this by making every log "single-writer". Only with a secret writeKey you can append data to the log. By convention that secret is

martinheidegger / array.js
Last active Jan 31, 2019
Set Performance Test
View array.js
'use strict'
const setOp = require('unordered-set')
module.exports = {
add: (count, objs) => {
const set = []
for (var i = 0; i < count; i++) {
setOp.add(set, objs[i])
setOp.add(set, objs[i])
return set
martinheidegger / ?.md
Last active Dec 28, 2018
TypeScript definitions with different return types
View ?.md

How do I write the following JavaScript in Typescript most efficiently?

  • sample.js does a fairly simplified example for a code with the logic: "if callback, then callback, else promise" in add and a logAndAdd method reuses add, so the result of logAndAdd will also be either a callback or a promise, depending on the input.

  • test.js makes sure that this is supposed to work

  • sample.d.ts is how I assume the .d.ts should look like

  • sample.ts is not working but shows how I thought TypeScript could work neatly.


Keybase proof

I hereby claim:

  • I am martinheidegger on github.
  • I am martinheidegger ( on keybase.
  • I have a public key ASAODk6U9znTl6lczgayqQWDNnAK-NGrPZWWtMF02Nj6VQo

To claim this, I am signing this object:

martinheidegger / partArray.js
Created Sep 3, 2018
Construct Huge arrays made out of parts ^_^
View partArray.js
function partArray ( {
let lengths = => part.length)
let length = lengths.reduce((total, length) => total + length)
function* iterator () {
for (const part of parts)
for (const value of part) yield value
function item (index) {
let partIndex = 0
for (const part of parts) {
martinheidegger / example_output.csv
Last active Dec 22, 2017
Stat module for Node.js to collect averages of Memory & CPU consumption over a given period of time.
View example_output.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 16 columns, instead of 14. in line 4.
1513914518233, 78273,78273,78273,23573,23573,23573,5583596,5329040,5838152,10854400,10854400,10854400,558976,439592,678360
1513914520381.644, 61037.47537077804,61037.47537077804,61037.47537077804,23573,23573,23573,7570791.859881992,7168906.021724596,7898616.114693746,10854400,10854400,10854400,1522872.917892116,1416024.60562031,1889588.4111456308
1513914522528.9185, 48683.45425623419,48683.45425623419,48683.45425623419,23573,23573,23573,8585283.686068054,8419800.250697419,8931602.671535378,10854400,10854400,10854400,2458086.628234829,2394709.239230188,2883538.4351940444
1513914524676.8794, 39999.763262061286,39999.763262061286,39999.763262061286,23573,23573,23573,9220846.7495376,9108108.058582326,9425541.758640196,10854400,10854400,10854400,3383111.35641
martinheidegger / debug-promise.js
Last active Jul 20, 2017
An approach to debug promises that have not yet finished when the process is exited.
View debug-promise.js
'use strict'
const DATE_MAX = (36 * 36 * 36 * 36 * 36) // Since we use base 36 this should give us 5 characters
const RANDOM_MAX = 100000
function createId () {
// ID consistent of a time aspect as well as a random aspect to make sure two Promises
return `${( % DATE_MAX).toString(36)}-${(Math.random() * RANDOM_MAX | 0).toString(36)}`
martinheidegger / nodeticks.js
Last active Apr 19, 2017
An explanatory script to illustrate the timings of intervals and the event loop
View nodeticks.js
#!/usr/bin/env node
const foreverTick = (fn) => {
// Note: Using process.nextTick instead of setImmediate will result in an endless loop!
const ticker = () => {
// stopForever is a nice trick for a stoppable forever function
const stopForever = fn()
if (!stopForever) {

Node.js Stiftung - Stipendium zur Förderung der Vielfalt

Über das Stipendium

Der Node.js Stiftung ist es ein wichtiges Anliegen jeden in die Community einzuschliessen, aus diesem Grund möchten wir uns an Mitglider aus Technologie und Open-Source Gruppen von Minderheiten und Randgruppen richten.

Drei Personen werden eine Förderung erhalten. Entschieden wird auf Basis von Notlage und des Einflusses der Person.

Die Förderung umfasst