Skip to content

Instantly share code, notes, and snippets.

@nasser
nasser / render.js
Created January 7, 2021 18:10
Flat template rendering in node.js in two lines of code
const render = (template, values) =>
template.replace(/\{\{([^}]+)\}\}/g, (_, key) => values[key]);
render("hello {{place}}", { place: "world" })
// => "hello world"
render("shell='{{SHELL}}', term='{{TERM}}'", process.env)
// => "shell='/bin/bash', term='xterm-256color'"
const tape = require('tape')
const hypercore = require('hypercore')
const ram = require('random-access-memory')
const { runAll, replicate } = require('./lib/util')
const { Kappa } = require('..')
const createIndexer = require('../sources/hypercore-sparse')
const topics = ['red', 'blue', 'green', 'yellow']
@colby
colby / 12pomodoro.md
Last active August 1, 2019 16:59
The 12 Pomodoro Workday

The 12 Pomodoro Workday

Or the 25 hour work week. Heavily borrowed from cblgh.

The Planning

The structure is simple:

  • 1 pomodoro planning the work day
  • 8 pomodoros of work
  • 3 pomodoros of break

1+8+3=12 pomodoros,

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
@dwblair
dwblair / Readme.md
Last active July 10, 2019 00:20
Testing out substack's "ACK' functionality for hypercore!

testing out ACKs in hypercore

Using substack's 'ack' branch of hypercore, you can set an 'ack' flag to 'true' when creating a hypercore replication feed, and you'll be able to tell, for any given hypercore log block you append to a hypercore feed, whether it has been received by a peer.

As a test, I ran "node testsend.js" below ... which generates a public key [KEY], and allows me to type messages into the terminal 'live'. In another directory, I ran "node testreceive.js [KEY]" in order receive those messages ...

Here's what it looked like on the 'send' side as I typed in new messages (I'm including a snippet after I'd already been testing a while) ...

2019-07-06T23:03:14.746Z> bubbles

So, as I mentioned last time, I have two fundamental goals with dat that are not addressed by simply running dat share.

  • Uptime: making sure that the site is seeded even if my local laptop is closed, eaten by a bear, or disconnected from the internet
  • Resilience: ensuring that there's a way to restart my website if the original seeding computer is lost. I try to make everything on my primary work/personal computer work in such a way that I can recover it all, easily, onto a new machine if I need to

To break these down a bit more, uptime is a combination of two things:

  • Ensuring that there are seeders
  • Ensuring that those seeders are seeding, and they're up-to-date

Errmojis

Users have a hard time dealing with errors.

To solve that, put these emojis prominently in your error messages. Then when the user says:

I dont know what happened but I saw a christmas tree and then everything stopped working

You'll know it was an internal error!

@asukakenji
asukakenji / 0-go-os-arch.md
Last active April 24, 2024 06:51
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.17.1 darwin/amd64.

GOOS Values

GOOS Out of the Box
aix
android
quinlan@corinthian:~/.weechat/logs$ grep -B1 -rn 'tenyks.*LOLBOW$' ./irc.freenode.#infoforcefeed.weechatlog | grep -v 'LOLBOW' | grep -v '\-\-' | sed -r 's/([0-9 -:]*)(\s*)([a
-zA-Z1-9_-]*)(\s*)lol$/\3/g' | sort | uniq -c > /tmp/matches.txt
quinlan@corinthian:~/.weechat/logs$ cat /tmp/matches.txt
1 437815-2016-03-03 03:10:59 tenyks Link title: Urban Dictionary: Lol
1 446223-2016-04-05 19:07:17 Xe lol\
1 466876-2016-06-09 15:13:39 nijotz BimboTea
1 469408-2016-06-24 23:06:43 dm lol me bb
1 469885-2016-06-27 14:35:13 lykkin lol that's a good typo
1 525127-2017-02-28 16:05:48 [2017]
1 527824-2017-03-14 19:15:10 [2017]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import errno
import os
import shutil
from subprocess import check_output
import arrow