Skip to content

Instantly share code, notes, and snippets.

View ingenthr's full-sized avatar

Matt Ingenthron ingenthr

View GitHub Profile
/**
* Copyright (C) 2009-2013 Couchbase, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@ingenthr
ingenthr / Main.java
Last active December 28, 2015 06:59
A quick test to determine the number of threads created by a CouchbaseClient.
package com.couchbase.client.demo;
import com.couchbase.client.CouchbaseClient;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ingenthr
ingenthr / update user.py
Created January 15, 2014 02:01
to get syntax highlighting for a screenshot
""" Retrieve the user to change the email address """
user = cb.get("ingenthr")
""" Change the email and store the user """
user.value['email'] = "ingenthr@couchbase.com"
cb.set(user.key, user.value, cas=user.cas) # concurrent safe!
@ingenthr
ingenthr / NetJsonTranscoder.java
Created October 2, 2014 00:23
Sample of reading .NET JSON from Java with Couchbase
/**
* Copyright (C) 2014 Couchbase, Inc.
* Copyright (C) 2006-2009 Dustin Sallings
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@ingenthr
ingenthr / _README.md
Last active September 16, 2015 12:58 — forked from brett19/_README.md

This is a listing of various examples used for the Couchbase Go SDK GA Release Blog.

Blog Post

@ingenthr
ingenthr / n1ql.go
Last active September 16, 2015 13:14
N1QL Query from Go
cluster, _ := gocb.Connect("couchbase://localhost")
bucket, _ := cluster.OpenBucket("default", "")
query := gocb.NewN1qlQuery("SELECT * FROM default")
rows := bucket.ExecuteViewQuery(query)
var row interface{}
for rows.Next(&row) {
fmt.Printf("Row: %+v\n", row)
}
// Read
Observable loadedFromId = bucket.get("id"); // async using RxJava
JsonDocument found = bucket.get("notexisting").toBlocking().singleOrDefault(null); // sync
// Write
JsonDocument found = bucket.get("notexisting").toBlocking().singleOrDefault(null); //
// Query
@ingenthr
ingenthr / ConvertToRdds.scala
Last active November 24, 2015 23:44
Blog: Bulk Transformations of Couchbase Data Using Apache Spark with an External Source
/** Returns an RDD based on email address extracted from the document */
def CreateMappableRdd(s: (String, String)): (String, JsonDocument) = {
val return_doc = JsonDocument.create(s._1, JsonObject.fromJson(s._2))
(return_doc.content().getString("email"), return_doc)
}
@ingenthr
ingenthr / Main.java
Created December 17, 2015 00:17
Couchbase quick example of Prepared Parameterized Statements from Java SDK
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import java.util.concurrent.TimeUnit;
/**
* Created by ingenthr on 12/16/15.
*/
public class Main {
@ingenthr
ingenthr / first_node.sh
Created May 19, 2016 22:52
Quick hack to set up the first node and complete provisioning. Was done to work around a bug in memory optimized indexes.
#!/usr/bin/env bash
set -xe
# Setup Services
curl -i -u Administrator:password -X POST \
http://127.0.0.1:8091/node/controller/setupServices \
-d 'services=kv%2Cn1ql%2Cindex'
# Initialize Node with /couchbase for index and data path
curl -i -u Administrator:password -X POST \