Skip to content

Instantly share code, notes, and snippets.

View defHLT's full-sized avatar
🐔

Artem Kholodnyi defHLT

🐔
View GitHub Profile
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
} else {
Timber.plant(new CrashReportingTree());
}
....
private static class CrashReportingTree extends Timber.Tree {
@Override protected void log(int priority, String tag, String message, Throwable t) {
/**
* Created by ice on 5/3/15.
*/
public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>> {
private final int maxRetries;
private final int retryDelayMillis;
private int retryCount;
@defHLT
defHLT / retry.java
Created June 9, 2015 20:56
RX retry times
mySubscription = retrofitInterface.doSmth(param)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.retryWhen(new RetryWithDelay(4, 2000))
.subscribe(....)
package com.mlatu.tv.ui;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.mlatu.tv.R;
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* 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
@defHLT
defHLT / fib.java
Created June 1, 2015 23:12
Fib generator
import java.util.Iterator;
class HelloWorldApp {
public static void main(String[] args) {
Iterable<Integer> fibo = new Iterable<Integer>() {
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
int a = 0;
fib = Enumerator.new do |y|
a, b = 0, 1
loop do
y.yield a
a, b = b, a + b
end
end
p fib.take 25
7 user=> (def get-prev-and-set (let [a (atom {})] (fn [x] (let [r (@a :a)] (swap! a assoc :a x) r))))
6 #'user/get-prev-and-set
5 user=> (get-prev-and-set 1)
4 nil
3 user=> (get-prev-and-set 123)
2 1
1 user=> (get-prev-and-set 42)
8 123
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
mContextStream.onNext(activity);
}
// ......
t.search(query) // Retrofit
.subscribeOn(Schedulers.io())
.retry(3)
.observeOn(Schedulers.io())
.subscribe(new Observer<List<SearchResult>>() {
@Override
public void onCompleted() {
}
@Override