Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

M. Reza Nasirloo MRezaNasirloo

👨‍💻
View GitHub Profile
@MRezaNasirloo
MRezaNasirloo / Ganjeh.kt
Last active May 4, 2020
Ganjeh lets you share a ViewModel across multiple LifecycleOwners
View Ganjeh.kt
package com.mrezanasirloo.ganjeh
import android.util.SparseArray
import androidx.activity.ComponentActivity
import androidx.annotation.MainThread
import androidx.fragment.app.Fragment
import androidx.fragment.app.createViewModelLazy
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelLazy
@MRezaNasirloo
MRezaNasirloo / build.gradle
Created Aug 27, 2018 — forked from JonasGroeger/build.gradle
Gradle: Read git commit hash.
View build.gradle
def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
def takeFromHash = 12
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
View DiffCharTest.java
import android.support.annotation.NonNull;
import org.junit.Test;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import static org.junit.Assert.assertSame;
@MRezaNasirloo
MRezaNasirloo / MainActivity.java
Created Apr 3, 2018
Retrofit parse error body sample
View MainActivity.java
package com.mrezanasirloo.retrofiterrorhandling;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@MRezaNasirloo
MRezaNasirloo / OkHttpProgressGlideModule.java
Created Nov 13, 2017 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
View OkHttpProgressGlideModule.java
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@MRezaNasirloo
MRezaNasirloo / TextViewCompatTint.java
Last active Apr 4, 2019
A Backward Compatible TextView drawableTint
View TextViewCompatTint.java
package com.github.pedramrn;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import com.github.pedramrn.slick.parent.R;
@MRezaNasirloo
MRezaNasirloo / create-multi-host-swarm-digitalocean.sh
Last active Jun 3, 2016 — forked from jmshal/create-multi-host-swarm-digitalocean.sh
Setup a Docker Swarm multi-host cluster on DigitalOcean
View create-multi-host-swarm-digitalocean.sh
docker-machine create \
--driver=digitalocean \
--digitalocean-access-token=$DO_TOKEN \
--digitalocean-size=512mb \
--digitalocean-region=nyc3 \
--digitalocean-private-networking=true \
--digitalocean-image=ubuntu-15-10-x64 \
docker-swarm-kv-store
docker $(docker-machine config docker-swarm-kv-store) run -d \
You can’t perform that action at this time.