Skip to content

Instantly share code, notes, and snippets.

View ultraon's full-sized avatar

Vitalii ultraon

View GitHub Profile
/// Pack For XCode
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
@AlexGladkov
AlexGladkov / Coroutines + Rx.swift
Last active December 16, 2020 08:50
Coroutines + Rx (Multiplatform + iOS Native)
import LMCustomerSDK // Your Kotlin Multiplatform Library
import RxSwift
struct RxAsyncResult<ResultElement: AnyObject> {
#if targetEnvironment(simulator)
let async: AsyncResult<ResultElement>
#else
let async: AsyncResult
#endif
@OleksandrKucherenko
OleksandrKucherenko / build.gradle
Last active April 11, 2022 21:06
repack AAR with different types of compatibility things, like: androidx vs support library, include/exclude/repackage aar during compilation
/** Copyright: 2019-*, Oleksandr Kucherenko (olku@artfulbits.se) */
apply plugin: 'com.android.library'
android {
/* ... default android lib OR app configuration ... */
}
configurations {
repack { transitive = false }
compatibility { transitive = false }
fun main(args: Array<String>) {
println("a" to "b")
println("a" to "b" tre "c")
println("a" to "b" tre "c" fo "d")
println("a" to "b" tre "c" fo "d" fi "e")
println("a" to "b" tre "c" fo "d" fi "e" sik "f")
println("a" to "b" tre "c" fo "d" fi "e" sik "f" seva "g")
}
infix fun <A, B, C> Pair<A, B>.tre(c: C) = Triple(first, second, c)
@hrach
hrach / channel.kt
Last active May 24, 2021 08:52
Kotlin Channels Debounce & Throttle
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.channels.produce
import kotlin.coroutines.experimental.CoroutineContext
fun <E> ReceiveChannel<E>.debounce(
wait: Long = 50,
context: CoroutineContext = DefaultDispatcher
): ReceiveChannel<E> = produce(context) {
@imminent
imminent / ClickActors.kt
Created November 25, 2017 18:36
Kotlin actor extensions for Android listeners
/**
* MIT License
*
* Copyright (c) 2017 Dandré Allison
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@elizarov
elizarov / Example.kt
Last active September 21, 2019 16:15
// https://akarnokd.blogspot.ru/2017/09/rxjava-vs-kotlin-coroutines-quick-look.html
import kotlinx.coroutines.experimental.*
suspend fun f1(i: Int): Int {
Thread.sleep(if (i != 2) 2000L else 200L)
return 1
}
suspend fun f2(i: Int): Int {
Thread.sleep(if (i != 2) 2000L else 200L)
@koral--
koral-- / build.gradle
Last active December 12, 2017 01:31
testApt to testAnnotationProcessor migration, workaround for issue: https://code.google.com/p/android/issues/detail?id=224272
android.applicationVariants.all {
def aptOutputDir = new File(buildDir, "generated/source/apt/${it.unitTestVariant.dirName}")
it.unitTestVariant.addJavaSourceFoldersToModel(aptOutputDir)
}
@gtomek
gtomek / IoUtilsWithOkIo.java
Created February 10, 2016 10:55
Read files with Okio
/**
* Utils for I/O operations.
* <p/>
* Created by Tomek on 09/06/15.
*/
public class IoUtils {
/**
* Reads file and returns a String.
*