Skip to content

Instantly share code, notes, and snippets.

@tgrall
tgrall / samplegeoquery.java
Last active August 29, 2015 14:05
Sample Java GeoQuery
import com.mongodb.*;
/**
* Created by tgrall on 8/27/14.
*/
public class TestApp {
public static void main(String[] args) throws Exception {
@tgrall
tgrall / distinct.go
Created October 29, 2014 10:37
Go Sample : How to do a Distinct
package main
import (
"fmt"
"log"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type City struct {
@tgrall
tgrall / demo.MapRDBSJSONType.java
Created October 3, 2015 12:55
OJAI/MapR-DB Sample code to save/get binary content
package demo;
import com.mapr.db.MapRDB;
import com.mapr.db.Table;
import org.ojai.Document;
import javax.print.Doc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@tgrall
tgrall / TwitterInjector.java
Created November 6, 2012 03:28
TwitterInjector
package com.couchbase.demo;
import com.couchbase.client.CouchbaseClient;
import org.json.JSONException;
import org.json.JSONObject;
import twitter4j.*;
import twitter4j.json.DataObjectFactory;
import java.io.InputStream;
@tgrall
tgrall / sample-couchbase-pom.xml
Last active December 9, 2015 22:28
Sample Maven Dependency File
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<dependencies>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>couchbase-client</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
@tgrall
tgrall / simple-connection.java
Last active December 9, 2015 22:28
Connect to Couchbase Server
// import
import com.couchbase.client.CouchbaseClient;
...
...
List<URI> uris = new LinkedList<URI>();
uris.add(URI.create("http://127.0.0.1:8091/pools"));
CouchbaseClient client = null;
@tgrall
tgrall / call_collated_view_from_java.java
Last active December 13, 2015 16:58
View call for blog on collated views
View view = client.getView("brewery", "all_with_beers");
Query query = new Query();
query.setIncludeDocs(true).setLimit(100);
ViewResponse result = client.query(view, query);
ArrayList<HashMap<String, String>> items =
new ArrayList<HashMap<String, String>>();
for(ViewRow row : result) {
HashMap<String, String> parsedDoc = gson.fromJson(
(String)row.getDocument(), HashMap.class);
function(doc, meta) {
switch(doc.type) {
case "brewery":
emit([meta.id, 0, doc.name]);
break;
case "beer":
if (doc.name && doc.brewery_id) {
emit([doc.brewery_id, 1, doc.name], null);
}
}
@tgrall
tgrall / SampleStoreImage.java
Created June 3, 2013 13:39
Storing an image in Couchbase using Java SDK
package com.couchbase.devday;
import com.couchbase.client.CouchbaseClient;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
@tgrall
tgrall / SampleLookupApp.java
Created July 29, 2013 15:37
Sample Java Lookup
package com.couchbase.sample;
import com.couchbase.client.CouchbaseClient;
import com.google.gson.Gson;
import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;