Skip to content

Instantly share code, notes, and snippets.

@emilbayes
emilbayes / .travis.yml
Last active April 21, 2023 01:00
Continous Delivery with Travis CI
language: node_js
node_js:
- '0.11'
notifications:
email: false
deploy:
- provider: heroku
api_key:
secure: ...
app: some-app
@emilbayes
emilbayes / key.js
Created March 30, 2020 22:30
Key encapsulation
const sodium = require('sodium-native')
const assert = require('nanoassert')
const priv = new WeakMap()
class Key {
static BYTES = sodium.crypto_secretbox_KEYBYTES
static NONCEBYTES = crypto.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
static TAGBYTES = sodium.crypto_aead_xchacha20poly1305_ietf_ABYTES
static create () {
@emilbayes
emilbayes / index.js
Created March 20, 2020 12:01
DHT with sodium-native
const sodium = require('sodium-native')
const DHT = require('bittorrent-dht')
const dht = new DHT({
verify: sodium.crypto_sign_verify_detached
})
const keys = keygen()
dht.put({
v: Buffer.from('Hello world'),
function generator () {
var lastTime = Date.now()
var cnt = 0
return function () {
var currentTime = Date.now()
if (currentTime !== lastTime) {
lastTime = currentTime
cnt = 0
}
const accounts = 1
const bits = 42
function forin (n, exp) {
res = []
for (var i = 0; i < n; i++) {
res.push(exp(n))
}
return res
}
@emilbayes
emilbayes / json-pointer.js
Created March 10, 2015 14:57
Minimalistic JSON Pointer (RFC 6901) implementation. Does not support URI Fragments, but otherwise compliant
'use strict';
exports.get = function(document, pointer) {
//Empty pointer references the whole document
if(pointer === '') return document;
//Split the pointer into reference tokens and unescape
var referenceTokens = pointer.slice(1).split('/').map(unescape);
//Decent down the object iteratively
return referenceTokens.reduce(function(object, token) {
node_modules
remote
local
@emilbayes
emilbayes / README.md
Last active November 14, 2018 11:16
Streams stuff
  • do on readable then read
  • do framing
  • don't use data
  • check this.destroyed after each "Hand-off" (emit and push)
  • check stream.destroyed after all async operations