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
suspend fun calculateSquareRoot(number: Double): Double {
val block: (Continuation<Double>)->Any? = {
// Wait for result in current thread
kotlin.math.sqrt(number)
}
return suspendCoroutineUninterceptedOrReturn(block)
}
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> {
import kotlin.concurrent.thread
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.createCoroutineUnintercepted
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
fun main() {
// Define a suspend lambda
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!"
}

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 / KeyEvents.java
Created May 29, 2021 08:40
Android KeyEvent with codes in arraylist
public static ArrayList<ArrayList<String>> getKeyEvents() {
return new ArrayList<ArrayList<String>>() {
{
add(new ArrayList<String>() {{
add("UNKNOWN");
add("0");
}});
add(new ArrayList<String>() {{
add("SOFT_LEFT");
@omkar-tenkale
omkar-tenkale / AndroidManifest.xml
Last active November 20, 2022 23:33
android FileUriExposedException fix view file intent crash with fileprovider approach
<provider
android:name=".GenericFileProvider"
android:authorities="${applicationId}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>