Skip to content

Instantly share code, notes, and snippets.

View chemickypes's full-sized avatar
📱

Angelo Moroni chemickypes

📱
View GitHub Profile
class AppRestService : IAppRestService {
override fun getAppRestService(): IRestService {
val httpClient = OkHttpClient().newBuilder()
val interceptor = Interceptor { chain ->
val request = chain?.request()?.newBuilder()?.addHeader("SomeHeader", "SomeHeaderProperty")?.build();
chain?.proceed(request)
}
httpClient.networkInterceptors().add(interceptor)
val customGson = GsonBuilder().registerTypeAdapter(MyClassCloud::class.java, MyClassCloudDeserializer("1")).create()
val retrofit = Retrofit.Builder().baseUrl(IRestService.URL_BASE).addConverterFactory(GsonConverterFactory.create(customGson)).client(httpClient.build()).build()
@koesie10
koesie10 / ApiModule.java
Created October 3, 2015 07:40
Retrofit 1 error handling behaviour in Retrofit 2
// Dagger 1 example
@Module(
complete = false,
library = true
)
public final class ApiModule {
@Provides
@Singleton
Retrofit provideRetrofit(Gson gson, Application app) {
return new Retrofit.Builder()
@ssinss
ssinss / EndlessRecyclerOnScrollListener.java
Last active January 19, 2024 08:52
Endless RecyclerView OnScrollListener
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
@julianshen
julianshen / CircleTransform.java
Last active November 6, 2023 12:47
CircleTransform for Picasso
/*
* Copyright 2014 Julian Shen
*
* 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
@franmontiel
franmontiel / PersistentCookieStore.java
Last active July 6, 2023 09:07
A persistent CookieStore implementation for use in Android with HTTPUrlConnection or OkHttp 2. -- For a OkHttp 3 persistent CookieJar implementation you can use this library: https://github.com/franmontiel/PersistentCookieJar
/*
* Copyright (c) 2015 Fran Montiel
*
* 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
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)){
if("com.example.MyNeatoIntentService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
@msangel
msangel / ApiModule.java
Last active October 10, 2022 14:45 — forked from koesie10/ApiModule.java
Retrofit 1 error handling behaviour in Retrofit 2.3.0
// Dagger 1 example
@Module(
complete = false,
library = true
)
public final class ApiModule {
@Provides
@Singleton
Retrofit provideRetrofit(Gson gson, Application app) {
return new Retrofit.Builder()
@mustafasevgi
mustafasevgi / EndlessRecyclerOnScrollListener.java
Created April 7, 2016 13:07 — forked from imran0101/EndlessRecyclerOnScrollListener.java
RecyclerView position helper to get first and last visible positions
/**
* Custom Scroll listener for RecyclerView.
* Based on implementation https://gist.github.com/ssinss/e06f12ef66c51252563e
*/
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = "EndlessScrollListener";
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
@cmelchior
cmelchior / CustomTypeAdapter.java
Created April 9, 2015 06:35
Realm, GSON and primitive JSON arrays
// Make a custom Gson instance, with a custom TypeAdapter for each wrapper object.
// In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer>
Type token = new TypeToken<RealmList<RealmInt>>(){}.getType();
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@JeyDi
JeyDi / PandasSQLQuery.py
Last active March 4, 2022 07:08
From SQL to Python Pandas
# From SQL to Python Pandas Cheatsheet
# many thanks to: https://medium.com/jbennetcodes/how-to-rewrite-your-sql-queries-in-pandas-and-more-149d341fc53e
# Using airports data example: https://ourairports.com/data/
import pandas as pd
# Reset Pandas Index
df.reset_index(drop=True, inplace=True)
# Simply add a columns with an easy calculation