Skip to content

Instantly share code, notes, and snippets.

View roschlau's full-sized avatar

Robin roschlau

  • Echometer GmbH
  • Ingolstadt, Germany
View GitHub Profile
@roschlau
roschlau / rainbow_brackets.xml
Created November 7, 2018 22:11
Rainbow Brackets Config
<application>
<component name="RainbowSettings">
<option name="darkRoundBracketsColors">
<array>
<option value="0x4f5b62" />
<option value="0x718792" />
<option value="0x8eacbb" />
<option value="0xc1d5e0" />
<option value="0xfefefe" />
</array>
@roschlau
roschlau / dependency.build.gradle
Created March 25, 2019 09:46
Sharing test sources in gradle
configurations {
// Creating testOutput configuration to bundle test dependencies and sources so other projects can depend on them
testOutput.extendsFrom(testCompile)
}
dependencies {
testOutput sourceSets.test.output
}
@roschlau
roschlau / UploadFilesUseCase.kt
Last active May 9, 2020 07:33
Kotlin Coroutines implementation of "More Granular Retry" from https://www.techyourchance.com/concurrency-frameworks-overrated-android/
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.io.File
class UploadFilesUseCase : BaseBusyObservable<UploadFilesUseCase.Listener>() {
interface Listener {
fun onFilesUploaded()
@roschlau
roschlau / AnsiStyles.kt
Created January 16, 2023 17:11
Utility code to style console output
fun styled(style: AnsiStyle, str: String) = style.code + str + AnsiStyle.RESET
interface AnsiStyle {
val code: String
companion object {
const val RESET = "\u001B[0m"
}
}
/**
* Utility function to sort elements by some nested property or another calculated value. Meant to fix JavaScript
* missing a built-in `sortedBy` function like Kotlin has.
* @example
* people.sort(by(person => person.age))
* @param accessor a function that should return the value to sort by if called on an element
*/
export const by: <T>(accessor: (element: T) => string | number) => (a: T, b: T) => number = (accessor) =>
(a, b) => {
const aValue = accessor(a)