Skip to content

Instantly share code, notes, and snippets.

View christianb's full-sized avatar

Christian Bunk christianb

View GitHub Profile
@christianb
christianb / random_number_from_val_property.kt
Last active June 4, 2019 10:08
Things to know about Android/Kotlin
// Looking at vals, delegated properties are not immutable. Remember, val does not imply anything with regards to mutability
// it merely says that the variable/property is read-only
private val aBeautifulNumber: Double
get() = Math.random()
@christianb
christianb / findType.kt
Last active July 28, 2019 22:24
Finds the generic type T in List
/**
* Finds the generic type T in List.
*
* @return first item that is instance of T or null.
*/
inline fun <reified T> List<Any>.findType(): T? {
return find { it is T } as? T
}
@christianb
christianb / MockkMatchers.kt
Created July 30, 2019 15:03
Verify the argument passed to a function are correct using Mockk Matchers
class foo {
fun bar(list: List<Any>)
}
// verifies the list is empty when passed to bar()
verify { foo.bar(match { it.isEmpty() }) }
@christianb
christianb / git-diff-between-tags
Last active November 15, 2019 10:29
Log commits between tags
git log --pretty=oneline tagA..tagB
# or
git lg 1.2.7..master
@christianb
christianb / gist:f6abb7f40a67ae196dd163bfa5b389a2
Last active September 23, 2019 14:40
How to unit testing runnable and handlers
every { handler.removeCallbacks(any()) } returns Unit
every { handler.postDelayed(any(), any()) } answers {
// capture runnable
(this.args[0] as Runnable).run()
true
}
@christianb
christianb / docker_commands.sh
Last active October 9, 2019 21:24
Docker commands
# build with docker compose
docker-compose build
# run with docker-compose and open bash
docker-compose run --rm <image> /bin/bash
# Stop all Docker containers
docker stop $(docker ps -a -q)
@christianb
christianb / Git-unable-to-resolve-reference.txt
Created November 15, 2019 10:25
Git: unable to resolve reference
When you can't checkout a remote branch with Git and getting this error:
“unable to resolve reference” you should do the following:
Try cleaning-up your local repository with:
$ git gc --prune=now
$ git remote prune origin
See: https://stackoverflow.com/questions/2998832/git-pull-fails-unable-to-resolve-reference-unable-to-update-local-ref
@christianb
christianb / when_updating_targetSdkVersion.txt
Created November 22, 2019 16:26
When updating targetSdkVersion?
https://support.google.com/googleplay/android-developer/answer/113469#targetsdk
https://developer.android.com/distribute/best-practices/develop/target-sdk
@christianb
christianb / ConcurrencyHelpers.kt
Created June 13, 2020 21:15 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
@christianb
christianb / constraint_view_min_max.xml
Created July 24, 2020 14:57
Contraint a View Min Max within ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintWidth_min="10dp"