Skip to content

Instantly share code, notes, and snippets.

View cdmunoz's full-sized avatar

Carlos Daniel cdmunoz

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@cdmunoz
cdmunoz / build.gradle
Created March 16, 2020 03:31
Navigation component, Bottom Nav View and Fragment Container
def nav_version_ktx = "2.3.0-alpha01"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version_ktx"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version_ktx"
def material_version = "1.1.0"
implementation "com.google.android.material:material:$material_version"
def fragment_version = "1.2.2"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
@cdmunoz
cdmunoz / MaxInversions.kt
Created March 12, 2020 15:44
Solution to Hackerrank's Max Inversions problem
// Complete the maxInversions function below.
fun maxInversions(prices: Array<Int>): Long {
var inversionsCounter = 0L
val arraySize = prices.size
for (i in 0 until arraySize - 1) {
var smaller = 0 //smaller elements on right
for (j in i + 1 until arraySize) {
if (prices[i] > prices[j]) {
smaller++
@cdmunoz
cdmunoz / StockOpenClose.kt
Created March 12, 2020 15:43
Solution to Hackerrank's Stock Open/Close Problem
package vanhack
import com.google.gson.Gson
import java.io.File
import java.io.InputStreamReader
import java.time.LocalDate
import java.time.Month
import java.time.format.DateTimeFormatter
import java.util.*
@RunWith(AndroidJUnit4ClassRunner::class)
class MyUITestWithIdlingResourcesRuleTest {
... //some variable def
@get:Rule
val activityRule = ActivityScenarioRule(MyMainActivity::class.java)
//this line replaces the registration/deregistration within @Before/@After methods
@get:Rule
val espressoIdlingResourceRule = MyEspressoIdlingResourceRule()
class MyEspressoIdlingResourceRule: TestWatcher() {
private val idlingResource = EspressoIdlingResource.countingIdlingResource
override fun starting(description: Description?) {
IdlingRegistry.getInstance().register(idlingResource)
super.starting(description)
}
override fun finished(description: Description?) {
IdlingRegistry.getInstance().unregister(idlingResource)
@RunWith(AndroidJUnit4ClassRunner::class)
class MyUITestWithIdlingResourcesTest {
... //some variable def
@get:Rule
val activityRule = ActivityScenarioRule(MyMainActivity::class.java)
@Before
fun setup() {
//register idling resource
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
@cdmunoz
cdmunoz / gist:ad2b8f58f73edad10f353c5bbf5ffc95
Last active January 3, 2020 20:38
MediatorLiveData Ejemplo
private int totalCallRequestCount = 0;
private int totalCallResponseCount = 0;
private void setupLiveDataMerger() {
processFinishedSuccessfullyLiveData = new MediatorLiveData<>();
processFinishedSuccessfullyLiveData.addSource(userInfoLiveData, new Observer<Person>() {
@Override
public void onChanged(@Nullable Person person) {
totalCallResponseCount++;
setProcessFinishedSuccessfully();
@cdmunoz
cdmunoz / Turnstile.kt
Last active February 5, 2024 03:56
Turnstile hackerrank's problem solution
fun getTimes(times: Array<Int>, directions: Array<Int>): Array<Int> {
val result: Array<Int> = Array(times.size) { 0 }
val endTime: Int = times.max() ?: 0
if (endTime == 0) return result
val inQueue: Queue<Int> = LinkedList()
val outQueue: Queue<Int> = LinkedList()
var currentIndex = 0
var turnstile = 0
class MyAppFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
//the logic here
}
override fun onNewToken(token: String) {
//all the logic of the old FirebaseInstanceIdService.onTokenRefresh() here
//usually, to send to the app server the instance ID token
sendTokenToTheAppServer(token)