Skip to content

Instantly share code, notes, and snippets.

View joehand's full-sized avatar
🌳
be like tree

Joe Hand joehand

🌳
be like tree
View GitHub Profile
@joehand
joehand / readme.md
Last active April 15, 2017 01:41
SLEEP - Hyperdrive v8 for Dat!

SLEEP

Syncable Lightweight Event Emitting Persistence

SLEEP metadata allow files to be accessed randomly, cryptographically verified, and dynamically updated. SLEEP files can be shared for easy distribution and we also specify a way to expose SLEEP over REST. The Dat project uses SLEEP to distribute data over decentralized networks securely.

Docs in progress

Our docs page on SLEEP and in progress whitepaper have a more in depth look at SLEEP, but does not reflect the recent v8 release changes. We're in the process of updating the docs.

@joehand
joehand / dat-bags.md
Last active June 10, 2017 18:35
bagit + dat thinking

There can be two versions of a Dat Bag:

  1. "Holey" Bag - meant for archviving of metadata at specific Dat archive version.
  2. Complete Bag - a complete backup of an archive checkpoint.
  3. Serialized Bag - this would be for bag with Dat without having Dat stuff inside the bag

Holey Dat Bag:

A "Holey" bag contains a fetch.txt file which points to where to download the rest of the data if file is not in data/ payload.

@joehand
joehand / storage.js
Last active March 24, 2017 20:34
Secret Key Storage
var fs = require('fs')
var path = require('path')
var toilet = require('toiletdb')
var homedir = require('os-homedir')
var raf = require('random-access-file')
var thunky = require('thunky')
var debug = require('debug')('dat-node')
module.exports = function (dir) {
// Stores secret key in ~/.dat/<pub-key>-key.json
@joehand
joehand / metadata-datasets.js
Last active March 20, 2017 17:32
opendata.arcgis metadata & download scripts
var paginationStream = require('pagination-stream')
var JSONStream = require('JSONstream')
var ndjson = require('ndjson')
var pump = require('pump')
var fs = require('fs')
var path = require('path')
// Downloads opendata.arcgis.com/datasets.json
// Metadata is arcgis api?
@joehand
joehand / guesskey.js
Created January 19, 2017 19:11
Guessing Archive Keys
function checkDriveKeys () {
drive.core.list(function (err, vals) {
if (err) return cb(err)
if (vals.length > 2 && !opts.key) return cb(new Error('Drive has multiple archives. Must specify key.'))
else if (!vals.length || opts.key) {
// make new archive or use opts.key
archive = drive.createArchive(opts.key, opts)
return done()
}
debug(`Drive has ${vals.length} existing keys. Getting archive key.`)
{"url":"dat://<dat-link>", "directory": "/server/15122016/", "date":"2016-12-16"}
{"url":"dat://<dat-link-twoo>", "directory": "/server/15122016/", "date":"tomorrow"}
{"url":"dat://<dat-link-three>", "directory": "/server/15122016/", "date":"next day"}
{"url":"dat://<dat-link-etc>", "directory": "/server/15122016/", "date":"etc"}
// This file would be in a folder shared over Dat.
// Each Dat you could add a row and that will automatically get synced to your local archive
@joehand
joehand / server.js
Last active December 2, 2016 23:21
township server
var http = require('http')
var memdb = require('memdb')
var appa = require('appa')
var township = require('township')
module.exports = function (cb) {
var creds = {
host: 'http://127.0.0.1',
port: 9966,
requiredScopes: {
var hyperdrive = require('hyperdrive')
var level = require('level')
var raf = require('random-access-file')
var db = level('db')
var drive = hyperdrive(db)
db.get('key', function (err, val) {
if (!val) return createArchive()
readArchive(val)
var Swarm = require('discovery-swarm')
var swarmDefaults = require('datland-swarm-defaults')
module.exports = function (archive, opts) {
opts.discovery = {upload: true, download: true}
var swarm = Swarm(swarmDefaults({
id: archive.id,
hash: false,
utp: opts.utp,
function DatFs (opts) {
if (!(this instanceof DatFs)) return new DatFs(opts)
if (!opts) opts = {}
Dat.call(this, opts)
}
inherits(DatFs, Dat)