Skip to content

Instantly share code, notes, and snippets.

slightfoot /
Last active Feb 3, 2021
Fix for upload progress monitoring in Android.
import android.util.Log;
gabrielemariotti /
Last active Feb 24, 2021
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (

Centralize the support libraries dependencies in gradle

Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.

A very good way is to separate gradle build files, defining something like:

marcelpinto /
Last active Dec 12, 2019 — forked from blipinsk/
An extension of Android AppBarLayout, that allows to programatically change the CollapsibleToolbarLayout state and receive state changes (collapsed, expanded and idle)
* Copyright 2015 Bartosz Lipinski
* 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
Tetr4 /
Last active Feb 1, 2020
How to force a cached or network response on Android with Retrofit + OkHttp
OkHttpClient okHttpClient = new OkHttpClient();
try {
int cacheSize = 10 * 1024 * 1024 // 10 MiB
Cache cache = new Cache(getCacheDir(), cacheSize);
} catch (IOException e) {
Log.e(TAG, "Could not set cache", e);
// Forces cache. Used for cache connection
alexwen / gist:4b337bc669509a696b5b
Created Apr 25, 2015
OkHttp Observable Callback
View gist:4b337bc669509a696b5b
public Observable<FilesWrapper> download(List<Thing> things) {
return Observable.from(things)
.flatMap(thing -> {
File file = new File(getExternalCacheDir() + File.separator + thing.getName());
if (file.exists()) {
return Observable.just(file);
Request request = new Request.Builder().url(thing.getUrl()).build();
hamakn /
Created Apr 6, 2015
Android: Get height of status, action, navigation bar (pixels)
// status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
View Install Scala + Play Framework with Activator in

Step by step to install Scala + Play Framework in Ubuntu 14.04 with Activator.

Install Scala

sudo apt-get remove scala-library scala
sudo dpkg -i scala-2.11.6.deb
sudo apt-get update
sudo apt-get install scala
stkent /
Last active Jun 24, 2022
Android Studio Shortcuts (Mac)

Android Studio Shortcuts (Mac)


  • Two of the most useful shortcuts utilize the Fn (function) keys. It is therefore recommended that you enable the "Use all F1, F2, etc. keys as standard function keys" option [System Preferences > Keyboard].
  • Be sure to enable the Mac OS X 10.5+ keymap in Android Studio [Preferences > Keymap].
  • A fairly complete shortcut list can be found here.

Useful symbols:

grantland /
Last active Feb 3, 2022
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
soheilhy /
Last active Jun 26, 2022
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for,, and on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers