Skip to content

Instantly share code, notes, and snippets.

View houssemzaier's full-sized avatar

Houssem Zaier houssemzaier

View GitHub Profile
@houssemzaier
houssemzaier / Test2.kt
Created July 29, 2020 12:12
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//Your task is to split the chocolate bar of given dimension n x m into small squares.
//Each square is of size 1x1 and unbreakable. Implement a function that will return minimum number of breaks needed.
//
//For example, if you are given a chocolate bar of size 2 x 1 you can split it to single squares in just one break, but for size 3 x 1 you must perform two breaks.
//
//If input data is invalid you should return 0 (as in no breaks are needed if we do not have any chocolate to split). Input will always be a non-negative integer.
fun breakChocolate(n: Int, m: Int): Int = if ((n in 0..1) && (m in 0..1)) {
0
@houssemzaier
houssemzaier / Test3.kt
Created July 29, 2020 12:11
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
fun getMiddle(word: String): String {
val middleIndex = word.length / 2
return if (word.length.isEven()) {
word.substring((middleIndex - 1)..middleIndex)
} else {
word[middleIndex].toString()
}
package fr.francetv.francetvsport.arch.presentation.main.navigations
import java.io.IOException
import java.util.*
import java.util.stream.Collectors
object GroupByDemoInJava8 {
@Throws(IOException::class)
@JvmStatic
package fr.francetv.francetvsport.arch.presentation.base
import android.view.View
import android.widget.Toast
class DebouncingOnClickListener(
private val intervalMillis: Long,
private val doClick: ((View) -> Unit)
) : View.OnClickListener {
private var enabled = true
@houssemzaier
houssemzaier / main.kt
Created July 26, 2018 21:13
This sample shows replayed response (that could have a param) from an Observable Subject used like a proxy between the client and original Observable
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import java.util.*
fun main(args: Array<String>) {
val vm = VM(Repo())
vm.observableData.subscribe {
println("from sub1 $it")
}
Thread.sleep(3333)
@houssemzaier
houssemzaier / ApiResponse.java
Created May 4, 2018 15:02 — forked from AkshayChordiya/ApiResponse.java
LiveData adapter for Retrofit
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@houssemzaier
houssemzaier / ApiResponse.java
Created May 4, 2018 15:02 — forked from AkshayChordiya/ApiResponse.java
LiveData adapter for Retrofit
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@houssemzaier
houssemzaier / sample_dsl_with_kotlin.kt
Last active November 21, 2017 12:23
sample dsl with kotlin
package com.example.hzaier.myapplicationkt.dsl
import org.junit.Test
interface Matcher<T> {
fun test(lhs: T)
infix fun or(other: Matcher<T>): Matcher<T> = object : Matcher<T> {
override fun test(lhs: T) {
@houssemzaier
houssemzaier / TestLogin.java
Created September 21, 2017 15:39 — forked from lparoli/TestLogin
Class example for testing a Login screen using Screen Object Pattern & JUnit4.
package qa.com.espressospoonstructure.tests;
import org.junit.Test;
import qa.com.espressospoonstructure.screenObjects.LoginScreen;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
public class TestLoginScreen extends BaseTestCase<MainActivity> {
@houssemzaier
houssemzaier / LoginScreen.java
Last active September 21, 2017 09:19 — forked from lparoli/LoginScreen
Screen Object Pattern class example
package qa.com.espressospoonstructure.screenObjects;
import android.support.test.espresso.ViewInteraction;
import org.hamcrest.Matcher;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.scrollTo;