Skip to content

Instantly share code, notes, and snippets.

View Sloy's full-sized avatar

Rafa Vázquez Sloy

View GitHub Profile
@Sloy
Sloy / build.gradle
Last active August 29, 2015 14:15
Dex Count Gradle
buildscript {
repositories {
jcenter()
maven { url 'http://dl.bintray.com/sloy/maven'} //<- only needed while jcenter refresh to the new version
}
dependencies {
classpath 'com.sloydev:dexcountprettify-plugin:0.1.2'
}
}
@Sloy
Sloy / build.gradle
Created June 26, 2015 14:41
Automatic apk signing for CI
android {
...
signingConfigs {
release {
storeFile file('../certs/release.keystore')
def (releaseKeystorePassword, releaseKeyAlias, releaseKeyPassword) = signingConfig()
storePassword releaseKeystorePassword
keyAlias releaseKeyAlias
keyPassword releaseKeyPassword
@Sloy
Sloy / video2gif.py
Last active December 30, 2015 09:59
Este script genera una animación gif a partir de un archivo de vídeo, colocando opcionalmente un fondo en cada frame. Está pensado para convertir los vídeos obtenidos en Android mediante 'adb shell screenrecord' o con la herramienta de Android Studio.
#coding=utf-8
"""
Por: Rafa Vázquez
http://sloydev.com/
Este script genera una animación gif a partir de un archivo de vídeo, colocando opcionalmente un fondo en cada frame.
Está pensado para convertir los vídeos obtenidos en Android mediante 'adb shell screenrecord' o con la herramienta de Android Studio.
Un ejemplo del resultado puede verse en http://i.imgur.com/Opu5aG3.gif
@Sloy
Sloy / AutocompleteViewActions.java
Created August 17, 2016 08:49
Custom Espresso action for AutoCompleteTextView. It replaces the text without showing the annoying popup in your tests.
public class AutocompleteViewActions {
public static ViewAction replaceAutocomplete(@Nonnull String stringToBeSet) {
return actionWithAssertions(new ReplaceAutocompleteTextAction(stringToBeSet));
}
/**
* This is based on {@link ReplaceTextAction}
* with modifications thanks to "http://www.grokkingandroid.com/how-androids-autocompletetextview-nearly-drove-me-nuts/".
* <p>
@Sloy
Sloy / SimpleContextMenu.java
Created August 21, 2016 17:48
A context menu alternative with a simpler API, without the fuzz of all that lifecycle mess
public class SimpleContextMenu {
private final Context context;
private final String[] titles;
private final Runnable[] callbacks;
public static Builder builder(Context context) {
return new Builder(context);
}
@Sloy
Sloy / Monitor GcmNetworkManager tasks
Created September 29, 2016 09:18
GcmNetworkManager monitoring command
$ while sleep 1; do adb shell dumpsys activity service GcmService --endpoints my.package.name | grep "Pending:" -A 20; done
@Sloy
Sloy / MenuItemValueHolder.java
Last active November 2, 2016 09:57
Wrap your MenuItem with this class and forget about activity/fragment lifecycle with menu items. Initializing the visibility and your menu is not created yet? Don't worry, it will queue actions and trigger them once it's ready.
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.ActionProvider;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import java.util.LinkedList;
import java.util.List;
public class NetworkEndpointPreference extends StringPreference {
@Inject
public NetworkEndpointPreference(SharedPreferences preferences) {
super(preferences, "debug_network_endpoint_url", DebugApiEndpoints.PROD.getUrl());
}
}
@Sloy
Sloy / potato.js
Last active October 27, 2017 10:19
Just a JS potato
Object.prototype.potato = function(){
console.log('MMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmdhysssssyhhmNMMMMMMMMMMMMMMMMMMMMMMMMMM','MMMMMMMMMMMMMMMMMMMMMMMmy+:.```.--:::::--.```.:+ydMMMMMMMMMMMMMMMMMMMM','MMMMMMMMMMMMMMMMMMMMh+. .:+shddhhhyyyyyhhhddhs+:. ./hNMMMMMMMMMMMMMMMM','MMMMMMMMMMMMMMMMMMy- .+hdhysoo++++++++++++++ooyhdh+. .sNMMMMMMMMMMMMMM','MMMMMMMMMMMMMMMMd: .sdho+++ssso++++++++++++++++++oydy- -dMMMMMMMMMMMMM','MMMMMMMMMMMMMMMy` +dho+++++ooso++++++++++++++++++oooym+ .dMMMMMMMMMMMM','MMMMMMMMMMMMMMs``sms++++++++++++++++++++++++++++osss+sm+ .NMMMMMMMMMMM','MMMMMMMMMMMMMh``ymo++sso++++++++++++++++++++++++++++++hm- oMMMMMMMMMMM','MMMMMMMMMMMMm` oms+++ooo++++++++++++++++++++++++++++++oms .NMMMMMMMMMM','MMMMMMMMMMMM: /my++++++++++++++++++++++++++++++++++++++hd` dMMMMMMMMMM','MMMMMMMMMMMs .dh+++++++++oyhhyo+++++++++++++++++ohhhyo+ym- sMMMMMMMMMM','MMMMMMMMMMm` smo++++++++ommmmmmo+++++++++++++++ommmmmd+om+ :MMMMMMMMMM','MMMMMMMMMM/ :my++++++++++dmmmmd+++++ssyyyyyso++odmmmmh++dh `dMMMMMMMMM','MMMMMMMMMh``hd++++++
@Sloy
Sloy / GetAndForgetProperty.kt
Created November 22, 2017 11:02
A custom delegate for a property that it's deleted after reading it, so it can only be used once.
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* With this delegate, a property will only return it's value once. Subsequent queries will return the default value.
*/
class GetAndForgetProperty<in R, T>(private val defaultValue: T) : ReadWriteProperty<R, T> {
companion object {
fun <T> getAndForget(defaultValue: T): GetAndForgetProperty<Any, T> {