Skip to content

Instantly share code, notes, and snippets.

Avatar
👀
https://web3.storage

Alan Shaw alanshaw

👀
https://web3.storage
View GitHub Profile
@alanshaw
alanshaw / sns2s3.js
Created Jun 10, 2022
SNSEvent to S3Event
View sns2s3.js
/**
* Extract an S3Event from the passed SNSEvent.
* @param {import('aws-lambda').SNSEvent} snsEvent
* @returns {import('aws-lambda').S3Event}
*/
function toS3Event (snsEvent) {
const s3Event = { Records: [] }
for (const snsRec of snsEvent.Records) {
try {
for (const s3Rec of JSON.parse(snsRec.Sns.Message).Records || []) {
@alanshaw
alanshaw / filter.txt
Created Jun 7, 2022
Filter github PRs you need to review
View filter.txt
review-requested:alanshaw
View dagChecker.js
// Lambda index CAR ////////////////////////////////////////////////////////////
const blocks = Set<CID>()
const links = Set<CID>()
const car = readCar(path)
for (const block in car) {
blocks.add(block.cid)
getLinks(block).forEach(cid => links.add(cid))
}
@alanshaw
alanshaw / custom-bs-path.mjs
Last active Apr 19, 2022
Store to NFT.Storage using a custom blockstore path
View custom-bs-path.mjs
import { NFTStorage } from 'nft.storage'
import { getFilesFromPath } from 'files-from-path'
import { FsBlockStore as Blockstore } from 'ipfs-car/blockstore/fs'
import Path from 'path'
const token = 'YOUR_API_TOKEN'
// ///////////////////////////////////////////////////////////////////////////
// Save DAG to a custom location by changing this path...
const bsPath = './blockstore'
@alanshaw
alanshaw / setulimit.sh
Created Mar 22, 2022
ulimit maxfiles on MacOS Monterey
View setulimit.sh
sudo sysctl kern.maxfilesperproc=256
@alanshaw
alanshaw / sample.mjs
Created Mar 7, 2022
Sample dotStorage CIDs
View sample.mjs
/**
* Create IPFS unixfs directories of random CIDs from the data source. CIDs are
* grouped by DAG size:
* 0-1MB
* 1MB-5MB
* 5MB-25MB
* 25MB-100MB
* 100MB-500MB
* 500MB-1GB
* 1GB-10GB
View web3file.ts
import path from 'path'
type ImportCandidate = x|y|z|{ path: string, content: x|y|z }
type UnixFsEntry = { path: string, content: AsyncIterable<Uint8Array> }
// extends Blob?
class Web3File extends Blob {
constructor (filename: string, content: AsyncIterable<Uint8Array>, options?: Web3FileOpts)
// Generate from content?
View deadline.js
const deadline = async function * (source, deadineMs, onDeadline) {
class DeadlineError extends Error {}
while (true) {
let timeoutID
try {
const next = await Promise.race([
new Promise((resolve, reject) => {
timeoutID = setTimeout(() => reject(new DeadlineError()), deadineMs)
}),
source.next()
@alanshaw
alanshaw / address.ts
Created Jan 21, 2021
Utility functions for Addresses
View address.ts
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 {
View balances-to-json.js
// 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 () {