Skip to content

Instantly share code, notes, and snippets.

Avatar

Jean-Michel Fayard jmfayard

View GitHub Profile
View coroutines.md
View androidstudio-gradle-daemons.sh
# Open a new android project in Android Studio
# From Android Studio, run the gradle task ":properties"
# From the command-line, run
$ ./gradlew :properties
# Check if you see this message
Starting a Gradle Daemon, 1 incompatible could not be reused
# To debug the problem run this
$ ps auxw | grep GradleDaemon
@jmfayard
jmfayard / Config.kt
Last active Sep 22, 2020
Gists Gradle-Kotlin-DSL
View Config.kt
// buildSrc/src/main/kotlin/Config.kt
object Config {
const val ACTIVITY = "com.mautinoa.cardapp.MainActivity"
const val PACKAGE = "com.mautinoa.cardapp"
const val kotlinVersion = "1.2.71"
object SdkVersions {
val versionCode = 1
val compile = 28
val target = 26
@jmfayard
jmfayard / GooglePlay.kt
Created Sep 5, 2018
Custom task with gradle kotlin buildSrc
View GooglePlay.kt
// buildSrc/src/main/java/GooglePlay.kt
import java.io.File
object GooglePlay {
@JvmStatic
fun updateWhatsNew(projectDir: File, version: String) {
val files: List<File> = listOf(
"src/production/play/en-US/listing/whatsnew-alpha",
@jmfayard
jmfayard / app-component-1.kt
Last active Feb 15, 2018
How To Not Use Dagger2
View app-component-1.kt
fun app() = AppComponent.instance
interface AppComponent {
val context: Context
val retrofit: Retrofit
val okHttpClient: OkHttpClient
val catRepository: CatRepository
val catService: CatService
val mainThreadScheduler: Scheduler
View KotlinCovariance.kt
data class Producer<out T : Beverage>(
val beverage: T
) {
fun produce() : T = beverage
}
class Consumer<in T: Beverage> {
fun consume(t: T) = println("Thanks for the drink $t!")
}
View parsePhoneNumber.kt
// https://medium.com/@garnop/safe-concise-text-parsing-with-regex-destructuring-in-kotlin-b8f77ef1e30c
fun parsePhoneNumber(input: String): PhoneNumber {
val invalids = input.filterNot { it in '0'..'9' || it == '-' }
require(invalids.isEmpty()) { "Input $input has invalid characters : $invalids" }
val (areaCode, prefix, lineNumber) = input.split("-").map(String::toInt)
return PhoneNumber(areaCode, prefix, lineNumber)
}
fun main(args: Array<String>) {
View lolcat (.bash_profile)
lolcat() {
FILE="$HOME/.config/androidpackage.txt"
echo "Reading ${FILE}"
export PACKAGE=$( cat ${FILE} )
adb devices
echo pidcat $1 $2 $PACKAGE
sleep 2
pidcat $1 $2 $PACKAGE
}
@jmfayard
jmfayard / README.md
Last active Feb 5, 2021
Gradle Incompatible Daemons HOWTO
View README.md

Add the printProperties task to your build.gradle

Run from both the command-line and intellij the gradle task printProperties

> Task :printProperties
Detecting what could cause incompatible gradle daemons
Run './gradlew printProperties' from the command-line and the same task Android studio
See https://docs.gradle.org/4.5/userguide/build_environment.html
See https://docs.gradle.org/4.5/userguide/gradle_daemon.html#daemon_faq