Skip to content

Instantly share code, notes, and snippets.

James Halliday substack

Block or report user

Report or block substack

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@substack
substack / perf.js
Created Jul 17, 2019
dataview vs typed array performance
View perf.js
let abuf = (function () {
let ua = new Uint32Array(1000*1000)
let max = 2**32
for (let i = 0; i < ua.length; i++) {
ua[i] = i%5
}
return ua.buffer // assume we got this from a network connection
})()
;(function () {
@substack
substack / kv.js
Created Jun 27, 2019
sharding hypertrie kv prototype api
View kv.js
var argv = require('minimist')(process.argv.slice(2), {
alias: { d: 'datadir', s: 'swarm', n: 'node' },
string: [ '_' ]
})
if (argv._[0] === 'listen') {
var prefix = argv._[1]
var listen = require('../listen.js')({
prefix,
swarm: require('discovery-swarm')
@substack
substack / core.js
Created Jun 21, 2019
hooking into have/want events in hypercore replication
View core.js
var hypercore = require('hypercore')
if (process.argv[2] === 'init') {
var feed = hypercore(process.argv[3])
feed.ready(function () {
console.log(feed.key.toString('hex'))
})
} else if (process.argv[2] === 'populate') {
var feed = hypercore(process.argv[3])
var r = feed.replicate({ live: true })
@substack
substack / bytes.js
Last active May 17, 2019
split a u64 into two u32s and verify that the combination works
View bytes.js
var n = 123456789012345
var u32a = Uint32Array.from([n,n/2**32])
var u8a = new Uint8Array(u32a.buffer)
console.log(u8a)
// Uint8Array [ 121, 223, 13, 134, 72, 112, 0, 0 ]
View hawaii-police-shootings.md
@substack
substack / main.rs
Created Jan 11, 2019
rust combination macro
View main.rs
macro_rules! comb {
($f:tt, ($($x:tt),*), $H:expr, $($T:expr),*) => {
comb!($f, ($($x,)*$H), $($T),*);
comb!($f, ($($x,)*($H,$H)), $($T),*);
};
($f:tt, ($($x:tt),*), $H:expr) => {
$f!("{:?}", ($($x),*,$H));
$f!("{:?}", ($($x),*,($H,$H)));
};
}
@substack
substack / net.js
Created Dec 4, 2018
web extension nodejs net module adaptor
View net.js
var EventEmitter = require('events').EventEmitter
var Duplex = require('readable-stream').Duplex
var encoder = new TextEncoder
var decoder = new TextDecoder
exports.Server = Server
exports.createServer = function (opts) {
return new Server(opts)
}
exports.connect = exports.createConnection = connect
@substack
substack / .gitconfig
Created Nov 25, 2018
git config alias for serving local repos
View .gitconfig
[alias]
serve = "!server(){ git daemon --verbose --export-all --base-path=. --reuseaddr $@; }; echo git://localhost:9418/; server"
@substack
substack / manifest.json
Created Nov 22, 2018
tcp server web extension. copy the files from https://github.com/mozilla/libdweb/tree/master/src/TCPSocket into exapi/tcp
View manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "tcp-server-demo",
"description": "tcp server in a web extension",
"permissions": [],
"experiment_apis": {
"TCPSocket": {
"schema": "exapi/tcp/schema.json",
"child": {
@substack
substack / bot.js
Last active Nov 10, 2018
deltachat bot, not working yet
View bot.js
var DeltaChat = require('deltachat-node')
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var handle = require('./handle.js')
var minimist = require('minimist')
var argv = minimist(process.argv.slice(2), {
alias: { c: 'config' }
You can’t perform that action at this time.