Skip to content

Instantly share code, notes, and snippets.

Avatar

Zac Sweers ZacSweers

View GitHub Profile
@ZacSweers
ZacSweers / RxponetialBackoff
Created Feb 23, 2016 — forked from sddamico/LICENSE
Exponential Backoff Transformer
View RxponetialBackoff
/**
* @param interval The base interval to start backing off from. The function is: attemptNum^2 * intervalTime
* @param units The units for interval
* @param retryAttempts The max number of attempts to retry this task or -1 to try MAX_INT times,
*/
public static <T> Observable.Transformer<T, T> backoff(final long interval, final TimeUnit units, final int retryAttempts) {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(final Observable<T> observable) {
return observable.retryWhen(
@ZacSweers
ZacSweers / ExponentialBackoff
Last active Apr 14, 2020 — forked from jerrellmardis/ExponentialBackoff
Exponential Backoff using Rx.retryWhen() I DON'T KNOW WHY THIS HAS HIGH SEO I JUST FORKED IT TO SAVE A COPY
View ExponentialBackoff
// retries up to 3 times while exponentially backing off with each retry
.retryWhen(errors ->
errors
.zipWith(
Observable.range(1, MAX_RETRIES), (n, i) -> i
)
.flatMap(
retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS)
)
)
View okiobuffer.java
public void readTwice()
{
Observable.fromCallable(() -> {
RedditData inflatedModel = null;
Response response = makeRequest();
String diskValue = null;
try {
File file = new File(getContext().getCacheDir(), "file");
BufferedSink cacheBody = Okio.buffer(Okio.sink(file));
View caltrain.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZacSweers
ZacSweers / RxJava.md
Last active Sep 3, 2018 — forked from cesarferreira/RxJava.md
Party tricks with RxJava, RxAndroid & Retrolambda
View RxJava.md

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
View Username blacklist
about
account
add
admin
api
app
apps
archive
archives
auth
View MenuPreference.java
public class MenuPreference extends ListPreference {
private View anchor;
public MenuPreference(Context context) {
super(context);
}
public MenuPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
View gist:78f082bdc0ac17797c7a
apply plugin: 'java'
apply plugin: 'maven-publish'
group = 'com.demo'
version = '1.0.0'
sourceCompatibility = 1.7
repositories {
mavenCentral()