Skip to content

Instantly share code, notes, and snippets.

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
index(feed, {
start: 0,
end: Infinity,
key: feed.key
}, function onentry (entry, cb) {
cb()
}, function ondone () {
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'))
{ 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 June 13, 2016 12:08
yo-yo + es6 = ❤️
const yo = require('yo-yo')
module.exports = entries => yo`
<ul>
${entries.map(entry => yo`
<li>${entry.name}</li>
`)}
</ul>`
@juliangruber
juliangruber / extend.plist
Created May 30, 2016 20:30
Here is how to accept custom protocol links like dat://LINK in an @electronjs app, in osx. For this to work you need to properly package the app into a `.app`, and place the CFBundleURLTypes spec into it's Info.plist. Then, move the app into another directory using Finder (!). Here we're using electron-packager.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Dat Link</string>
<key>CFBundleURLSchemes</key>
<array>
<string>dat</string>
</array>
</dict>
@juliangruber
juliangruber / extend.plist
Last active August 23, 2020 18:48
Here is how to accept files dropped on an @electronjs app's icon in osx. For this to work you need to properly package the app into a `.app`, and to place the CFBundleDocumentTypes spec into it's Info.plist. Here we're using electron-packager.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>All Files</string>
<key>LSHandlerRank</key>
@juliangruber
juliangruber / index.js
Last active October 12, 2015 19:00
requirebin sketch
var fill = require('fill-colorcoded-bar');
var Bar = require('colorcoded-bar');
var raf = require('raf');
var data = [];
for (var i = 0; i < 1000; i++) data[i] = Math.random();
(function(){
var el = document.createElement('canvas');
document.body.appendChild(el);
@juliangruber
juliangruber / index.js
Last active October 8, 2015 06:25
requirebin sketch
var Bar = require('colorcoded-bar');
var insertCSS = require('insert-css');
// Vertical bar
(function(){
var bar = new Bar();
for (var i = 0; i < 100; i++) {
bar.set(i, 'rgba(1, 1, 1, ' + i / 100 + ')');
}