Skip to content

Instantly share code, notes, and snippets.

@nasser
nasser / render.js
Created Jan 7, 2021
Flat template rendering in node.js in two lines of code
View render.js
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'"
View sources-hypercore-sparse.js
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 Aug 1, 2019
The 12 Pomodoro Workday
View 12pomodoro.md

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,

View join-the-dht-cult.md

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 Jul 10, 2019
Testing out substack's "ACK' functionality for hypercore!
View Readme.md

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
@substack
substack / core.js
Created Jun 21, 2019
hooking into have/want events in hypercore replication
View core.js
var hypercore = require('hypercore')
if (process.argv[2] === 'init') {
var feed = hypercore(process.argv[3])
feed.ready(function () {
console.log(feed.key.toString('hex'))
})
} else if (process.argv[2] === 'populate') {
var feed = hypercore(process.argv[3])
var r = feed.replicate({ live: true })
View dat-resilience.md

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
View errmojis.md

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 / go-os-arch.md
Last active Jul 8, 2021
Go (Golang) GOOS and GOARCH
View go-os-arch.md

Go (Golang) GOOS and GOARCH

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

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • aix
  • android
View help.sh
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]