Skip to content

Instantly share code, notes, and snippets.

View christianb's full-sized avatar

Christian Bunk christianb

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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()
val matrix = Matrix()
val srcIndex = 0
val dstIndex = 0
val pointCount = 4 // or any other number of points you wanna transform
/**
* Set the matrix such that the specified src points would map to the specified dst points. The
* "points" are represented as an array of floats, order [x0, y0, x1, y1, ...], where each
* "point" is 2 float values.
*/
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
defaultConfig {
applicationId "samples.linhtruong.com.ui_reactive_rxjava_realm"
minSdkVersion versions.minSdk
@christianb
christianb / thread-looper-handler.kt
Last active June 1, 2019 20:16
How to create a Thread with an Looper, called by a Handler
// Understanding Handler and Looper in Android
// by Rahul Rastogi
// https://medium.com/@rastogi.tech/understanding-handler-and-looper-in-android-c6fa673c6822
var handler: Handler? = null
Thread {
Looper.prepare() // Creating a Looper for this thread.
// Creating a Handler for given Looper object.