Skip to content

Instantly share code, notes, and snippets.

View Chippiewill's full-sized avatar
🤠

Will Gardner Chippiewill

🤠
View GitHub Profile
@Chippiewill
Chippiewill / bigram.c
Last active January 3, 2016 14:18
n-gram analysis
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 2
static const char ALPHABET[] = "abcdefghijklmnopqrstuvwxyz";
unsigned result[sizeof(ALPHABET) / sizeof(ALPHABET[0]) - 1][sizeof(ALPHABET) / sizeof(ALPHABET[0]) - 1];

Couchbase Binary Protocol

Introduction

Couchbase is a high performance NoSQL document store that has evolved from the combination of Memcached and CouchDB. The Couchbase binary protocol is based off of the Memcached binary protocol.

This document has been adapted from the Memcached 'Binary Protocol Revamped' document and may make reference to parts of the protocol not implemented by Couchbase Server.

class SetHashTable:
def add_key(set, key, value):
# Adds a key to the set, creates if doesn't exist
def get_set(set):
# Gets all the keys/values in the set
import os
from subprocess import call
import sys
import time
if len(sys.argv) > 2 and sys.argv[2] == "cbstats":
def get_stats():
out = os.popen("/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbstats {} all -b {}".format(sys.argv[1], sys.argv[2])).read()
ret = []
for row in out.split("\n"):
@Chippiewill
Chippiewill / fast_literal_compare.cc
Created October 7, 2016 13:45
Example code for performing fast comparison against string literals in C++
#include <cstring>
#include <iostream>
#include <string>
template <size_t N>
bool compare(const char* s, size_t n, const char(&data)[N]) {
// Subtract 1 from N to remove null-termination
if (n != (N - 1)) {
return false;
}
diff --git a/include/memcached/engine_error.h b/include/memcached/engine_error.h
index fafcb44..e97003c 100644
--- a/include/memcached/engine_error.h
+++ b/include/memcached/engine_error.h
@@ -93,6 +93,10 @@ public:
: system_error(int(ev), engine_error_category(), what_arg) {}
};
+static inline std::error_condition make_error_condition(cb::engine_errc e) NOEXCEPT {
+ return std::error_condition(int(e), cb::engine_error_category());
diff --git a/engines/utilities/engine_error.cc b/engines/utilities/engine_error.cc
index 7fc1f63..e16d299 100644
--- a/engines/utilities/engine_error.cc
+++ b/engines/utilities/engine_error.cc
@@ -63,6 +63,11 @@ public:
return iter->second;
}
}
+
+ std::error_condition default_error_condition(int code) const NOEXCEPT override {
namespace cb {
/**
* Intrusive map generates the key for the map based on the mapped
* value and a KeyFunc supplied as a template parameter.
*/
template <class KeyFunc,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
@Chippiewill
Chippiewill / unique_lock_ref.cc
Created February 15, 2017 23:05
unique_lock_ref
#include <iostream>
#include <mutex>
template <typename mutex>
struct unique_lock_ref {
unique_lock_ref(const std::unique_lock<mutex>& lh) {
if (!lh) {
throw std::logic_error("Cannot instantiate a unique_lock_ref "
"with an unlocked unique_lock");
}
@Chippiewill
Chippiewill / md5.cc
Created February 23, 2017 09:15
md5 hls
/*
* Simple MD5 implementation
*
* Compile with: gcc -o md5 md5.c
*/
#include <stdlib.h>
#include <string.h>
#include "md5.h"