Skip to content

Instantly share code, notes, and snippets.

@abhi-bit
abhi-bit / script.js
Last active September 23, 2015 14:35
map function
function (doc, meta) {
if (meta.type != "json") return;
var stringToUtf8Bytes = function (str) {
var utf8 = unescape(encodeURIComponent(str));
var bytes = [];
for (var i = 0; i < str.length; ++i) {
bytes.push(str.charCodeAt(i));
}
{
"customer_contacts": "n/a",
"account_type": "n/a",
"name": "xyz",
"sales_rep": "abc@couchbase.com",
"note": "",
"customer_type": "customer",
"type": "customer",
"sla": "n/a"
}
{
"Virtual Host": {
"status": "INFO",
"description": "Xen 3.4.3.amazon (preserve-AD)"
},
"OS Name": {
"status": "INFO",
"description": "Linux 2.6.32-358.14.1.el6.x86_64"
},
"Installed CPUs": {
{
"name": "xyz_3",
"sdk_version": "n/a",
"cluster_id": "0095a9cfef8dc3ac1fe6de12affe5745",
"couchbase_version": "2.5.1-1083-rel-enterprise",
"node_count": "2 - Recommend at least 3 nodes",
"customer_id": "xyz",
"type": "cluster"
}
import urllib2
import json
import subprocess
import sys
def main():
cluster_ip = sys.argv[1]
bucket = sys.argv[2]
bucket_map_url = "http://" + cluster_ip + \
@abhi-bit
abhi-bit / wrapper.py
Created June 3, 2015 10:19
cbbackup wrapper to back up vbuckets in batches
import argparse
import gevent
from gevent.subprocess import Popen
vbucket_count = 1024
backup_script = "/opt/couchbase/bin/cbbackup"
parser = argparse.ArgumentParser(description="cbbackup wrapper to back up vbuckets in batches")
parser.add_argument('-b', action='store', dest='batch_size', type=int,
@abhi-bit
abhi-bit / http.rs
Last active August 29, 2015 14:20
Vanilla web server
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
use std::str;
use std::thread;
fn handle_client(mut stream: TcpStream) {
match stream.peer_addr() {
Err(_) => (),
Ok(pn) => println!("Received connection from: [{}]", pn),
}
@abhi-bit
abhi-bit / gethighscore.py
Last active August 29, 2015 14:18
Use Couchbase views to populate leaderboard
#!/usr/bin/env python
from couchbase import Couchbase
from couchbase import FMT_JSON
from couchbase.views.params import Query
from couchbase.views.iterator import View
import datetime
import json
from operator import itemgetter
import random
@abhi-bit
abhi-bit / syncCas.java
Created March 4, 2015 08:47
Sync cas
// Set test key to cluster
client.set("test-key", "couchbase!").get();
// Grab cas value
CASValue<Object> lock = client.gets("test-key");
long cas_id = lock.getCas();
client.cas("test-key", cas_id, "test-value");
System.out.println((String) client.get("test-key"));
import com.couchbase.client.CouchbaseClient;
//import net.spy.memcached.transcoders.SerializingTranscoder;
import java.util.Random;
import java.net.URI;
import java.util.*;
import java.lang.*;
import java.util.concurrent.TimeUnit;