Skip to content

Instantly share code, notes, and snippets.

View jchris's full-sized avatar

Chris Anderson jchris

View GitHub Profile

Have you taken a look at the offline capabilities CouchDB provides? I gave a tech talk at Google in 2009, about ground computing and the benefits of local data: http://googlecode.blogspot.com/2009/09/chris-anderson-couchdb-relaxing-offline.html

Couch is being ported to many new implementations. For instance the new PouchDB syncs with CouchDB, and is built on IndexedDB for browser JavaScript https://github.com/mikeal/pouchdb

Also for iOS there is the lightweight TouchDB, which also syncs with CouchDB and uses SQLite for storage: https://github.com/couchbaselabs/TouchDB-iOS

The essence of the idea is that your data set should be the same no matter where you are (like the cloud) but stored locally (like a desktop). The endgame for this application architecture is independent apps (run offline and installed like desktop apps) that connect to the cloud when they want to share data or they are interested in a continuous data feed.

@jchris
jchris / Test.js
Created September 10, 2012 18:48
var menu = cb.get("tonight"),
starters = cb.multiget(menu.starters),
mains = cb.multiget(menu.mains),
steak = cb.set("steak",{tags: ["paleo"]});
mains.push(steak);
cb.set(menu);
{
"name" :"Duck Soup",
"description" : "Water and duck, a natural combination.",
"ingredient_ids" :["da4e76f","cdc9630e"],
"tags" : ["game","soup","French"],
"cooks" : ["joe", "Martha"],
"chef" : "jchris"
}
<?php
// adjust these parameters to match your installation
$cb = new Couchbase("127.0.0.1:8091", "user", "pass", "default");
$cb->set("a", 1);
var_dump($cb->get("a"));
?>
<?php
$cb = new Couchbase("127.0.0.1:8091", "user", "pass", "default");
@jchris
jchris / examples.js
Created September 23, 2012 14:49
pretend code: launch the app, connects to couchbase, also some examples
var couchbase = require("couchbase"),
config = {
hosts : ["localhost:8091", "localhost:9000"],
bucket : "TapLibz",
password : "buzz-the-tower",
};
// would be neat to have default connection level
// options (place to set observe and expiration, etc)
@jchris
jchris / sync.js
Created October 27, 2012 17:44
sync with coap
var setup, outbox = [], relay = [], syncServers = [],
relayCap = 4, copyFactor = 1, defaultLeisure = 5000/*ms*/,
outboxInterval, relaysInterval, initInterval;
exports.log = function (json) {
if (!setup) {doInit();}
outbox.push([0, json]);
};
function setupTimers() {
@jchris
jchris / tests.log
Created October 31, 2012 21:38
running make check inside the node repository checkout
ether 14:15:26 ~/couchbase-sdks/node(work) jchrisa
make check
(cd tests && ./runtests.sh 0*.js)
00-args.t.js .. OK
01-set.js .. OK
assert.js:3657: Uncaught AssertionError: JSON values should be converted back to objects
assert.js:3657: Uncaught AssertionError: Unicode characters should round trip.
timeout, assuming failure
02-get.js .. FAIL
03-multiget.js .. OK
@jchris
jchris / sync.js
Last active December 14, 2015 05:28
Sync function runs validation and generates access() and channel() maps.
config.sync = function(doc, oldDoc, userCtx, secObj) {
if (doc.channel_id) {
// doc belongs to a channel
channel("ch-"+doc.channel_id);
// this document describes a channel
if (doc.channel_id == doc._id) {
// magic document, treat it carefully
if (oldDoc && oldDoc.owners.indexOf(userCtx.name) === -1) {
throw({unauthorized:"you are not a channel owner"});
}
./sync_gateway ~/code/CouchChat-iOS/sync-gateway-config.json
16:23:39.792740 Enabling logging: [CRUD REST+]
Sync Gateway starting with config settings:
{
"Interface": ":4984",
"AdminInterface": ":4985",
"Persona": {
"Origin": "http://animal.local:4984/"
},
"Log": [