Skip to content

Instantly share code, notes, and snippets.

View mikeal's full-sized avatar
🏠
Working from home

Mikeal Rogers mikeal

🏠
Working from home
View GitHub Profile
@mikeal
mikeal / gist:1840641
Created February 16, 2012 01:33
get a new/clean port with node.js
var portrange = 45032
function getPort (cb) {
var port = portrange
portrange += 1
var server = net.createServer()
server.listen(port, function (err) {
server.once('close', function () {
cb(port)
@mikeal
mikeal / r2.js
Last active April 21, 2023 17:13
HTTP Client Comparison
const r2 = require('r2')
let doJsonThing = async (path, propname) => {
let res = await r2(`http://api.com${path}`).json
return res[propname]
}
@mikeal
mikeal / count-npm-dependencies.js
Created February 16, 2016 00:49
Calculate the average number of dependencies in all modules on npm.
var request = require('request')
, JSONStream = require('JSONStream')
, deps = []
request('https://skimdb.npmjs.com/registry/_all_docs?include_docs=true')
.pipe(JSONStream.parse('rows.*.doc'))
.on('data', function (obj) {
// project against outdated or broken package.json
if (!obj['dist-tags']) return
if (!obj['dist-tags'].latest) return

We’ve been saying for a long time that we need “something like a CAP theorum for IPLD.” By this, I mean that we need a way to talk about the design tradeoffs that are made when designing data structures in IPLD.

This is going to end up looking a lot different than the CAP theorem but the end goal is to have something that provides us a blueprint for how to discuss the performance tradeoffs of different data structure designs.

Anyway, here’s my attempt at a first draft. It’s incomplete but I need some feedback in order to iterate on it and turn it into a proper PR.


@mikeal
mikeal / get-comments.js
Last active June 14, 2022 12:36
The easiest way to get comments out of any code file... seriously?!?
var highlight = require('highlight.js')
var cheerio = require('cheerio')
var strip = ['/', '#', ' ', '*', "<", ">", '-', '\\']
function getComments (str) {
var html = highlight.highlightAuto(str).value
var $ = cheerio.load(html)
var lines = $('span.hljs-comment').map(function(i, el) {return $(this).text();}).get()
return lines.map(function (l) {
@mikeal
mikeal / blocks-in-ipfs.js
Created October 20, 2020 20:24
Filecoin Liftoff
import * as Block from 'multiformats/block'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as codec from '@ipld/dag-cbor'
import { CID } from 'multiformats'
let value = { hello: 'world' }
let hello = await Block.encode({ value, codec, hasher })
let bbbb = await Block.encode({ value: { foo: hello.cid }, codec, hasher })
const publicIp = require('public-ip')
const bent = require('bent')
const get = bent('json', 'https://my-lambda-url')
exports.handler = async function http (req) {
let { retries, ips } = req.queryStringParameters
const ip = await publicIp.v4()
if (ips) ips = ips.split(',')
else ips = []
@mikeal
mikeal / missing.sh
Created July 1, 2020 21:38
show functions with missing coverage
cat coverage/tmp/coverage-* | jq '.result[] | select(.url == "file:///root/dagdb/src/kv.js")
| .functions[] | select(.ranges[].count == 0)'
@mikeal
mikeal / gist:9242748
Last active June 23, 2020 05:17
Response to Nodejitsu NPM Trademark

I've known people at nodejitsu for years, since before the company even existed. I still consider many of them friends. That said, somebody over there has lost their mind.

Trademarks are an important part of open source. They protect the integrity of the trust that is built by any project. A classic example of why this is the case is Firefox. Suppose that a malware producer takes the Firefox codebase, which is free and open source, packages up their malware with it and then releases it as "Firefox". Then they buy search advertising and suddenly their bad and malicious version of Firefox is the first result on search engines across the web. This is clearly a bad thing for Firefox and open source everywhere, but what can Mozilla do to protect their community of users?

They can't enforce a software license since the use is permitted under the Mozilla Public License. They can, however, enforce on these hypothetical bad actors using their trademark on the word "Fi

{
"carUrl": "https://dumbo-v2-cars-encode-public.s3.us-west-2.amazonaws.com/bafyreifxo4u7nuyvjjwhlibvnzjxrb6bxo3ok6xeukze6iybdyc7kvngum%2Fbafyreifxo4u7nuyvjjwhlibvnzjxrb6bxo3ok6xeukze6iybdyc7kvngum.car",
"dataset": "encode-public",
"parts": [
"mAVUSIG7RzFYiX3JUIBAJzDy/V1dgHlI/3yp8/brAZWkDZZWe",
"mAVUSICl6Enz7p+XpsR19HX3rXFbT98sP1GS98L2nm7pwMsI0",
"mAVUSIFlxWE0UJw41r+YniU9oieqKfQgolSDLU0apaB5LD5CZ",
"mAVUSIMmZlwF2h1G2HkUgK62LxJAhNrD0XfBrRpoeUl1WBm7K",
"mAVUSILZYhlK40rJ0Fxfexl5ugh60G9agykgXqyQKYwqpeh+3",
"mAVUSIOqqvN4gCRPRqFMgmw2nuNxKgTdKNf2jhblmSPyuzwA0",