Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View houssemzaier's full-sized avatar

Houssem Zaier houssemzaier

View GitHub Profile
@houssemzaier
houssemzaier / OperatorFlowOnTest.kt
Last active September 30, 2022 12:01
onEach and flowOn
package fr.x
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import org.junit.Test
@houssemzaier
houssemzaier / TestSomeBehaviorSharedFlow.kt
Last active July 17, 2022 20:48
TestSomeBehaviorSharedFlow
package com.ankorstore.account.presentation
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Test
@houssemzaier
houssemzaier / SticktModeUtil.kt
Created February 9, 2020 22:23
This solution gives the possibility to just hide the "android.os.strictmode.UntaggedSocketViolation" or just log it in a verbose lever, which I prefer.
@RequiresApi(Build.VERSION_CODES.P)
fun StrictMode.VmPolicy.Builder.detectAllExpect(ignoredViolationPackageName: String, justVerbose: Boolean = true): StrictMode.VmPolicy.Builder {
return detectAll()
.penaltyListener(Executors.newSingleThreadExecutor(), StrictMode.OnVmViolationListener
{
it.filter(ignoredViolationPackageName, justVerbose)
})
}
package com.bravedroid.connecta.presentation.main
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import kotlin.properties.ReadOnlyProperty
@houssemzaier
houssemzaier / Coroutines.kt
Created November 5, 2020 19:09
Pushing data to one Flow from two twoCoroutines (Senders) and dispatching the received data to 2 receivers (collectors) that are collecting from one sharedFlow (dispatcher)
package fr.francetv.francetvsport.arch.application
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collect
fun main() = runBlocking {
@houssemzaier
houssemzaier / Main3.kt
Created September 7, 2020 17:49
Without unit Testing just run as jvm console app
package com.raywenderlich.kotlin.coroutines
import androidx.arch.core.executor.ArchTaskExecutor
import androidx.arch.core.executor.TaskExecutor
import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
@ExperimentalCoroutinesApi
class Main3 {
@houssemzaier
houssemzaier / Main3.kt
Created September 6, 2020 23:03
synchronized data observed with a Page sealed class pattern
package com.raywenderlich.kotlin.coroutines
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.setMain
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
@houssemzaier
houssemzaier / TestingLifeCycleEffectCancelingParent.kt
Last active September 2, 2020 20:04
Testing Effect on children When Canceling Parent job
package fr.francetv.francetvsport.arch.presentation.videodetail
import kotlinx.coroutines.*
fun main() = runBlocking {
val parentJob = launch {
launch {
println("start launch child")
while (isActive) {
delay(500)
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() {
runBlocking {
val doIt1 = doIt1()
val doIt2 = doIt2()
val doIt3 = doIt3()
println("result ${doIt1 + doIt2 + doIt3}")
@houssemzaier
houssemzaier / Test1.kt
Created July 29, 2020 12:12
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N.
fun find(integers: Array<Int>): Int {
var outlierInteger: Int = 0
val oddIntegers = mutableListOf<Int>()
val evenIntegers = mutableListOf<Int>()
var i = 0
while (i <= integers.lastIndex) {
val integer = integers[i]
if (integer.isEven()) {