Skip to content

Instantly share code, notes, and snippets.


Konstantin terrakok

View GitHub Profile
View SimpleDividerDecorator.kt
* Created by Konstantin Tskhovrebov (aka @terrakok) on 25.08.17.
class SimpleDividerDecorator(
private val dividerSizePx: Int,
dividerColor: Int
) : RecyclerView.ItemDecoration() {
private val paint = Paint().apply { color = dividerColor }
View SmartField.kt
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
* Created by Konstantin Tskhovrebov (aka @terrakok) on 18.09.17.
class SmartField<T: Any>(
private val editText: EditText,
View Extension.kt
fun Resources.color(colorRes: Int) =
if (Build.VERSION.SDK_INT >= 23) {
this.getColor(colorRes, null)
} else {
fun ViewGroup.inflate(@LayoutRes layoutRes: Int, attachToRoot: Boolean = false): View {
return LayoutInflater.from(context).inflate(layoutRes, this, attachToRoot)
View MoxyMapFragment.kt
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.arellomobile.mvp.MvpDelegate
View KotlinBase64.kt
private const val BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
private val BASE64_INVERSE_ALPHABET = IntArray(256) { BASE64_ALPHABET.indexOf(it.toChar()) }
fun String.encodeBase64(): String = String(encodeBase64ToByteArray())
fun String.encodeBase64ToByteArray(): ByteArray = encodeToByteArray().encodeBase64()
fun ByteArray.encodeBase64ToString(): String = String(encodeBase64())
fun String.decodeBase64(): String = String(decodeBase64ToByteArray())
terrakok / NanoRedux.kt
Created Sep 13, 2020
Very lighweight and simple redux implementation for android apps.
View NanoRedux.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import timber.log.Timber
interface State
interface Action
interface Effect
interface Screen<T : State> {
terrakok / AndroidBaseFragment.kt
Last active Sep 14, 2020
Android fragment with real lifecycle
View AndroidBaseFragment.kt
import android.os.Bundle
import androidx.annotation.LayoutRes
open class BaseFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLayoutId) {
protected lateinit var runId: String
private set
private var instanceStateSaved: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) {
View CurlLoggingInterceptor.kt
* Copyright (C) 2016 Jeff Gilfelt.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software