Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Marchuck / ReactiveScrollView.java
Created August 2, 2017 15:35
reactive scrollview (able to detect scroll gesture)
package evalu.com.evalu.utils.rx;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
import io.reactivex.subjects.PublishSubject;
CatPresenter{
BehaviorSubject<List<Cat>> catsSubject = BehaviorSubject.create();
Disposable catsDisposable;
void onCreate(){
someClient.subscribe( cats -> { catsSubject.onNext(cats) })
@Marchuck
Marchuck / RxPlayer.java
Created June 30, 2017 21:56
example of rxPlayer implementation
package xD;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.util.Log;
import hugo.weaving.DebugLog;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
@Marchuck
Marchuck / GattUpdatesHelper.java
Created March 25, 2017 18:36
enable or disable gatt subscriptions
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.support.annotation.NonNull;
import android.util.Log;
import java.util.UUID;
/**
* Helper which enables or disables BLE gatt updates from connected peripheral, not tested in production
*/
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil
@Marchuck
Marchuck / OrientationChangeWithPendingNetworkRequestActivity.java
Created November 15, 2016 18:50
workaround for request with activity and screen orientation changes
/**
* @author Lukasz Marczak
* @since 28.09.16.
*/
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
int threadCt = Runtime.getRuntime().availableProcessors() + 1;
ExecutorService executor = Executors.newFixedThreadPool(threadCt);
Schedulers scheduler = Schedulers.from(executor);
Observable.range(1,1000)
.groupBy(i -> batch.getAndIncrement() % threadCt )
.flatMap(g -> g.observeOn(scheduler)
.map(i -> intenseCalculation(i))
public static void main(String[] argv) {
new CesarCipher().solve();
}
public void solve() {
Scanner in = new Scanner(System.in);
int t = Integer.valueOf(in.nextLine());
String line = in.nextLine();
StringBuilder sb = new StringBuilder();
String keys = in.nextLine();
String[] getIds = new String[]{"id:0", "id:1", "id:2", "id:3"};
rx.Observable.just(getIds)
.flatMap(new Func1<String[], Observable<String>>() {
@Override
public Observable<String> call(String[] strings) {
//dla kazdego id odpytaj api
return Observable.from(strings);
}
}).flatMap(new Func1<String, Observable<Integer>>() {
@Override
rx.Observable.range(1, 100).map(i -> String.valueOf(i).concat(
(i % 15 == 0 ? "FizzBuzz" : i % 3 == 0 ? "Fizz" : i % 5 == 0 ? "Buzz" : "")))
.subscribe(System.out::println);
OR, more readable:
rx.Observable.range(1, 100).map(i -> i + suffixFor(i)).subscribe(System.out::println);
...