Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
nolanlawson / index.html
Last active Aug 26, 2015
Basic PouchDB authentication test site
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="./mocha.css" />
<script src="./mocha.js"></script>
<script>
mocha.setup('bdd');
</script>
@nolanlawson
nolanlawson / test.md
Last active Aug 28, 2015
Test results
View test.md
  • MacBook Pro (Retina, 15-inch, Late 2013)
  • Yosemite 10.10.5
  • basic-updates 200 iterations
  • 243758c51f6ee906af0d4821fe891577058cab6b vs 4.0.0

safari 9.0

before: 24867ms after: 17232ms

@nolanlawson
nolanlawson / xhr_obfuscation.md
Created Feb 7, 2014
XHR obfuscation for web games
View xhr_obfuscation.md

XHR obfuscation for web games

This is just a Gist to remind myself to start implementing this at some point. This would be a cool library.

@nolanlawson
nolanlawson / tests.broken.js
Created Feb 11, 2014
Deliberately broken test.basics.js test
View tests.broken.js
it('update_seq persists', function(start) {
var name = testHelpers.name;
testUtils.initTestDB(name, function(err, db) {
db.post({test:"somestuff"}, function (err, info) {
new PouchDB(name, function(err, db) {
db.info(function(err, info) {
equal(info.doc_count, 2, 'Doc Count persists'); // should be 1
start();
});
});
View print_pouchdb_size.py
#!/usr/bin/env python
#
# Prints the pouchdb.min.js and gzipped file sizes for
# all PouchDB builds in the past several months.
#
import requests, zlib
def main():
print 'Commit','GitHub link','Date','pouchdb.min.js size','gzipped size'
@nolanlawson
nolanlawson / size_diffs.md
Last active Aug 29, 2015
Top 20 most size-increasing and size-reducing pouchdb commits
View size_diffs.md
@nolanlawson
nolanlawson / inconsistent_results_couchdb_reduce_error.js
Created Apr 10, 2014
inconsistent_results_couchdb_reduce_error.js
View inconsistent_results_couchdb_reduce_error.js
it('should handle user errors in reduce functions', function () {
return new Pouch(dbName).then(function (db) {
function getKey(row) {return row.key; }
db.on('error', function () { /* noop */ });
return createView(db, {
map : function (doc) {
emit(doc.name, doc.data);
},
reduce : function (keys, values) {
return values[0].foo.bar;
@nolanlawson
nolanlawson / pouchdb_index_api.md
Last active Aug 29, 2015
PouchDB 2.3.0 index API proposal
View pouchdb_index_api.md

PouchDB 2.3.0 index API proposal

Wherein we hack up our dream map/reduce API, slated to be introduced in PouchDB 2.3.0.

Basic

new PouchDB('mydb', {indexes: ['title']});
View ascript.js
var start = document.getElementById('start');
var stuff = document.getElementById('stuff');
var remote = new PouchDB('http://registry.npmjs.org/', {cache: true});
var local = new PouchDB('npm');
start.addEventListener('click', function (){
remote.info().then(function (a) {
return a.doc_count;
}).then(function (count) {
remote.replicate.to(local, {
batch_size: 100
View websql_example.js
openDatabase('mydatabase', 1, 'mydatabase', 5000000, function (db) {
function onTransactionSuccess() {
console.log('yay, transaction succeeded!');
}
function onTransactionError() {
console.log('boo, transaction failed!');
}
db.transaction(function (tx) {