Skip to content

Instantly share code, notes, and snippets.

View omkar-tenkale's full-sized avatar
☸️
Planning

Omkar Tenkale omkar-tenkale

☸️
Planning
View GitHub Profile
import java.lang.Exception
import kotlin.concurrent.thread
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
fun main() {
// Compiler generates a new class that contains the suspendingLambda
class Continuation1(val previousContinuation: Continuation<Double>) : Continuation<Unit> {
suspend fun calculateSquareRoot(number: Double): Double {
val block: (Continuation<Double>)->Any? = {
// Wait for result in current thread
kotlin.math.sqrt(number)
}
return suspendCoroutineUninterceptedOrReturn(block)
}
public interface Continuation<in T> {
// A map like data structure to hold data carried by the continuation
public val context: CoroutineContext
// Called to complete the unfinished execution
public fun resumeWith(result: Result<T>)
}
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.createCoroutineUnintercepted
fun launch(block: suspend () -> Unit) {
val callback = object : Continuation<Unit> {
override val context: CoroutineContext = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {}
}
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.createCoroutineUnintercepted
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
fun main() {
// Compiler generates a new class that contains the suspendingLambda
class Continuation1(val previousContinuation: Continuation<String>) : Continuation<Unit> {
override val context = previousContinuation.context
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.createCoroutineUnintercepted
fun main() {
// Define a suspend lambda that returns "Hello World!"
val suspendingLambda: suspend () -> String = suspend {
"Hello World!"
}
@omkar-tenkale
omkar-tenkale / ControlledExplosion.kt
Last active April 6, 2024 04:43
Compose Explosion Animation Snippets
@Composable
fun ControlledExplosion() {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
var progress by remember { mutableStateOf(0f) }
Explosion(progress)

This is a draft, a note to myself to understand dagger

Understanding Dagger2

It all starts with a messy code, or its early realization if your're well prepared As projects starts to become large, they will have lots of classes referencing lots of dependencies

Retrofit instance, logger instance, DB instance, SharedPreferenceManager instance Generally we declare them singleton and move on, accessing them directly This is fine in the beginning but it hampers testability in long term as those singletons are hard to mock

@omkar-tenkale
omkar-tenkale / build.gradle
Created November 15, 2022 09:53
Change gradle android apk name
android{
...
def changeApkName = { variant ->
variant.outputs.each { output ->
def apk = output.outputFile;
def addBrand = true
def addTime = false
def addGitBranch = true
def addVersionCode = true
def addVersionName = true
@omkar-tenkale
omkar-tenkale / build.gradle
Created November 15, 2022 09:51
Gradle keystore configuration
apply plugin: ...
def debugKeystorePropertiesFile = rootProject.file("env/debug-keystore.properties");
def debugKeystoreProperties = new Properties()
debugKeystoreProperties.load(new FileInputStream(debugKeystorePropertiesFile))
def releaseKeystorePropertiesFile = rootProject.file("env/release-keystore.properties");
def releaseKeystoreProperties = new Properties()
if(releaseKeystorePropertiesFile.exists()) {
releaseKeystoreProperties.load(new FileInputStream(releaseKeystorePropertiesFile))