Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
nolanlawson / get.js
Last active August 29, 2015 14:04
Simple "get"s and "put"s in PouchDB
pouch.get('some_doc_id').catch(function (err) {
if (err.name === 'not_found') {
return {}; // default doc
}
throw err;
}).then(function (doc) {
// do something with the doc
}).catch(function (err) {
// handle any errors
});
@nolanlawson
nolanlawson / lipsum.txt
Created August 12, 2014 16:31
lipsum.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ligula id mi ullamcorper congue vel vel quam. Nulla dapibus dignissim orci, ac elementum orci feugiat non. In lacinia nisl eu mollis varius. Etiam euismod scelerisque neque vitae luctus. Donec congue adipiscing nulla, vitae pellentesque tortor fringilla id. Cras eget posuere sapien, ut blandit elit. Nunc ut ligula eros. Aenean commodo at erat at tempor. Aliquam tortor diam, faucibus sit amet elementum eget, convallis nec urna. Phasellus aliquam lectus lectus, non tempus eros volutpat vitae. Proin faucibus dolor eu aliquet bibendum. Pellentesque vel sem ut eros lobortis ultricies. Integer non erat volutpat felis tincidunt dapibus. Quisque id malesuada dolor.
Praesent at risus nec est sodales vulputate id non lacus. Proin in odio luctus, fermentum nulla id, vulputate metus. Etiam pellentesque viverra pellentesque. Suspendisse porttitor, erat consequat elementum commodo, urna massa varius quam, a vehicula turpis justo et dui. Vivamus a vestibul
@nolanlawson
nolanlawson / pouch_and_couch.md
Last active August 29, 2015 14:05
pouch_and_couch.md

Guide to PouchDB

Introduction

What is PouchDB?

PouchDB is a JavaScript implementation of CouchDB. Its goal is to emulate every CouchDB API with near-perfect fidelity, running in the browser, in Node.js, or as a simple client to CouchDB.

@nolanlawson
nolanlawson / id_rsa.pub
Created August 16, 2014 18:28
Nolan Lawson's public key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjcpucwo5XlyQZKPSNUdfjKQ1mlrZG+Yxlu14G/50WMu3nu6H1Fc4wpQbzsnKWxrC69w1w+pGHiX3SnklJygEVfuOWlctu3lSk0S+hEoqRyEUEwFCTTLOK47HzHvkuFz0MPvsx7oQL49UUAPJwZlVdlEFKvDWdOQmBJk5IxTiJXRJZUwfF8YwX5V6Ta+ueSs64KQfjY1mS3ZIFe6V47BIU1rVjkEbkA9EDBFrMxT5HIubNFaCFwbQ/9wyOixDTPoYot1D7mKxwtymuChDxjt8d7TPwXGEqjxwBdANv2IYzUaRXN3lH2JVAJYGYWm4zlY0aML88vRfDKFJQUDnzK2O1 nolan.lawson@gmail.com
@nolanlawson
nolanlawson / recompile_assets.sh
Last active August 29, 2015 14:05
Recompile just the assets in an Android APK. Faster than `gradle installDebug` if you're just modifying HTML/CSS/JS.
#!/bin/bash
#
# Recompile Android assets into a -debug.apk. Assumes you have apktool
# installed and it's globally accessible as "apktool".
#
# Usage: ./recompile_assets.sh [path/to/debug.apk] [path/to/assets]
#
# If you don't include any arguments, it will try to determine the
# location of your assets/apk using the current working directory.
#
@nolanlawson
nolanlawson / touchdb_improvements.md
Last active August 29, 2015 14:05
Improvements to the TouchDB replication algorithm in PouchDB 3.0.2

Improvements to the TouchDB replication algorithm in PouchDB 3.0.2

Edit: we had to roll back this feature. It ended up introducing conflicts in PouchDB (#2685). The TouchDB implementation is still the fastest I'm aware of.

Up until PouchDB 3.0.x, our replication algorithm was largely the same as TouchDB's, as described here.

However, recently we have discovered an improvement to this algorithm, which results in a nearly 20x speedup, as measured by using the npm-browser project. Details are in these GitHub issues: #2472, #2475, and #2647.

Obviously this "20x" number will vary depending on latency and connection speed, but we're definitely in the "decimal order of magnitude" are

@nolanlawson
nolanlawson / bug.md
Created August 28, 2014 18:41
bugzilla report

file here: https://www.w3.org/Bugs/Public/

When reading from two objectStores, where one objectStore contains a field that's simply a foreign key to another objectStore, it would be useful to have a native method that could return a Cursor that iterates over both objectStores at once. I.e. this would be the equivalent of a "SELECT * FROM table1 JOIN table2 ON table1.foo=table2.bar" in the SQL world.

In working on PouchDB, we've had an opportunity to build parallel implementations of a CouchDB-like database backed by both WebSQL and IndexedDB. And it's come up frequently that our bulk-read operation is about a decimal order of magnitude faster in WebSQL than in IndexedDB [1]. This seems to be because in WebSQL we can take advantage of the native JOIN operation, whereas in IndexedDB we can't. (We maintain one objectStore for documents keyed by ID, and another one of documents keyed by the "seq" number, which is more-or-less the order they were inserted in the database. These two have to be merged before we c

@nolanlawson
nolanlawson / test.js
Created August 28, 2014 21:16
test.js
it('test concurrent allDocs', function () {
var db1 = new PouchDB(dbs.name);
var db2 = new PouchDB(dbs.name + '_2');
var promise = PouchDB.utils.Promise.resolve();
for (var i = 0; i < 25; i++) {
/* jshint loopfunc:true */
promise = promise.then(function () {
return db1.post({});
@nolanlawson
nolanlawson / index.html
Created September 3, 2014 15:56
Demonstrate an AJAX request for a blob URL of type image/png
<html>
<body>
<pre id="display"></pre>
<script src="//cdn.jsdelivr.net/pouchdb/3.0.3/pouchdb.js"></script>
<script>
(function () {
'use strict';
//
// main code starts here
@nolanlawson
nolanlawson / index.html
Last active August 29, 2015 14:06
Demonstrate an AJAX request for a blob URL of type image/png
<html>
<body>
<pre id="display"></pre>
<script src="pouchdb.js"></script>
<script src="index.js"></script>
</body>
</html>