Skip to content

Instantly share code, notes, and snippets.

@Razhan
Razhan / EllipsizingTextView.java
Created March 10, 2025 06:23 — forked from shayousefi/EllipsizingTextView.java
A TextView that ellipsizes more intelligently. This class supports ellipsizing multiline text through setting android:ellipsize and android:maxLines.
/*
* Copyright (C) 2011 Micah Hainline
* Copyright (C) 2012 Triposo
* Copyright (C) 2013 Paul Imhoff
* Copyright (C) 2014 Shahin Yousefi
*
* 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
*
@Razhan
Razhan / auth_retry_interceptor.dart
Created March 4, 2025 08:17 — forked from iamnabink/auth_retry_interceptor.dart
Auth Refresh Token Retry Interceptor using Dio Package
/// Author: Nabraj Khadka
/// Created: 28.05.2023
/// Description: Auth Interceptor
///
import 'package:project/app/api/interceptors/pretty_dio_logger.dart';
import 'package:project/app/configs/api_endpoints.dart';
import 'package:project/app/storage/storage_const.dart';
import 'package:project/app/view/dialogs/toast.dart';
import 'package:project/features/auth/domain/repositories/token_repository.dart';
@Razhan
Razhan / debounce.kt
Created November 18, 2022 02:36 — forked from faruktoptas/debounce.kt
Kotlin coroutine debounce for EditText
fun <T> debounce(
waitMs: Long = 300L,
scope: CoroutineScope,
destinationFunction: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
debounceJob?.cancel()
debounceJob = scope.launch {
delay(waitMs)
class MenuViewModel {
val coffeeList: LiveData<List<Coffee>> = liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
// if the data needs to be processed before displaying,
// this is where I usually do it
menuRepo.menu.collect(::emit)
}
}
class MenuRepository {
private val menuChannel = BroadcastChannel<List<Coffee>>(CONFLATED)
@Razhan
Razhan / Promise.kt
Created July 15, 2019 11:47 — forked from exallium/Promise.kt
Quick and dirty Promise in Kotlin
sealed class Either<out L, out R> {
data class Left<out L>(val l: L) : Either<L, Nothing>()
data class Right<out R>(val r: R) : Either<Nothing, R>()
}
fun asdf() {
val p = Promise<Int> { resolve, reject ->
resolve(Either.Left(4))
}
@Razhan
Razhan / build.gradle
Created April 4, 2019 07:38 — forked from KenVanHoeylandt/build.gradle
Gradle auto-installing pre-commit hook
apply from: rootProject.file('gradle/install-git-hooks.gradle')
@Razhan
Razhan / Async.kt
Created December 21, 2018 06:24 — forked from SUPERCILEX/Async.kt
Google Play Services Tasks API with Kotlin Coroutines support
suspend fun <T> Task<T>.await(): T {
if (isComplete) return if (isSuccessful) result else throw exception!!
return suspendCoroutine { c: Continuation<T> ->
addOnSuccessListener { c.resume(it) }
addOnFailureListener { c.resumeWithException(it) }
}
}
fun <T> Deferred<T>.asTask(): Task<T> {
val source = TaskCompletionSource<T>()
public suspend inline fun <T : Closeable?, R> T.useCancellably(
crossinline block: (T) -> R
): R = suspendCancellableCoroutine { cont ->
cont.invokeOnCancellation { this?.close() }
cont.resume(use(block))
}
@Keep
internal class LoggingHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler),
CoroutineExceptionHandler {
override fun handleException(context: CoroutineContext, exception: Throwable) {
Crashlytics.logException(exception)
// Since we don't want to crash and Coroutines will call the current thread's handler, we
// install a noop handler and then reinstall the existing one once coroutines calls the new
// handler.
Thread.currentThread().apply {
@Razhan
Razhan / DataBindingHelper.java
Created December 20, 2018 10:05 — forked from yhirano/DataBindingHelper.java
My DataBindingHelper for Android.
package your.project.view.helper;
import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;