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
<?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>
@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);
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 / 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
@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 / 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}
*
interface EnumWithKey<T, K> {
val T.key: K
}
/*
* The reified type parameter lets you call the function without explicitly
* passing the Class-object.
*/
inline fun <reified T : Enum<T>, R> EnumWithKey<T, R>.byKey(key: R): T? {
return enumValues<T>().find { it.key == key }
@FrancescoJo
FrancescoJo / spring-jpa-disable-automatic-method-derivation.kt
Last active June 5, 2019 09:13
How to disable spring-jpa automatic method derivation
interface UserRepository : JpaRepository<User, Long>, UserRepositoryExtension
interface UserRepositoryExtension {
/*
* Here we get exception as following:
*
* Caused by: java.lang.IllegalArgumentException: Failed to create query for method
* public abstract User UserRepositoryExtension.getByRoleCriteria(java.lang.String,java.util.Set)!
* At least 2 parameter(s) provided but only 1 parameter(s) present in query.
*
@FrancescoJo
FrancescoJo / AnimalClassfication.java
Last active June 27, 2019 01:01
An example to demonstrate animal classification system in Java 1.8.x.
class Animal { }
class Reptile extends Animal { }
class Bird extends Animal { }
interface MobileLife {
// Every classes derived from this interface should implement common features on it.
void move(double displacement);
double getDistance();
@FrancescoJo
FrancescoJo / AnimalClassfication.dart
Created June 17, 2019 13:38
An example to demonstrate animal classification system in Dart 2.x.
class Animal { }
class Reptile extends Animal { }
class Bird extends Animal { }
mixin MobileLife {
// We don't need to implement _move on every classes using this mixin, since mixin can include state.
var _distance = 0.0;
void _move(double displacement) {