Skip to content

Instantly share code, notes, and snippets.

View tleyden's full-sized avatar

Traun Leyden tleyden

View GitHub Profile
@tleyden
tleyden / gist:8063905
Created December 21, 2013 00:42
satoshidb
package satoshidb
import (
"appengine"
"appengine/taskqueue"
"appengine/urlfetch"
"fmt"
"io/ioutil"
"net/http"
"net/url"
func NewBoard(compactBoard string) Board {
var board Board
name := "boardlexer"
_, tokensChannel := lex(name, compactBoard)
i := 0
for token := range tokensChannel {
@tleyden
tleyden / gist:8547657
Created January 21, 2014 20:24
cbl-android-async

Concurrency Support

The Couchbase Lite API is mostly synchronous. That makes it simpler and more efficient. Most of the API calls are quick enough that it's not a problem to run them on the main thread, but some things might become too slow, especially with large databases, so you might want to offload the processing to a background thread. You have a couple of options.

Asynchronous Queries

View queries slow down as the database grows, especially when the view's index needs to be updated after the database changes. You can prevent this from blocking your UI by running the query asynchronously.

The easiest way to do this is just to use LiveQuery. It always runs its queries in the background, and then posts a notification on the main thread after the query is complete.

build.gradle:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile project(':libraries:stubworld-corelib-sqlite4java')
compile project(':libraries:stubworld-corelib-android') {
exclude module: ':libraries:stubworld-corelib-android:libraries:stubworld-corelib-java'
}
}
@tleyden
tleyden / gist:8789472
Created February 3, 2014 18:27
json struct
type Generation struct {
start_time string
number int
state string
agents []Agent
games []Game
}
type GenerationJson struct {
Start_time string
@tleyden
tleyden / gist:9215525
Created February 25, 2014 19:12
couchbase-lite-android-ektorp tree
.
├── LICENSE.TXT
├── README.md
├── build
│   ├── bundles
│   │   ├── debug
│   │   │   ├── AndroidManifest.xml
│   │   │   ├── R.txt
│   │   │   ├── assets
│   │   │   ├── classes.jar
@tleyden
tleyden / gist:9215548
Created February 25, 2014 19:14
couchbase-lite-android-ektorp tree -L 4
.
├── LICENSE.TXT
├── README.md
├── build
│   ├── bundles
│   │   ├── debug
│   │   │   ├── AndroidManifest.xml
│   │   │   ├── R.txt
│   │   │   ├── assets
│   │   │   ├── classes.jar
@tleyden
tleyden / gist:9821497
Created March 27, 2014 23:29
Sync gateway crash checkers bot
6:23:14.302215 HTTP: #013: POST /checkers/_bulk_docs
16:23:14.302536 HTTP: #014: GET /checkers/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=91542&limit=100&filter=sync_gateway/bychannel&channels=game
16:23:14.308464 HTTP: #015: GET /checkers/user:076D9356-0711-44AC-8B8A-55748924E326 (ADMIN)
16:23:14.313421 HTTP: #016: GET /checkers/_changes?feed=longpoll&timeout=20000&since=91543 (ADMIN)
16:23:14.801578 HTTP: #017: GET /checkers/votes:checkers?rev=26339-b1875efcffceb3a693f00c90bb516a64&revs=true&attachments=true
16:23:14.801591 HTTP: #018: GET /checkers/game:checkers?rev=34360-1e2f438a9929a44c79fc49fc688ae969&revs=true&attachments=true
16:23:19.714674 HTTP: #019: PUT /checkers/_local/05b1d7a52d341f2e62c34fd4b085d232936b01fd
16:23:20.871836 HTTP: #020: PUT /checkers/_local/87e4a2d5a2b33f8bd97802038665255c9d7f521b
16:23:26.054957 HTTP: #021: POST /checkers/_revs_diff
16:23:26.091196 HTTP: #022: POST /checkers/_bulk_docs
@tleyden
tleyden / gist:11147841
Created April 21, 2014 16:27
sync gateway local config
{
"log": ["CRUD+", "REST+", "Changes+", "Attach+"],
"facebook" : {
"register" : true
},
"databases": {
"db": {
"server": "walrus:data",
"sync": `
function(doc){
@tleyden
tleyden / gist:11148026
Created April 21, 2014 16:33
sync gateway doc
hornet: ~$ http localhost:4984/grocery-sync/_all_docs
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 157
Content-Type: application/json
Date: Mon, 21 Apr 2014 16:32:30 GMT
Server: Couchbase Sync Gateway/0.94
{
"rows": [