Skip to content

Instantly share code, notes, and snippets.

View carsonfarmer's full-sized avatar
🏖️
Remote working...

Carson Farmer carsonfarmer

🏖️
Remote working...
View GitHub Profile
@seanlinsley
seanlinsley / iterable_weak_set.js
Last active August 2, 2023 03:58
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) {
@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`.
*
@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 {
@yelouafi
yelouafi / delimited-continuations.js
Last active July 13, 2023 21:41
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)
}
@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 (
const { Transform } = require('stream');
class AppendInitVect extends Transform {
constructor(initVect, opts) {
super(opts);
this.initVect = initVect;
this.appended = false;
}
_transform(chunk, encoding, cb) {
package main
import (
"fmt"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
// Simple example of how to display an image from IPFS on your html web page
// Using ipfs/js-ipfs : https://github.com/ipfs/js-ipfs#use-in-the-browser
// Don't forget to include the scripts into your html page:
// <script src="https://unpkg.com/ipfs/dist/index.min.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
function showIPFSImage () {
// Create the IPFS node instance
const node = new Ipfs()
@jonathanlurie
jonathanlurie / jsont.js
Last active August 16, 2023 08:33
Serialize/deserialize json and conserve typed arrays
/*
Author: Jonathan Lurie - http://me.jonathanlurie.fr
License: MIT
The point of this little gist is to fix the issue of losing
typed arrays when calling the default JSON serilization.
The default mode has for effect to convert typed arrays into
object like that: {0: 0.1, 1: 0.2, 2: 0.3} what used to be
Float32Array([0.1, 0.2, 0.3]) and once it takes the shape of an
object, there is no way to get it back in an automated way!