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
{
"@@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 January 13, 2023 07:11
(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
}
}
@gilgoldzweig
gilgoldzweig / MockSharedPreference.kt
Last active January 31, 2024 14:33
Mock implementation of shared preference, which just saves data in memory using map.
package com.gilgoldzweig.mvp.preferences
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import java.util.HashMap
import kotlin.collections.set
/**
* Mock implementation of [SharedPreferences], which just saves data in memory using map.
*/
#!/bin/bash
<< ////
The script creates 'licenses' under '$ANDROID_HOME' and creates a file which proves
that the SDK license was accepted by the user.
Please copy this to your own account/gist/server. Every time there's an updated license, update the file with the new
license hash.
Legally if you run this script (or your own version of it), it means YOU accepted the license - don't trust someone else.
The hashes below are supposed to be taken from $ANDROID_HOME/licenses/android-sdk-license on YOUR machine, after you