Skip to content

Instantly share code, notes, and snippets.

Michael Nitschinger daschl

Block or report user

Report or block daschl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View build.gradle
/**
* Copyright (C) 2014 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:
*
@daschl
daschl / samples.py
Created Aug 22, 2016
Couchbase Spark Samples
View samples.py
// Start the Shell
./pyspark --packages com.couchbase.client:spark-connector_2.10:1.2.1 --conf "spark.couchbase.bucket.travel-sample="
// Create a DF
>>> df = sqlContext.read.format("com.couchbase.spark.sql.DefaultSource").option("schemaFilter", "type=\"airline\"").load()
// Print the Schema
>>> df.printSchema()
root
View bla.jsx
<ul id="results-list" className="list-group">
{
this.state.responses.map((item, key) => {
if (item.success) {
<li key={key} className="list-group-item list-group-item-success">
<pre>{JSON.stringify(item, null, 2)}</pre>
</li>
} else {
<li key={key} className="list-group-item list-group-item-success">bla</li>
}
View build.gradle
plugins {
id 'scala'
id 'maven-publish'
}
repositories {
mavenCentral()
jcenter()
}
View Bucket.java
/*
* Copyright (c) 2018 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@daschl
daschl / gist:db9fcc9d2b932115b679
Last active Jan 10, 2019
Draft: Writing Code for Production
View gist:db9fcc9d2b932115b679

Writing Resilient Reactive Applications

This guide is a first draft (that will end up in the official docs) on writing resilient code for production with the Couchbase Java SDK. At the end, the reader will be able to write code that withstands bugs, latency issues or anything else that can make their application fail.

Note that lots of concepts can be applied for both synchronous and asynchronous access. When necessary, both patterns are discussed separately. Also, the focus is on database interaction, but if you are using RxJava as part of your stack you can apply most of the principles there as well (and should!).

RxJava 101 Recap: Cold and Hot Observables

When working with Observables, it is important to understand the difference between cold and hot. Cold Observables will start to emit events once a Observer subscribes, and will do it "fresh" for each Observer. Hot Observables instead are starting to emit data as soon as it becomes available, and will return the same (or parts of the same)

@daschl
daschl / couchbase-php-2pc-advanced.php
Created Jul 21, 2012
Advanced Couchbase 2PC PHP Implementation
View couchbase-php-2pc-advanced.php
<?php
/**
* A more general PHP two-phase commit implementation.
*
* This assumes that we run on 5.3 or later.
*/
class TransactionException extends Exception {}
/**
View prototype.java
// --- Collection API ---
// full doc fetch
Optional<Document> doc = collection.get("id");
// full doc fetch, turns into subdoc actually
Optional<Document> doc = collection.get("id", getOptions().withExpiration(true));
// full doc insert (since we now return a doc, let's take a document!)
collection.insert(
View CouchbaseContainer.java
package com.couchbase.testcontainers;
import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.WaitStrategy;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.images.builder.dockerfile.DockerfileBuilder;
import java.util.Arrays;
import java.util.Collection;
@daschl
daschl / ArraysAndDicts.java
Last active Aug 27, 2018
subdoc examples
View ArraysAndDicts.java
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.PersistTo;
import com.couchbase.client.java.ReplicateTo;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.document.subdoc.DocumentFragment;
import com.couchbase.client.java.document.subdoc.ExtendDirection;
import com.couchbase.client.java.error.subdoc.PathExistsException;
You can’t perform that action at this time.