Skip to content

Instantly share code, notes, and snippets.

@mnunberg
mnunberg / parse-git-describe.c
Last active August 29, 2015 13:56
Parse 'git describe' output
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
static void find_delim(char *s, char **res, int *ix)
{
for(; *ix && s[*ix] != '-'; *ix -= 1);
if (*ix) {
s[*ix] = '\0';
*res = s + *ix + 1;
@mnunberg
mnunberg / urldemo.py
Created February 7, 2014 21:05
Manually getting a view result via the Python SDK
#!/usr/bin/env python
from random import choice
import requests
from couchbase import Couchbase
from couchbase.views.params import Query
cb = Couchbase.connect(bucket='beer-sample')
node = choice(cb.server_nodes).replace("8091", "8092")
q = Query()
@mnunberg
mnunberg / lcb-doc.md
Last active August 29, 2015 13:56
lcb docs

// vim: set noexpandtab:

libcouchbase - The C Couchbase Client Library

The C library provides an interface to the Couchbase Cluster from a C application. It is used by many of our client libraries as lower layer which performs network I/O and protocol handling. It may also be used as a standalone client.

The library is known to function on Linux, Mac OS X and Windows. Other platforms may be work but are not routinely tested.

#include "readbuf.h"
struct my_bufinfo {
slist_node slnode; /** Node in send queue */
char *buf; /** Buffer for current segment */
size_t nbuf; /** Size of buffer */
size_t offset; /** Offset of buffer */
rdb_SEGMENT *segment; /** Segment for buffer */
};
#!/usr/bin/perl
use strict;
use warnings;
### Repositories:
my $REPOS = {
RPM => {
5 => {
'32bit' => "http://packages.couchbase.com/rpm/5.5/i386",
@mnunberg
mnunberg / lcb-boost-asio.cpp
Created November 16, 2014 23:22
lcb+boost
#include <string>
#include <vector>
#include <array>
#include <boost/asio.hpp>
#include <boost/chrono.hpp>
#include <libcouchbase/couchbase.h>
#include <libcouchbase/iops.h>
using std::string;
using std::vector;
@mnunberg
mnunberg / errhandling.md
Last active August 29, 2015 14:10
LCB Error handling

Library Internals: How the library deals with errors

This document is intended to be informative and not authoritative. The library may change its internal behavior regarding error handling without notice.

This document describes how the library internally deals with errors, so that you can get a better idea of what may be happening when debugging various issues.

Error Types

@mnunberg
mnunberg / lcb-connmgmt.md
Last active August 29, 2015 14:14
libcouchbase Connection Management

Connection Management in libcouchbase

This document explains how the library handles TCP connections internally. This will cover both HTTP and Memcached connections

Memcached Sockets

Bootstrapping

During initial bootstrap, the library effectively loops over the list of hosts twice,

@mnunberg
mnunberg / beer-sample.c
Created February 19, 2015 21:45
lcb-views-beer-sample
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <libcouchbase/couchbase.h>
#include <libcouchbase/views.h>
#define CONNSTR "couchbase://localhost:12000/beer-sample"
static void rowCallback(lcb_t instance, int cbtype, const lcb_RESPVIEWQUERY *resp) {
if (! (resp->rflags & LCB_RESP_F_FINAL)) {
@mnunberg
mnunberg / ryow.py
Last active August 29, 2015 14:18
N1QL Read-Your-Writes with Python 2.0
#!/usr/bin/env python
"""
Connect to a Couchbase 4.0 cluster and issue a N1QL query.
Note that primary index creation will fail.
"""
import sys
from time import time
from pprint import pprint
from couchbase.bucket import Bucket