This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
PLUGINS = dict() | |
def register(func): | |
"""Register a function as plug-in""" | |
#add function name and function to dictionary | |
PLUGINS[func.__name__] = func | |
return func | |
#example to put in dictionary | |
@register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import functools | |
def slow_down(func): | |
"""Sleep 1 second before calling the function""" | |
@functools.wraps(func) | |
def wrapper_slow_down(*args, **kwargs): | |
#stop code to play one secend | |
time.sleep(1) | |
#return called functon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def debugger(func): | |
"""Print the functon singnature and return value""" | |
functools.wraps(func) | |
def debugger_wraper(*args,**kwargs): | |
#list of input args | |
args_repr = [repr(a) for a in args] | |
#list of input kwargs | |
kwargs_repr = [f'{k} = {v!r}' for k, v in kwargs.items()] | |
#sum of the input values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import functools | |
def timer(func): | |
"""print the runtime of the decorated function""" | |
functools.wraps(func) | |
def timer_wraper(*args,**kargs): | |
#get time before call func | |
start_time = time.perf_counter() | |
#call func | |
value = func(*args,**kargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
private lateinit var binding: ActivityMainBinding | |
private val activityViewModel: ShearedViewModel by viewModels() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FragmentViewBindingDelegate<T : ViewBinding>( | |
val fragment: Fragment, | |
val viewBindingFactory: (View) -> T | |
) : ReadOnlyProperty<Fragment, T> { | |
private var binding: T? = null | |
init { | |
fragment.lifecycle.addObserver(object : DefaultLifecycleObserver { | |
val viewLifecycleOwnerLiveDataObserver = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PourkazemiMahdi | |
fun <T> StateFlow<T>.collectIt(lifecycleOwner: LifecycleOwner, function: (T) -> Unit) { | |
lifecycleOwner.lifecycleScope.launch { | |
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED){ | |
collect { | |
function.invoke(it) | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am mahdipourkazemi on github. | |
* I am mahdipoori (https://keybase.io/mahdipoori) on keybase. | |
* I have a public key ASBiXDkQwDrOO7xTQ3cQQyQUMy-3NJcY1ItyO4J2O3zBZQo | |
To claim this, I am signing this object: |