Skip to content

Instantly share code, notes, and snippets.

View martinheidegger's full-sized avatar
😅
working

Martin Heidegger martinheidegger

😅
working
View GitHub Profile
import {ReadableStream} from 'node:stream/web';
/**
* @param iterable an iterable (asynchronous or synchronous)
*
* @see https://streams.spec.whatwg.org/#example-rs-pull
*/
function iterableToReadableStream(iterable) {
return new ReadableStream({
async start() {
let last = new Date();
setInterval(function () {
delta = new Date() - last;
if (delta > 2) {
console.log(delta);
}
last = new Date();
}, 1);
setInterval(function () {

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
@timoxley
timoxley / Readme.md
Last active June 7, 2016 07:27
JS Pop Quiz: How well do you know your functions?

JS Pop Quiz: How well do you know your functions?

Given an Array of Functions fns, what argument(s) can you pass to fns.forEach such that each function in fns will execute, in order, without creating any anonymous (or named) functions or invoking the Function constructor?

Conditions

  • Do not use the function keyword, or arrow functions () => .
  • Do not invoke the Function constructor.
  • Do not use method definitions.
  • Function#bind & friends on the Function.prototype are ok.
@michelsalib
michelsalib / timestampable.ts
Created April 22, 2015 15:52
Typescript @timestampable annotation
@timestampable
class Dog {
public name: string = 'Paul';
}
function timestampable(func) {
return <any>(function() {
var genericConstructor = () => {};
genericConstructor.prototype = func.prototype;
var instance = new genericConstructor();