Skip to content

Instantly share code, notes, and snippets.

View tieskedh's full-sized avatar
✔️

Thijs de Haan tieskedh

✔️
View GitHub Profile
@3v1n0
3v1n0 / map-string-any-kotlin-serialization-tests.kt
Last active September 25, 2023 18:15
Kotlin Map<String, Any?> (andy Any type in general) (de)serialization tests with both Binary (CBOR) and JSON support
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
import kotlin.reflect.KType
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.full.starProjectedType
@dant3
dant3 / nullable.kt
Created August 4, 2017 12:38
Check if kotlin generic is nullable type
inline fun <reified T> isNullable(): Boolean = null is T
@beyondeye
beyondeye / firebase_coroutine_integration.kt
Created May 27, 2017 20:32
integration of firebase wth kotlin coroutines
/**
* allow to define callback wrappers that are protected from accidental multiple calls to resume/resumeWithException
* Created by daely on 3/30/2017.
*/
class WrappedContinuation<T>(val c: Continuation<T>) : Continuation<T> {
var isResolved = false
override val context: CoroutineContext
get() = c.context
override fun resume(value: T) {
@Miha-x64
Miha-x64 / enums.kt
Last active February 9, 2022 10:00
Enum extensions for Kotlin, superseded by https://github.com/Miha-x64/Kotlin-MPP_Collection_utils
package net.aquadc.common
// Gist: https://gist.github.com/Miha-x64/5f626228b34175f827734596d6701008
import java.util.*
// maps
inline fun <reified K : Enum<K>, V> enumMapOf(): MutableMap<K, V> {
return EnumMap<K, V>(K::class.java)
}
@timyates
timyates / CoRepeat.kt
Last active October 31, 2017 15:11
Repeating Sequences in Kotlin
// Version using experimental co-routines in 1.1 thanks to @voddan on Slack
import kotlin.coroutines.experimental.buildSequence
fun <T> Sequence<T>.repeat() : Sequence<T> = buildSequence {
while(true) yieldAll(this@repeat)
}
fun main(args: Array<String>) {
sequenceOf(1, 2, 3).repeat().take(6).forEach { i -> println(i) }
}
@lynas
lynas / ankoFragment.java
Last active February 18, 2019 15:38
android fragment using anko
class MyFragment: Fragment(){
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return UI {
linearLayout{
editText()
button("OK")
}
}.view
}
}