Skip to content

Instantly share code, notes, and snippets.

@mirmilad
mirmilad / dynamic-filter.pipe.ts
Created January 3, 2021 22:28
a simple pipe for Angular that allows you filter array in template
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'dynamicFilter'
})
export class DynamicFilterPipe implements PipeTransform {
transform(items: any[], filter: any): any[] {
if (!items || !filter) {
return items;
@mirmilad
mirmilad / GradientTextViewUtil.java
Created February 4, 2020 22:21
A simple method to set LinearGradient as text color to TextView
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;
import android.text.Layout;
import android.widget.TextView;
public class GradientTextViewUtil {
@mirmilad
mirmilad / DebouncedLiveData.java
Created January 14, 2020 11:29
Simple DebouncedLiveData class for Android
import android.os.Handler;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.Observer;
public class DebouncedLiveData<T> extends MediatorLiveData<T> {
private LiveData<T> mSource;
private int mDuration;
@mirmilad
mirmilad / CoroutinePageKeyedDataSource.kt
Last active June 26, 2020 02:46
Android Paging Library with Kotlin Coroutines
import androidx.paging.PageKeyedDataSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
abstract class CoroutinePageKeyedDataSource<K, V>(private val coroutineContext: CoroutineContext) :
PageKeyedDataSource<K, V>() {
private val job = Job()
@mirmilad
mirmilad / debounce.kt
Last active June 21, 2023 22:46
Simple debounce extension for LiveData by using Coroutines
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
fun <T> LiveData<T>.debounce(duration: Long = 1000L, coroutineScope: CoroutineScope) = MediatorLiveData<T>().also { mld ->
val source = this