Skip to content

Instantly share code, notes, and snippets.

View hoc081098's full-sized avatar
✝️
Glory to God

Petrus Nguyễn Thái Học hoc081098

✝️
Glory to God
View GitHub Profile
@hoc081098
hoc081098 / MainActivity.kt
Created March 30, 2024 19:30
MainActivity.kt
package com.example.roomdb;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
package com.example.roomdb;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
private void API_Get_List() {
ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
executor.execute(new Runnable() {
@Override
public void run() {
final StringRequest request = new StringRequest(Request.Method.POST,
@hoc081098
hoc081098 / MainActivity.kt
Created March 30, 2024 16:38
MainActivity.kt
package com.example.roomdb;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import 'dart:async';
extension SplitExtension<T> on Stream<T> {
Stream<T> split() {
final controllers = <MultiStreamController<T>>[];
var index = -1;
var done = false;
StreamSubscription<T> subscription;
return Stream.multi(
import android.app.Activity
import androidx.annotation.MainThread
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import arrow.core.Either
import arrow.core.getOrHandle
import arrow.core.left
import arrow.core.right
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
public class ChannelsEventBus {
private val _channels = hashMapOf<KClass<*>, Channel<Any>>()
private fun createChannel(key: KClass<*>) = synchronized(this) { _channels.getOrPut(key) { Channel(Channel.UNLIMITED) } }
public fun send(event: Any): Unit = createChannel(event::class).trySend(event).let { }
@Suppress("UNCHECKED_CAST")
public fun <T : Any> receiveAsFlow(type: KClass<T>): Flow<T> = flow {
createChannel(type)
import androidx.annotation.MainThread
import com.st.android.showcase.ui.extension.debugCheckImmediateMainDispatcher
import java.io.Closeable
import javax.inject.Inject
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.onFailure
import kotlinx.coroutines.channels.onSuccess
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.receiveAsFlow
@hoc081098
hoc081098 / flatMapFirst.kt
Created May 16, 2020 16:21
exhaustMap, flatMapFirst for Kotlin Coroutines Flow, RxJava 3 | kotlin flow flatmapfirst
import io.reactivex.rxjava3.annotations.CheckReturnValue
import io.reactivex.rxjava3.core.BackpressureStrategy
import io.reactivex.rxjava3.core.Observable
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
@CheckReturnValue
inline fun <T : Any, R : Any> Observable<T>.exhaustMap(crossinline transform: (T) -> Observable<R>): Observable<R> {
suspend fun upload(uri: Uri) {
val contentResolver = applicationContext.contentResolver
val bytes = contentResolver
.openInputStream(uri)
?.use { inputStream -> inputStream.buffered().use { it.readBytes() } }
checkNotNull(bytes)
val type = contentResolver.getType(uri)
checkNotNull(type)