Skip to content

Instantly share code, notes, and snippets.

View carsonfarmer's full-sized avatar

carsonfarmer carsonfarmer

View GitHub Profile
@alexanderbez
alexanderbez / badger_wrapper.go
Last active January 22, 2023 21:03
An example wrapper around BadgerDB providing a simple embedded key/value store interface.
import (
"context"
"fmt"
"os"
"time"
"github.com/dgraph-io/badger"
)
const (
@yelouafi
yelouafi / delimited-continuations.js
Last active March 21, 2025 18:59
delimited continuations using javascript generators
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} = gen.next(arg)
if(done) {
if(gen._return) {
stepGen(gen._return, value)
}
@Bluebie
Bluebie / account.js
Created November 2, 2019 09:47
Partially encrypted account model for IPFS app
// Model to represent an account in the distributed database
// Accounts are mainly a place users can store information like their private keys, in a password protected
// vault, so they can login conveniently from other devices and keep hold of their private keys and record
// what blogs they are authors of. It's also a way for other users to lookup an authors public keys to validate
// their other objects when determining if a new version of some data really belongs to the blog it claims to be
// related to.
const nacl = require('tweetnacl')
const cbor = require('borc')
class HSAccount {
@douglascayers
douglascayers / async-poller.ts
Created December 23, 2019 05:25
Typescript async polling function. Simple proof-of-concept before I adopted the p-retry npm module.
/**
* The function you pass to `asyncPoll` should return a promise
* that resolves with object that satisfies this interface.
*
* The `done` property indicates to the async poller whether to
* continue polling or not.
*
* When done is `true` that means you've got what you need
* and the poller will resolve with `data`.
*
@seanlinsley
seanlinsley / iterable_weak_set.js
Last active October 7, 2025 00:13
Iterable WeakSet in JavaScript
// spec: https://github.com/tc39/proposal-weakrefs
// the spec contains an [iterable WeakMap implementation](https://github.com/tc39/proposal-weakrefs#iterable-weakmaps)
// NOTE: this WeakSet implementation is incomplete, only does what I needed
// In Firefox Nightly, visit about:config and enable javascript.options.experimental.weakrefs
class IterableWeakSet extends Set {
add(el) {
super.add(new WeakRef(el))
}
forEach(fn) {