Skip to content

Instantly share code, notes, and snippets.

@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 / 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,
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 + \
{
"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"
}
{
"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": {
{
"customer_contacts": "n/a",
"account_type": "n/a",
"name": "xyz",
"sales_rep": "[email protected]",
"note": "",
"customer_type": "customer",
"type": "customer",
"sla": "n/a"
}
@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));
}
@abhi-bit
abhi-bit / cb_set.py
Created September 24, 2015 08:24
set to cb using file from disk
import sys
import json
import random
import string
from couchbase import Couchbase
from couchbase import FMT_JSON
host = sys.argv[1]
bucket = sys.argv[2]
@abhi-bit
abhi-bit / regis_server.erl
Created December 14, 2015 09:19
ets simulation
-module(regis_server).
-behaviour(gen_server).
-include_lib("stdlib/include/ms_transform.hrl").
-export([start_link/0, stop/0, register/2, unregister/1, whereis/1,
get_names/0, lookup/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
code_change/3, terminate/2]).
start_link() ->
-on_load(init/0).
-module(merger).
-on_load(init/0).
-export([
new/0, new/1, new/2,
out/1,
in/3,
size/1,