Skip to content

Instantly share code, notes, and snippets.

View mahdiPourkazemi's full-sized avatar

Mahdi Pourkazemi mahdiPourkazemi

View GitHub Profile
@schlamar
schlamar / processify.py
Last active June 11, 2024 12:46
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
// Short way to collect StateFlow on coroutine when Activity Started.
// Useful when you need to collect one StateFlow, but could be used for many.
fun <T> StateFlow<T>.collectIt(lifecycleOwner: LifecycleOwner, function: (T) -> Unit) {
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
collect {
function.invoke(it)
}
}
}

OTP Viewer for Jetpack compose

Variables

val requesterList: ArrayList<FocusRequester>  = arrayListOf()
val textList: ArrayList<MutableState<TextFieldValue>> = arrayListOf()
var lastIndex = -1

for (i in 0 until count){
    // Add string mutableStateOf variables to the input count