Skip to content

Instantly share code, notes, and snippets.

View MRezaNasirloo's full-sized avatar
👨‍💻

M. Reza Nasirloo MRezaNasirloo

👨‍💻
View GitHub Profile
@MRezaNasirloo
MRezaNasirloo / cat_toy.c
Last active March 24, 2024 15:04
a cat toy, rotates a servo randomly, display info and ota updates
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Servo.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
blueprint:
name: IKEA Tradfri Switch Control with Dimming
description: Control IKEA Tradfri Switch (Square with 1/0 buttons) using zigbee2mqtt with dimming functionality.
domain: automation
input:
tradfri_switch_entity:
name: IKEA Tradfri Switch
description: The entity ID of the Tradfri Switch in Home Assistant.
selector:
entity:
@MRezaNasirloo
MRezaNasirloo / GeneralAdapter.kt
Created September 2, 2021 10:30
This Adapter eliminates the need to write custom RecyclerView.Adapters
package com.mrezanasirloo.adapter
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
/**
* This adapter eliminates the need to write custom [RecyclerView.Adapter]s and
* [RecyclerView.ViewHolder]s by delegating the view holder creation and binding to the [Item] class
*/
class GeneralAdapter(
@MRezaNasirloo
MRezaNasirloo / Either.kt
Last active April 3, 2021 07:55
An Either class
sealed class Either<L> {
class Success<L>(val value: L) : Either<L>()
class Error<L>(val title: String, val message: String) : Either<L>()
fun success(success: L.() -> Unit) {
if (this is Success<L>) success(value)
}
fun error(error: (Error<L>).() -> Unit) {
if (this is Error<L>) error(this)
}
}
@MRezaNasirloo
MRezaNasirloo / Ganjeh.kt
Last active October 9, 2021 13:17
Share ViewModels across LifecycleOwners
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 August 27, 2018 12:20 — forked from JonasGroeger/build.gradle
Gradle: Read git commit hash.
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
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 April 3, 2018 13:21
Retrofit parse error body sample
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 November 13, 2017 14:59 — forked from TWiStErRob/OkHttpProgressGlideModule.java
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// 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 May 24, 2021 06:37
A Backward Compatible TextView drawableTint
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;