WOW! WatchJS became so popular that I've been pushed to migrate it to GitHub
https://github.com/melanke/Watch.JS
Just kidding
WOW! WatchJS became so popular that I've been pushed to migrate it to GitHub
https://github.com/melanke/Watch.JS
Just kidding
Your API does REST, but can it SLEEP?
SLEEP (Syncable Lightweight Event Emitting Persistence) is an emerging standard for distributed data sync using HTTP and JSON. A generalized version of CouchDB's much lauded built-in replication, SLEEP extends the REST architecture to define a way in which databases can offer syncable JSON APIs that foster open data innovation by allowing developers to replicate entire databases over the net.
SLEEP comes from the Apache CouchDB project which is now widely known for it's multi-master streaming HTTP + JSON replication. This is possible in part because of the CouchDB _changes feed, which is a particular API that lets you see if there have been any changes made to the database since last time you synchronized. CouchDB can efficiently implement the _changes feed because of one subtle difference between it and most other databases: it stores a history of all changes that happen to the database, including deletes.
If you synchronize data from a remote source and then the
| #!/usr/bin/env python | |
| import sys | |
| import couchdb | |
| if __name__ == '__main__': | |
| srcurl, desturl = sys.argv[1:] |
| // 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() { |
| To use the two-layer cache: | |
| * Run memcached on each Django webserver | |
| * Add "LOCAL_CACHE_ADDR = ('127.0.0.1:11211',)" to settings.py | |
| * Replace "from django.core.cache import cache" with "from dualcache import cache" everywhere | |
| you want to use the two-layer cache. It can be freely mix and matched with Django's default caching. |
| #!/bin/sh | |
| # Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the | |
| # CREATE block and create them in separate commands _after_ all the INSERTs. | |
| # Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk. | |
| # The mysqldump file is traversed only once. | |
| # Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite | |
| # Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite |
| RDBMS schema safety tips & common practices... | |
| - define primary keys, even if artificial | |
| - normalize your schema, and denormalize carefully | |
| - use indexes judiciously | |
| - distributed 2PC is a tool best left in the toolbox | |
| - __many more known relational schema and modeling tips & tricks go here, but too lazy to type__ | |
| Document database / couchdb "schema" safety tips & common practices... |
| #!/usr/bin/env python | |
| """Store messages in a Maildir into a couchdb database.""" | |
| import couchdb | |
| from mailbox import Maildir | |
| from optparse import OptionParser | |
| import os | |
| from pprint import pprint | |
| import sys | |
| from uuid import uuid4 |
CRUD requires jquery.deepjson.js to work so it should be included
<script type="text/javascript" src="js/jquery.deepjson.js"></script>
Then you can assign whatever's in crud.json to a variable or you can put crud.json into your evently directory and let couchapp push it to your application.
Simplest way to use it is
| //Changes filter: "conflicts": "function(doc, req) { if(doc._conflicts) { return true; } else { return false; }}" | |
| var dbase = 'focus'; | |
| var ddoc = 'app'; | |
| var sys = require('sys'), | |
| couchdb = require('node-couchdb/lib/couchdb'), | |
| client = couchdb.createClient(5984, 'crate.im'), | |
| db = client.db(dbase), | |
| changes = db.changesStream({filter: ddoc + '/conflicts'}); |