Skip to content

Instantly share code, notes, and snippets.

package com.mirth.stevek.rxtest;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func3;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
@Flaccuss
Flaccuss / ParallelRxJavaUtil.java
Created March 16, 2018 18:59 — forked from PierceZ/ParallelRxJavaUtil.java
Util method to process a list of data in parallel.
/**
* Will process the data with the callable by splitting the data into the specified number of threads.
* <b>T</b> is ths type of data being parsed, and <b>U</b> is the type of data being returned.
*/
public static <T, U> Iterable<U> parseDataInParallel(@NonNull List<T> data, Function<List<T>, ObservableSource<U>> worker) {
int threadCount = Runtime.getRuntime().availableProcessors();
ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(threadCount);
Scheduler scheduler = Schedulers.from(threadPoolExecutor);
AtomicInteger groupIndex = new AtomicInteger();
@Flaccuss
Flaccuss / Singleton.java
Created March 16, 2018 20:11 — forked from aritraroy/Singleton.java
A Perfect Singleton Design Pattern Implementation
import java.io.Serializable;
/**
* The perfect implementation of Singleton design pattern
* Properly solves all the below mentioned problems in Singleton pattern
* <p>
* 1) Attack using Reflection API
* 2) Problems from serialization/deserialization of your object
* 3) Problems from cloning your object
* 4) Uncertainty in a multi-threaded environment
@Flaccuss
Flaccuss / post.md
Created August 16, 2018 18:48 — forked from grantland/post.md
RecyclerView item onClick

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder
@Flaccuss
Flaccuss / OkHttpProgressGlideModule.java
Created August 17, 2018 19:26 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
class NewsScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _NewsScreenState();
}
class _NewsScreenState extends State<NewsScreen> {
final List<String> listItems = [];
final List<String> _tabs = <String>[
"Featured",