Skip to content

Instantly share code, notes, and snippets.

View yongjhih's full-sized avatar
🏠
Working from home

Andrew Chen yongjhih

🏠
Working from home
View GitHub Profile
@kazukinr
kazukinr / LifecycleScopeObserver.kt
Last active December 26, 2022 11:43
A sample to manage CoroutinesScope with android lifecycle for ViewModel.
package com.github.kazukinr.android.ui.sample
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import java.io.Closeable
{
"@@locale": "es",
"helloWorld": "Hola Mundo",
"hello": "Hola $world",
"greeting": "$hello $world"
"helloWorlds": "{count,plural, =0{Hola}=1{Hola mundo}=2{Hola dos mundos}few{Hola {count} mundos}many{Hola todos {count} mundos}other{Hola otros {count} mundos}}",
}
{
"@@locale": "en",
"helloWorld": "Hello World",
"@helloWorld": {
"description": "The conventional newborn programmer greeting"
},
"hello": "Hello {world}",
"@hello": {
@yrom
yrom / main.dart
Created August 1, 2019 11:37
calculate fps in flutter app
var orginalCallback;
void main() {
runApp(...);
orginalCallback = window.onReportTimings;
window.onReportTimings = onReportTimings;
}
const maxframes = 60;
final lastFrames = ListQueue<FrameTiming>(maxframes);
// ignore_for_file: public_member_api_docs
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';
/// A provider that exposes a [ValueNotifier] in two independent pieces.
///
/// [StoreProvider] will expose both [ValueNotifier] and [ValueNotifier.value] independently
/// to its dependents.
@RBusarow
RBusarow / TestCoroutineExtension.kt
Last active November 20, 2023 19:03
A JUnit 4 Rule and JUnit 5 Extension for utilizing TestCoroutineDispatcher and TestCoroutineScope from kotlinx.coroutines-test
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
@truongsinh
truongsinh / build.gradle.diff
Last active December 25, 2019 01:55
step 3
diff --git a/app/build.gradle b/app/build.gradle
index d1b7792..dd96f56 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -47,3 +47,15 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
+
+
@volodia-chornenkyy
volodia-chornenkyy / OwnPushService.java
Created April 1, 2019 21:23
Handling of multiple FirebaseMessagingService
public class OwnPushService extends FirebaseMessagingService {
private List<FirebaseMessagingService> messagingServices = new ArrayList<>(2);
public GCPushService() {
messagingServices.add(new AirshipFirebaseMessagingService());
messagingServices.add(new TLFirebaseMessagingService());
}
@reuniware
reuniware / AESEncryptDecrypt.kt
Last active December 8, 2024 17:06
(Android/Kotlin) Encrypt and Decrypt with AES algorithm, and save/restore Secret Key and Inizialization Vector in SharedPreferences
fun encrypt(context:Context, strToEncrypt: String): ByteArray {
val plainText = strToEncrypt.toByteArray(Charsets.UTF_8)
val keygen = KeyGenerator.getInstance("AES")
keygen.init(256)
val key = keygen.generateKey()
saveSecretKey(context, key)
val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
cipher.init(Cipher.ENCRYPT_MODE, key)
val cipherText = cipher.doFinal(plainText)
fun <T> Class<Any>.invoke(methodName: String , vararg args: Pair<Class<*>, *>): T? {
return try {
getMethod(methodName, *(args.map { it.first }.toTypedArray()))
?.invoke(this, *(args.map { it.second }.toTypedArray())) as? T
} catch (e: Throwable) {
e.printStackTrace()
null
}
}