Skip to content

Instantly share code, notes, and snippets.

View kalpeshp0310's full-sized avatar
🏠
Working from home

Kalpesh Patel kalpeshp0310

🏠
Working from home
View GitHub Profile
@kalpeshp0310
kalpeshp0310 / File.java
Created April 7, 2016 15:43 — forked from dlew/File.java
Automated onError() message generation
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());
@kalpeshp0310
kalpeshp0310 / NetworkHelper.java
Last active April 14, 2017 08:25
Network Helper for RxJava, OkHttp, Gson
public class NetworkHelper {
private OkHttpClient okHttpClient;
private Gson gson;
public NetworkHelper(OkHttpClient okHttpClient, Gson gson) {
this.okHttpClient = okHttpClient;
this.gson = gson;
}
/**
@kalpeshp0310
kalpeshp0310 / SectionedRecyclerViewAdapter.java
Created November 7, 2016 10:44
SectionedRecyclerViewAdapter
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.ViewGroup;
import java.util.List;
public abstract class SectionedRecyclerViewAdapter<VH extends RecyclerView.ViewHolder>
extends RecyclerView.Adapter<VH> {
@kalpeshp0310
kalpeshp0310 / RxErrorCallAdapterFactory.java
Last active April 20, 2017 12:55
Retrofit CallAdapter for Rx Errors.
public class RxErrorCallAdapterFactory extends CallAdapter.Factory {
@Override
public CallAdapter<?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
Class<?> rawType = getRawType(returnType);
String canonicalName = rawType.getCanonicalName();
boolean isSingle = rawType == Single.class;
boolean isCompletable = rawType == Completable.class;
// Return type not a Rx type.
if (rawType != Observable.class && !isSingle && !isCompletable) {
@kalpeshp0310
kalpeshp0310 / main.go
Created January 8, 2018 12:45 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
### Keybase proof
I hereby claim:
* I am kalpeshp0310 on github.
* I am kalpeshp0310 (https://keybase.io/kalpeshp0310) on keybase.
* I have a public key ASB_knuOKyWEsobqePLKR0ClYdSgfgAV7qUs908zgUiQDgo
To claim this, I am signing this object: