Skip to content

Instantly share code, notes, and snippets.

View alanshaw's full-sized avatar
🫀
https://web3.storage

Alan Shaw alanshaw

🫀
https://web3.storage
View GitHub Profile
@alanshaw
alanshaw / address.ts
Created January 21, 2021 12:10
Utility functions for Addresses
import addr, { Address, newAddress } from '@glif/filecoin-address'
import { blake2b } from 'blakejs'
import varint from 'varint'
/**
* PayloadHashLength defines the hash length taken over addresses using the Actor and SECP256K1 protocols.
*/
export const payloadHashLength = 20
function addressHash (ingest: Uint8Array): Uint8Array {
// 1. Install deps with `npm i csv-parse @glif/filecoin-number`
// 2. Drop `balances.baseline.clean.out` and `balances.claus.clean.out` into the CWD
// 3. Run `node balances-to-json.js`
// 4. It'll create `balances.baseline.json` and `balances.claus.json` and `actors.json` in the CWD
const fs = require('fs')
const parse = require('csv-parse')
const { FilecoinNumber } = require('@glif/filecoin-number')
async function main () {
@alanshaw
alanshaw / format-percentage.js
Created October 12, 2020 10:02
Format a percentage according to some arbitrary rules that actually make it pleasing to look at.
// Format a percentage according to some arbitrary rules that actually make it pleasing to look at.
// 100 -> 100 // whole numbers have no decimal
// 85.1543 -> 85.1 // it just truncates after first non-zero decimal
// 3.00345 -> 3.003 // leading zeros preserved before truncate
// 3.0000345 -> 3.00003 // ...up to a limit of 5dp
// 3.000001 -> 3 // ...so fractional numbers with 5+ leading zeros become an integer
function formatPercentage (num) {
const [int, frac] = num.toFixed(5).split('.')
const index = frac.split('').findIndex(n => n !== '0')
return index === -1 ? int : `${int}.${frac.slice(0, index + 1)}`
@alanshaw
alanshaw / switch-k8-context.sh
Last active October 9, 2020 11:47
Switching k8 contexts for DO
# what even contexts do I have?
kubectl config get-contexts
# switch to other one
kubectl config use-context CONTEXT_NAME
# ===
# for new or update existing cluster credentials:
# ===
@alanshaw
alanshaw / thanks.go
Created June 18, 2020 20:52
stringer detection
name := "Unknown"
sc, ok := r.Client.(fmt.Stringer)
if ok {
name = sc.String()
}
oc.log.Info("optimizing_client", "thanks for the round", "client", name)
@alanshaw
alanshaw / drand.md
Last active July 21, 2020 20:27
drand dev setup

Setup

# Create keys
drand generate-keypair --tls-disable --folder ~/.drand0 127.0.0.1:3000
drand generate-keypair --tls-disable --folder ~/.drand1 127.0.0.1:3100
drand generate-keypair --tls-disable --folder ~/.drand2 127.0.0.1:3200

# Start daemons
drand start --tls-disable --folder ~/.drand0 --private-listen 127.0.0.1:3000 --control 3001 --public-listen 127.0.0.1:3002
@alanshaw
alanshaw / sysctl-tweaks.md
Created May 8, 2020 10:13
Notes on network debugging
@alanshaw
alanshaw / cids.md
Last active May 1, 2020 15:36
Well known CIDs
  • Room Guardian
    • bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
  • IPFS blog
    • bafybeifzcblbfi4nzmaq2ckaag63fufhkbfl7u3zqfkskmwjr3jsxtpyru
  • XKCD
    • QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm
  • Project Apollo Archives
    • QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
  • https://awesome.ipfs.io/datasets/
@alanshaw
alanshaw / example.js
Last active March 24, 2020 11:40
Code exercise
import React, { Component } from 'react'
import IPFS from 'ipfs'
export default class App extends Component {
constructor (props) {
super(props)
this.state = {
ready: false,
files: [],
fileName: '',
@alanshaw
alanshaw / go-cover.sh
Last active June 10, 2020 19:02
golang run tests with coverage and HTML coverage viewer
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... && go tool cover -html=coverage.txt