Skip to content

Instantly share code, notes, and snippets.

@hannesstruss
Created July 15, 2016 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannesstruss/7cf56f1ee914a1fba1312c8be57e4128 to your computer and use it in GitHub Desktop.
Save hannesstruss/7cf56f1ee914a1fba1312c8be57e4128 to your computer and use it in GitHub Desktop.
Easter Egg Timer
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.subjects.PublishSubject;
public class KonamiTimer {
private final PublishSubject<Integer> input;
private final int triggerCount;
public KonamiTimer(int triggerCount) {
this.triggerCount = triggerCount;
this.input = PublishSubject.create();
}
public void onInput() {
input.onNext(1);
}
/** Emits when unlocked */
public Observable<Void> completed() {
return input
.buffer(5, TimeUnit.SECONDS)
.map(List::size)
.filter(x -> x >= triggerCount)
.map(x -> null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment