Skip to content

Instantly share code, notes, and snippets.

import java.lang.ref.Cleaner;
public class InternalCleaner {
public static void main(String... args) throws Exception {
while (true) {
SensitiveData data = new SensitiveData();
Thread.sleep(100);
System.gc();
import java.lang.ref.Cleaner;
public class ExternalCleaner {
public static void main(String... args) throws Exception {
while (true) {
SensitiveData data = new SensitiveData();
StateCleaner cleaner = new StateCleaner(data);
Thread.sleep(100);
@daschl
daschl / a.md
Created July 1, 2022 06:36
Couchbase / Reactor Classpath Issues

Overview

The issue we are running into with the couchbase spark connector under databricks is that there seem to be classpath issues which based on my analysis and limited understandung of the underlying runtime should not happen.

I'm sharing the rough details below, if someone needs access to couchbase cloud credentials to try and reproduce please just ping me directly @daschl on twitter and I'm more than happy to provide those.

Background

The Connector uses the Couchbase Scala SDK underneath which has a direct dependency on project reactor and makes use of it quite heavily.

Looking at the classpath, it looks like there is more than one reactor version there:

@daschl
daschl / d2.rs
Created January 14, 2021 21:26
d2.rs
//! Experimental code for the touch screen display.
#![no_main]
#![cfg_attr(not(test), no_std)]
#[allow(unused_imports)]
use defmt_rtt as _;
use display_interface::DataFormat::U16BEIter;
use display_interface::WriteOnlyDataCommand;
use display_interface_spi::SPIInterfaceNoCS;
@daschl
daschl / couchbase-php-2pc-simple.php
Created July 21, 2012 08:39
Simple Couchbase PHP 2PC Implementation
<?php
/**
* Simple two-phase commit for PHP couchbase.
*
* Michael Nitschinger (@daschl, 2012)
*
* Additional Remarks
* ------------------
* - The Couchbase extension makes it currently pretty hard to write easy readable code when dealing with
* CAS (compared to the ruby adapter). This could certainly be improved with closures. I also found that
#![no_main]
#![cfg_attr(not(test), no_std)]
#[allow(unused_imports)]
use defmt_rtt as _;
#[allow(unused_imports)]
use nrf52840_hal as _;
use nrf52840_hal::gpio::{Level, Output, Pin, PushPull};
use nrf52840_hal::prelude::OutputPin;
@daschl
daschl / display.rs
Last active October 25, 2020 16:07
display.rs
#![no_main]
#![no_std]
use defmt_rtt as _;
use nrf52840_hal as _; // memory layout // global logger
use embedded_hal::digital::v2::OutputPin;
use nrf52840_hal::gpio::{p0, Level, Output, Pin, PushPull};
use nrf52840_hal::pac::{Peripherals, SPIM0, TIMER0};
use nrf52840_hal::prelude::*;
//! Helps to wrap plugins into commands for direct inclusion
use nu_plugin::Plugin;
use nu_cli::{CommandArgs, CommandRegistry, OutputStream, WholeStreamCommand};
use async_trait::async_trait;
use nu_protocol::Signature;
use nu_errors::ShellError;
pub struct PluginCommand<P> {
signature: Signature,
@daschl
daschl / gist:db9fcc9d2b932115b679
Last active August 26, 2020 23:17
Draft: Writing Code for Production

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)

package org.testcontainers.couchbase;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.ContainerNetwork;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.JsonNode;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
import org.testcontainers.shaded.okhttp3.Credentials;
import org.testcontainers.shaded.okhttp3.FormBody;