This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/// View model protocol | |
protocol ViewModel: ObservableObject { | |
var count: Int { get } | |
func increase() | |
} | |
/// Concrete implementation | |
class MyViewModel: ViewModel { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Common | |
const val RESOURCE_PATH = "./src/commonTest/resources" | |
expect class Resource(name: String) { | |
val name: String | |
fun exists(): Boolean | |
fun readText(): String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.test.TestCoroutineDispatcher | |
import kotlinx.coroutines.test.TestCoroutineScope | |
import kotlinx.coroutines.test.resetMain | |
import kotlinx.coroutines.test.setMain | |
import org.junit.jupiter.api.extension.AfterAllCallback | |
import org.junit.jupiter.api.extension.AfterEachCallback | |
import org.junit.jupiter.api.extension.BeforeAllCallback | |
import org.junit.jupiter.api.extension.ExtendWith | |
import org.junit.jupiter.api.extension.ExtensionContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified F : Fragment> createFakeFragmentInjector(crossinline block : F.() -> Unit) | |
: DispatchingAndroidInjector<Any> { | |
val myApp = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as MyApp | |
val originalDispatchingActivityInjector = myApp.dispatchingActivityInjector | |
var originalFragmentInjector: AndroidInjector<Any>? = null | |
val fragmentInjector = AndroidInjector<Fragment> { fragment -> | |
originalFragmentInjector?.inject(fragment) | |
if (fragment is F) { | |
fragment.block() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KeyStore keyStore = KeyStore.getInstance("PKCS12"); | |
FileInputStream clientCertificateContent = new FileInputStream("/path/to/publicAndPrivateKey.p12"); | |
keyStore.load(clientCertificateContent, "private key password".toCharArray()); | |
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); | |
keyManagerFactory.init(keyStore, "private key password".toCharArray()); | |
FileInputStream myTrustedCAFileContent = new FileInputStream("/path/to/embedded/CA-Chain.pem"); | |
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); | |
X509Certificate myCAPublicKey = (X509Certificate) certificateFactory.generateCertificate(myTrustedCAFileContent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
let xml = "<coord2 count=\"3\">" | |
+ "<markers>" | |
+ "<marker>" | |
+ "<item>marker1</item>" | |
+ "</marker>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OkHttpClient okHttpClient = new OkHttpClient(); | |
try { | |
int cacheSize = 10 * 1024 * 1024 // 10 MiB | |
Cache cache = new Cache(getCacheDir(), cacheSize); | |
okHttpClient.setCache(cache); | |
} catch (IOException e) { | |
Log.e(TAG, "Could not set cache", e); | |
} | |
// Forces cache. Used for cache connection |