Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
package main
import (
"fmt"
"github.com/couchbaselabs/go-couchbase"
"log"
)
func main() {
c, err := couchbase.Connect("http://localhost:8091")
@sideshowcoder
sideshowcoder / all_teams_view.json
Created April 11, 2014 12:45
Setting up couchbase views programmatically via Rak
{
"_id": "_design/teams",
"language": "javascript",
"views": {
"all": {
"map": "function(doc, meta){ if(doc.type === 'team'){ emit(meta.id, null); } }"
}
}
}
@sideshowcoder
sideshowcoder / uniq_acct_numbers.rb
Created April 14, 2014 10:36
Unique account numbers via view in couchbase
# Get a number of unique account numbers via a map / reduce view
#
# foobar bucket contains:
#
# A = {"acct":"123456","name":"John Smith"}
# B = {"acct":"123456","name":"John Smith"}
# C = {"acct":"123457","name":"Jane Doe"}
#
# map:
#
@sideshowcoder
sideshowcoder / cb-test.php
Created May 6, 2014 11:19
Couchbase PHP test
<?php
$cb = new Couchbase("127.0.0.1:8091", "", "", "default");
$cb->set("foo", "bar");
var_dump("foo");
@sideshowcoder
sideshowcoder / php.ini
Created May 6, 2014 13:42
Couchbase lib in PHP.ini
....
;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;Couchbase
extension=php_couchbase.dll
def database
return @database if @database
manager = CBLManager.sharedInstance
error_ptr = Pointer.new(:object)
@database = manager.databaseNamed("todos", error: error_ptr)
unless @database
error = error_ptr[0]
alert = UIAlertView.alloc.initWithTitle("Local Database Error",
message:"No access to local database. #{error}",
def authenticate &block
account_store = ACAccountStore.alloc.init
fb_account_type = account_store.accountTypeWithAccountTypeIdentifier( ACAccountTypeIdentifierFacebook)
facebook_options = {}
facebook_options[ACFacebookAppIdKey] = @application_id
facebook_options[ACFacebookPermissionsKey] = ["email"]
account_store.requestAccessToAccountsWithType(fb_account_type, options:facebook_options, completion: lambda do |granted, error|
if granted
accounts = account_store.accountsWithAccountType(fb_account_type)
def start_replication
@pull = @database.createPullReplication(sync_url)
@pull.continuous = true
@push = @database.createPushReplication(sync_url)
@push.continuous = true
listen_for_replication_events @pull
listen_for_replication_events @push
@sideshowcoder
sideshowcoder / item.rb
Created June 9, 2014 11:02
Getting data into CouchbaseLite via Ruby
class Item < CBLModel
attr_reader :created_at
def self.docType
"item"
end
def initInDatabase database, withTitle: title
self.initWithNewDocumentInDatabase database
self.setValue(self.class.docType, ofProperty: "type")
def create_item title
list = Item.alloc.initInDatabase(database, withTitle:title)
error_ptr = Pointer.new(:object)
list.save(error_ptr)
if error_ptr[0]
alert = UIAlertView.alloc.initWithTitle("Error", message: "Failed to create new item", delegate: nil, cancelButtonTitle: "Ok", otherButtonTitles: nil)
alert.show
else
list
end