Skip to content

Instantly share code, notes, and snippets.

View FrancescoJo's full-sized avatar
🤒
Out sick

Hwan Jo FrancescoJo

🤒
Out sick
View GitHub Profile
@FrancescoJo
FrancescoJo / Combinations.kt
Last active February 16, 2019 07:32
Logic to yield all `nCr` combinations
/**
* This logic demonstrates how to draw all nCr combinations from given set.
* The time complexity of this logic is O(n²).
* Actual logic invocations are 1/2((n - 2)² + r(n - 2) + 2), where n > 2.
*
* Imagine selecting 3 different numbers from a set which has 4 different
* numbers. Assume that we've given a set as follows:
*
* let dataSet = {1, 2, 3, 4}
*
@FrancescoJo
FrancescoJo / EvenOddPickGame.kt
Last active June 27, 2018 09:32
Unit testing with JUnit+Mockito vs. Spock. Have a look how Spock usage is concise than traditional JUnit side.
class EvenOddPickGame(private val randomIntGen : RandomValueGenerator<Integer>) {
fun pick(times: Int): List<String> {
return ArrayList<String>().apply {
for (i in 0 until times) {
val rolled = randomIntGen.nextRandom(lowerBound = 1, upperBound = 2) % 2
if (rolled == 0) {
add("EVEN")
} else {
add("ODD")
}
@FrancescoJo
FrancescoJo / AndroidAESCipherHelper.kt
Last active December 3, 2022 20:18
Android AES cipher helper with system generated key. No more static final String key in our class - an approach which is very vulnerable to reverse engineering attack. Available only API Level 23(M)+
import android.annotation.TargetApi
import android.os.Build
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Base64
import timber.log.Timber
import java.security.GeneralSecurityException
import java.security.KeyStore
import javax.crypto.Cipher
import javax.crypto.KeyGenerator
@FrancescoJo
FrancescoJo / SecureSharedPreferences.kt
Last active March 17, 2022 05:32
A SharedPreferences wrapper implementation with encryption/decryption, using CipherHelper implementation.
import android.content.SharedPreferences
/**
* A [android.content.SharedPreferences] wrapper that helps easy reading/writing values.
*
* @author Francesco Jo(nimbusob@gmail.com)
* @since 22 - Mar - 2018
*/
class SecureSharedPreferences(private val sharedPref: SharedPreferences) {
fun contains(key: String) = sharedPref.contains(key)
@FrancescoJo
FrancescoJo / AndroidRsaCipherHelper.kt
Last active July 5, 2023 03:08
Android RSA cipher helper with system generated key. No more static final String key in our class - an approach which is very vulnerable to reverse engineering attack.
import android.os.Build
import android.security.KeyPairGeneratorSpec
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Base64
import timber.log.Timber
import java.math.BigInteger
import java.security.GeneralSecurityException
import java.security.KeyPairGenerator
import java.security.KeyStore
@FrancescoJo
FrancescoJo / proguard_strip_howto.txt
Created February 23, 2017 03:00
How to strip v/d level of logging without any cumbersome jobs with Proguard
use -assumenosideeffects
https://www.guardsquare.com/en/proguard/manual/usage
http://qiita.com/gfx/items/e412dab7f127b7ae44d8
https://github.com/gfx/ProguardRemovesObjectWait
import java.util.regex.Matcher
import java.util.regex.Pattern
// ext makes method callable project wide
ext.getCurrentFlavor = { ->
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern;
@FrancescoJo
FrancescoJo / android_raw_uri_access.java
Created January 4, 2017 03:14
Android raw access via URI
String path = "android.resource://" + context.getPackageName() + "/" + R.raw.raw_resource_id;
Uri rawUri = Uri.parse(path);
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
<!ENTITY appname "WhereDat">
<!ENTITY author "Oded">
]>
<resources>
<string name="app_name">&appname;</string>
<string name="description">The &appname; app was created by &author;</string>
</resources>