Skip to content

Instantly share code, notes, and snippets.

🕉
I don't know

Julian Gruber juliangruber

🕉
I don't know
Block or report user

Report or block juliangruber

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
View oops2.js
const fs = require('fs')
const hyperdrive = require('hyperdrive')
const src = `/tmp/${Math.random()}/`
console.log(src)
const storage = require('dat-storage')(src)
const archive = hyperdrive(storage, { latest: true, indexing: true })
archive.writeFile('/dat.json', 'hi', err => {
if (err) throw err
View oops.js
const fs = require('fs')
const src = `/tmp/${Math.random()}`
Dat(src, (err, dat) => {
if (err) throw err
dat.archive.writeFile('/dat.json', 'hi', err => {
if (err) throw err
console.log(fs.readFileSync(`${src}/dat.json`)) // => empty
dat.archive.readFile('/dat.json', (err, data) => {
@juliangruber
juliangruber / 01-results.md
Last active Jan 15, 2018
benchmark: pull-stream vs async-stream
View 01-results.md
$ node bench-01-pull-stream.js
pull3*100000: 1995.798ms
pull_compose*100000: 1968.901ms
pull_chain*100000: 1871.930ms

$ node bench-02-async-stream.js
async3*100000: 3295.666ms
async3*100000: 3145.636ms
async3*100000: 2943.988ms
View async-heap.js
// https://github.com/juliangruber/async-stream
function heap (name, Stream) {
var start = Date.now()
var heap = process.memoryUsage().heapUsed
var a = [], N = 100000
for(var i = 0; i < N; i++)
a.push(Stream())
console.log(name, (process.memoryUsage().heapUsed - heap)/N, (Date.now()-start))
a = null
View gist:fe383095909a9e237c11a5318262920b
const writeToRemote = new PassThrough()
reconnect(async con => {
await sendState(con)
writeToRemote.pipe(con)
}).on('disconnect', () => {
writeToRemote.unpipe()
})
theRestOfYourProgram.pipe(writeToRemote)
View random-access-directory.js
var rad = require('random-access-directory')
var store = rad(procss.env.HOME + '/.dat/')
// create a first store
store = store('hypercore.txt')
store.get(0, ...)
// create another store, based on the first one
// this way modules can pass the store instance
View hypercore-index.js
index(feed, {
start: 0,
end: Infinity,
key: feed.key
}, function onentry (entry, cb) {
cb()
}, function ondone () {
View interactive-execution.js
const http = require('http')
http.createServer((req, res) => {
res.write('<!DOCTYPE html><html><head><title>electron-stream</title><script>')
res.write('console.log("hi");\n')
setTimeout(() => {
res.write('console.log("you");\n')
res.end('</script></head></html>')
}, 3000)
}).listen(8000, () => console.log('8000'))
View pkg.js
{ name: 'sillytest',
time:
{ modified: '2016-08-12T20:24:05.671Z',
created: '2016-04-04T16:39:05.573Z',
'1.0.0': '2016-04-04T16:39:05.573Z',
'1.0.1': '2016-04-04T16:42:05.213Z',
'1.0.2': '2016-04-04T16:42:24.049Z',
'1.0.3': '2016-04-04T16:42:52.291Z',
'0.0.1': '2016-08-12T20:19:52.345Z',
'0.0.2': '2016-08-12T20:20:08.997Z',
@juliangruber
juliangruber / render.js
Last active Jun 13, 2016
yo-yo + es6 = ❤️
View render.js
const yo = require('yo-yo')
module.exports = entries => yo`
<ul>
${entries.map(entry => yo`
<li>${entry.name}</li>
`)}
</ul>`
You can’t perform that action at this time.