Skip to content

Instantly share code, notes, and snippets.

View skinnydoo's full-sized avatar

Ralph Luckernst N., Simelus skinnydoo

View GitHub Profile
@johnkil
johnkil / InitAppUpdateFlow.kt
Created April 25, 2022 15:21
Support in-app updates
private fun initAppUpdateFlow() {
logcat { "check app update" }
val appUpdateManager = AppUpdateManagerFactory.create(this)
lifecycleScope.launch {
try {
appUpdateManager.requestUpdateFlow().collect(::onAppUpdateResult)
} catch (e: InstallException) {
logcat(LogPriority.ERROR) { "Failed to request app update flow\n${e.asLog()}" }
}
}
@marcouberti
marcouberti / gzip.kt
Last active June 3, 2025 06:14
Gzip compression and decompression in Kotlin / Android
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
/**
* Compress a string using GZIP.
*
* @return an UTF-8 encoded byte array.

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

@objcode
objcode / ConcurrencyHelpers.kt
Last active February 19, 2026 14:35
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active August 20, 2025 04:40
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@Tolriq
Tolriq / OkHttpWorkerPool.kt
Created November 14, 2018 13:14
OkHttp coroutine WorkerPool with proper exception handling and suspendCancellableCoroutine support.
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
@Takhion
Takhion / 1_property.kt
Created September 16, 2018 16:23
Kotlin property delegate utils
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
private typealias GetValue<This, R> = (thisRef: This, property: KProperty<*>) -> R
private typealias SetValue<This, R> = (thisRef: This, property: KProperty<*>, value: R) -> Unit
inline fun <This, R> property(
crossinline getValue: GetValue<This, R>
) =
@y-polek
y-polek / doze_mode_adb_commands.sh
Last active September 10, 2025 16:52
adb commands to test Doze mode
#! /bin/zsh
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset
@DaleLaw
DaleLaw / EventBus.kt
Last active November 2, 2023 15:25
Implement EventBus with Kotlin coroutine
object EventBus {
val bus: BroadcastChannel<Any> = BroadcastChannel()
fun send(o: Any) {
launch {
bus.send(o)
}
}
@JoseAlcerreca
JoseAlcerreca / Event.kt
Created April 26, 2018 10:25
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.