Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@benjchristensen
benjchristensen / DebounceBuffer.java
Last active March 1, 2024 15:46
DebounceBuffer: Use publish(), debounce() and buffer() together to capture bursts of events.
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
public class DebounceBuffer {
public static void main(String args[]) {
@benjchristensen
benjchristensen / Fibonacci.java
Last active August 14, 2017 10:01
Fibonacci + Rx
import java.util.HashMap;
import rx.Observable;
import rx.Subscriber;
public class Fibonacci {
public static void main(String... args) {
// via Observable.create
fib.take(13).forEach(System.out::println);
import java.util.concurrent.TimeUnit;
import rx.Observable;
public class MergeUntilComplete {
public static void main(String[] args) {
Observable<String> t1 = Observable.timer(0, 100, TimeUnit.MILLISECONDS).map(i -> "A-" + i);
Observable<String> t2 = Observable.timer(0, 300, TimeUnit.MILLISECONDS).take(5).map(i -> "B-" + i);
@benjchristensen
benjchristensen / CompositeSubscription.java
Last active August 29, 2015 14:01
CompositeSubscription using synchronized, mutable data structure
/**
* Copyright 2014 Netflix, 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
@benjchristensen
benjchristensen / AbstractPerformanceTester.java
Created May 28, 2014 20:10
TestRxPerf - simple map transform
package rx.perf;
import java.util.Iterator;
import rx.functions.Action0;
public abstract class AbstractPerformanceTester {
public static final long REPETITIONS = 5 * 1000 * 1000;
public static final int NUM_PRODUCERS = 1;
import rx.Notification;
import rx.Observable;
import rx.Observable.Operator;
import rx.Subscriber;
import rx.functions.Func1;
public class ConcatIfEmpty {
public static void main(String[] args) {

Keybase proof

I hereby claim:

  • I am benjchristensen on github.
  • I am benjchristensen (https://keybase.io/benjchristensen) on keybase.
  • I have a public key whose fingerprint is 6EC3 891B AF53 E272 976E 3060 EB6A 08CB EC72 5A7B

To claim this, I am signing this object:

package perf.backend;
import rx.Observable;
import rx.Observable.Operator;
import rx.Subscriber;
import rx.subjects.AsyncSubject;
import rx.subjects.ReplaySubject;
import rx.subjects.Subject;
public class ChooseSubjectBasedOnFirstValue {
@benjchristensen
benjchristensen / Outer.java
Last active August 29, 2015 13:55
Scheduler.java concept
compositeSubscription.add(scheduler.schedule(new Action1<Action0>() {
@Override
public void call(final Action0 self) {
innerSubscription.set(source.subscribe(new Observer<T>() {
@Override
public void onCompleted() {
self.call();
}
@benjchristensen
benjchristensen / ObsurvableBind3.java
Created January 19, 2014 15:33
Observable example with just the `bind` operator and unit tests asserting behavior while exploring the best signature. This variant uses: Func1<Operator<R>, Operator<T>> but has Operator implement Subscription directly and compose a CompositeSubscription within it.
/**
* Copyright 2014 Netflix, 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