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 / txt
Created December 25, 2018 11:01
中央六套1080p版本,有图标(不喜勿下)
辽沈战役
magnet:?xt=urn:btih:44B9E52EB7C80F2C86301E37EC3D3D4EC5A6D70E&dn=%E5%A4%A7%E5%86%B3%E6%88%98%20-%20%E8%BE%BD%E6%B2%88%E6%88%98%E5%BD%B9.1990.1080p.mkv
平津战役
magnet:?xt=urn:btih:7B7BA58AC94A1172402935266BBF226B4F270769&dn=%E5%A4%A7%E5%86%B3%E6%88%98%EF%BC%8D%E5%B9%B3%E6%B4%A5%E6%88%98%E5%BD%B9.1992.1080p.mkv
淮海战役
magnet:?xt=urn:btih:DA1B57C4E3F2ADE990282C813EFF0923AC04EDF7&dn=%E5%A4%A7%E5%86%B3%E6%88%98%EF%BC%8D%E6%B7%AE%E6%B5%B7%E6%88%98%E5%BD%B9.1991.1080p.mkv
@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 {