Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / BindableRecyclerView.kt
Created January 28, 2019 18:20
BindableRecyclerView for Kotlin
abstract class BindableAdapter<TYPE : MultiType>(private val list: MutableList<TYPE>) : RecyclerView.Adapter<BindableViewHolder<TYPE>>() {
override fun onBindViewHolder(
holder: BindableViewHolder<TYPE>,
position: Int
) = holder.bind(list[position])
override fun getItemViewType(position: Int): Int = list[position].type
override fun getItemCount(): Int = list.size
}
@hector6872
hector6872 / Demo.kt
Last active January 25, 2019 20:47 — forked from alexfu/Demo.kt
Making (Android) Spannable great again with Kotlin
val world = "World"
val spannedText = SpannableString("Hello $world!")
spannedText
.spanWith(world) {
what = BackgroundColorSpan(Color.RED)
flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
}
.spanWith(world) {
what = StyleSpan(Typeface.BOLD)
flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
@hector6872
hector6872 / .zshrc
Last active January 11, 2021 14:56
My awesome Zsh prompt
# ALIAS
# =============
alias ..='cd ..'
case `uname` in
Darwin)
alias flushdns='sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say cache flushed'
alias ls='ls -GpF' # Mac OSX specific
alias ll='ls -alGpF' # Mac OSX specific
;;
@hector6872
hector6872 / ParameterizedKotlinTest.kt
Created December 13, 2018 11:09 — forked from rossharper/ParameterizedKotlinTest.kt
Parameterized JUnit4 test example in Kotlin
@RunWith(Parameterized::class)
class KotlinTest(val paramOne: Int, val paramTwo: String) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data() : Collection<Array<Any>> {
return listOf(
arrayOf(1, "I"), // First test: (paramOne = 1, paramTwo = "I")
arrayOf(1999, "MCMXCIX") // Second test: (paramOne = 1999, paramTwo = "MCMXCIX")