Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
@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
@sideshowcoder
sideshowcoder / item_view_controller.rb
Created June 9, 2014 11:19
Couchbase as a table view data source
class ItemsViewController < UIViewController
attr_accessor :database, :user_id, :data_source
def viewDidLoad
super
navigationItem.title = "Items"
@items_table = UITableView.alloc.initWithFrame(view.bounds)
@items_table.delegate = self
@data_source = CBLUITableSource.alloc.init
#import "Blocks.h"
#import <CouchbaseLite/CouchbaseLite.h>
@implementation Blocks
+(void)setupListsMapBlockForView:(CBLView*)view
{
if (!view.mapBlock) {
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:@"list"])
@sideshowcoder
sideshowcoder / erl
Last active June 4, 2020 12:20
debug erlang nif code with lldb
#!/bin/sh
#
# %CopyrightBegin%
#
# Copyright Ericsson AB 1996-2012. All Rights Reserved.
#
# The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
# compliance with the License. You should have received a copy of the
# Erlang Public License along with this software. If not, it can be
@sideshowcoder
sideshowcoder / .jshintrc
Created June 30, 2014 16:10
Couchbase views jshintrc
{
"-W025": false
}
var cb = require("couchbase")
var async = require("async")
var cluster = new cb.Cluster("couchbase://localhost/")
var bucket = cluster.openBucket("default")
bucket.queryhosts = ["localhost:8093"]
var log = function () {
var args = Array.prototype.slice.call(arguments, 0)
console.log.apply(null, args.filter(function (e) { return e != null }))
@sideshowcoder
sideshowcoder / index.js
Created July 11, 2014 13:51
Couchbase View Query example key prefix matching
var couchbase = require("couchbase")
var async = require("async")
var bucket = new couchbase.Connection({})
function die(msg) {
if(msg) console.log(msg)
bucket.shutdown()
process.exit()
}
@sideshowcoder
sideshowcoder / 1000_docs.erl
Created September 2, 2014 16:09
Creating a 1000 documents in Couchbase via Erlang oneliner
[cberl:set(default, list_to_binary(X), 0, {[{<<"type">>,<<"bar">>}]}) || X <- [lists:flatten(io_lib:format("bar-~p", [X])) || X <- lists:seq(4, 10000)]].
@sideshowcoder
sideshowcoder / batch_insert.js
Last active September 1, 2017 12:14
Mass insert documents in Couchbase
var couchbase = require("couchbase")
var async = require("async")
var db = new couchbase.Connection({})
// create insert function which expects just a callback
function insertFormObject(object) {
return function (cb) {
db.set(object._id, object.value, cb)
}