Skip to content

Instantly share code, notes, and snippets.

View dpmedeiros's full-sized avatar

Daniel Medeiros dpmedeiros

View GitHub Profile
@dpmedeiros
dpmedeiros / Speed.kt
Last active February 12, 2020 19:55
A Kotlin class that embodies data rate. Provides methods to convert data rates from one unit to another as well as to a smallest value rounded data rate.
/**
* Units of speed
*/
enum class SpeedUnits {
BITS_PER_SEC { override fun toString(): String = "Bits/s" },
BYTES_PER_SEC { override fun toString(): String = "Bytes/s" },
KBITS_PER_SEC { override fun toString(): String = "KBits/s" },
MBITS_PER_SEC { override fun toString(): String = "MBits/s" }
}
@dpmedeiros
dpmedeiros / BlockingCallUtils.kt
Created October 4, 2019 20:53
Utility functions to transform asynchronous rxjava and callback-invoking methods into blocking calls
package com.dmedeiros.rx.utils
import rx.Completable
import rx.Single
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executors
import java.util.concurrent.ThreadFactory
import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.atomic.AtomicInteger
@dpmedeiros
dpmedeiros / ActivityResultRequester.kt
Created February 14, 2018 17:59
Extends Activity class to allow a caller to request a result from another activity and get notified via a callback.
package com.dpmedeiros.android.util
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.IntentSender
import android.support.annotation.MainThread
/**
* Extensions to Android's Activity class allowing a caller to request a result from another activity and get notified
@dpmedeiros
dpmedeiros / AndroidMockUtil.java
Last active January 28, 2021 06:26
Mock main thread handler for use in Android unit tests (requires Mockito and PowerMock)
package com.dpmedeiros.androidtestsupportlibrary;
import android.os.Handler;
import android.os.Looper;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import java.util.concurrent.Executors;