Skip to content

Instantly share code, notes, and snippets.

View jchris's full-sized avatar

Chris Anderson jchris

View GitHub Profile
@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 / 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)
<?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");
{
"name" :"Duck Soup",
"description" : "Water and duck, a natural combination.",
"ingredient_ids" :["da4e76f","cdc9630e"],
"tags" : ["game","soup","French"],
"cooks" : ["joe", "Martha"],
"chef" : "jchris"
}
@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);

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.

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to process 44141.
2011-09-24 15:04:57.694 daz[44141:f803] Registering custom .ini file /Users/jchrisa/Library/Application Support/iPhone Simulator/5.0/Applications/696D756A-2862-4778-A48A-E63A9E7FDAF8/daz.app/app.ini
2011-09-24 15:04:57.697 daz[44141:f803] Couchbase: Starting CouchDB, using runtime files at: /Users/jchrisa/Library/Application Support/iPhone Simulator/5.0/Applications/696D756A-2862-4778-A48A-E63A9E7FDAF8/daz.app/CouchbaseResources (built Sep 21 2011, 14:55:44)
Eshell V5.8 (abort with ^G)
@jchris
jchris / not_in_svn.rb
Created July 22, 2011 01:54
you want to know the commits that never made it into svn
# usage:
# git log | ruby not_in_svn.rb | less
# license: Apache 2.0
# copyright: J Chris Anderson 2011
# this might be too trivial to copyright
def print_if_no_match buffer, regex
text = buffer.join("\n")
unless text.match(regex)
puts text
@jchris
jchris / jquery.couchLogin.js
Created May 9, 2011 22:48
jQuery plugin for CouchDB login/signup/logout in 80 lines (2kb minified)
// Copyright Chris Anderson 2011
// Apache 2.0 License
// jquery.couchLogin.js requires jquery.couch.js
//
// Example Usage (loggedIn and loggedOut callbacks are optional):
// $("#mylogindiv").couchLogin({
// loggedIn : function(userCtx) {
// alert("hello "+userCtx.name);
// },
// loggedOut : function() {
@jchris
jchris / index.html
Created April 27, 2011 16:54
jQuery CouchDB Hello World - to use this script, create the map view in futon and click Save As, then upload index.html as an attachment to _design document created with the view. browse to index.html to run the app.
<!DOCTYPE html>
<html>
<head><title>Tiny CouchApp</title></head>
<body>
<h1>Tiny CouchApp</h1>
<form id="new_message">
<label for="message">Message:</label>
<input type="text" name="message" value="">
<p><input type="submit" value="Save &rarr;"></p>
</form>