Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
@mafintosh
mafintosh / index.js
Created April 25, 2014 14:55
phantom crazyness
var proc = require('child_process');
var stream = require('stream');
var DELIMITER = new Buffer('\n---------------\n');
var phantom = proc.spawn('phantomjs', ['phantom2.js']);
var urls = [
'http://sorribas.org',
'http://e-conomic.com',
IEUser@IE9WIN7 ~/test
$ npm i leveldown-prebuilt
npm http GET https://registry.npmjs.org/leveldown-prebuilt
npm http 304 https://registry.npmjs.org/leveldown-prebuilt
npm http GET https://registry.npmjs.org/node-pre-gyp
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/abstract-leveldown
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/node-pre-gyp
var storage = require('...')
var st = storage('./directory', torrent)
// the files will be stored as ./directory/file1.ext
// ./directory/file2.ext
// etc
st.put(index, piece, callback)
st.get(index, {start:0, end:10}, function(err, buffer) {
var osmdata = protobuf([{
name: 'stringtable',
type: 'bytes',
tag: 1
}, {
name: 'primitivegroup',
type: 'bytes',
tag: 2
}, {
name: 'granularity',
var torrentStream = require('torrent-stream')
var engine = torrentStream(require('fs').readFileSync('osm.torrent'))
engine.connect('172.16.16.162:61000')
engine.on('ready', function() {
console.log(engine.files[0].name)
engine.files[0].select()
})
@mafintosh
mafintosh / client.js
Created May 29, 2014 11:59
stream based dat replication
var replication = require(...)
var r = replication(datInstance)
var socket = net.connect(9090, 'localhost')
socket.pipe(r.createPushStream()).pipe(socket)
@mafintosh
mafintosh / gist:92ec1bd3a216efec975f
Last active August 29, 2015 14:02
dat clone / dat pull
var replicator = require('dat-replicator')
var request = require('request')
var Dat = require('dat')
var dat = new Dat('./', function(err) {
if (err) throw err
var req = request.post('http://localhost:6461/api/replicator/send')
var receive = replicator(dat).receive()
BinaryEncoding {
string key = 1
uint32 version = 2
Schema document = 3
}
Schema {
// whatever is defined by the dat schema
}
@mafintosh
mafintosh / progress.js
Created June 3, 2014 00:53
progress monitoring in dat
var progress = replicator.createPullStream(remote)
progress.bytes // how many bytes transferred
progress.documents // how many documents ...
progress.blobs // how many blobs
progress.on('update', function() {
// something has changed
})
var stream = require('stream')
var rs = new stream.Readable()
rs.push('hello')
rs.push('world')
rs._read = function() {}
var sameTick = true
rs.on('data', function() {