Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Kalpesh Patel kalpeshp0310

🏠
Working from home
View GitHub Profile
@kalpeshp0310
kalpeshp0310 / main.go
Created Jan 8, 2018 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
View main.go
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@kalpeshp0310
kalpeshp0310 / RxErrorCallAdapterFactory.java
Last active Apr 20, 2017
Retrofit CallAdapter for Rx Errors.
View RxErrorCallAdapterFactory.java
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) {
View SectionedRecyclerViewAdapter.java
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 / NetworkHelper.java
Last active Apr 14, 2017
Network Helper for RxJava, OkHttp, Gson
View NetworkHelper.java
public class NetworkHelper {
private OkHttpClient okHttpClient;
private Gson gson;
public NetworkHelper(OkHttpClient okHttpClient, Gson gson) {
this.okHttpClient = okHttpClient;
this.gson = gson;
}
/**
@kalpeshp0310
kalpeshp0310 / File.java
Created Apr 7, 2016 — forked from dlew/File.java
Automated onError() message generation
View File.java
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());