Skip to content

Instantly share code, notes, and snippets.


py - Pierre Yves Ricau pyricau

View GitHub Profile
pyricau / compare.benchmarks.main.kts
Created September 7, 2023 00:22
A Kotlin script to compare the output of two Macrobenchmark runs, validating the data and computing the confidence interval for a difference between two means
View compare.benchmarks.main.kts
#!/usr/bin/env kotlin
import com.squareup.moshi.Moshi
pyricau /
Last active December 19, 2022 19:13
ClassShot: detect which classes have been loaded at runtime
import android.content.Context;
import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.squareup.haha.perflib.ClassObj;
import com.squareup.haha.perflib.HprofParser;
import com.squareup.haha.perflib.Snapshot;
pyricau / Example.kt
Created June 4, 2021 20:21
A test coroutine dispatcher to reproduce race conditions
View Example.kt
// Here's an example based on a test that was meant to reproduce a race condition,
// where we were launching several coroutines in a specific order without realizing
// that a different order would introduce race conditions. The test code here was used to
// reproduce the exact bad order.
// Note: there are probably better approaches to doing this.
val dispatcher = QueueDelegatingTestDispatcher()
// ... TODO pass in the dispatcher to the tested code launching coroutines
View BadParcelableFix.kt
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.os.Parcel
import android.util.Base64
* This class implements a fix for
* Investigation:
* Usage:
pyricau / WindowSpy.kt
Last active September 15, 2020 20:34
View WindowSpy.kt
import android.annotation.TargetApi
import android.os.Build.VERSION_CODES
import android.view.View
import android.view.Window
object WindowSpy {
* Installs a listener for new [Window] instances. This should only be called once, any new call
* will uninstall the previous listener.
pyricau / AndroidLeaks.kt
Created January 15, 2020 20:45
Fixing a SpellChecker leak in Android M
View AndroidLeaks.kt
* Every editable TextView has an Editor instance which has a SpellChecker instance. SpellChecker
* is in charge of displaying the little squiggle spans that show typos. SpellChecker starts a
* SpellCheckerSession as needed and then closes it when the TextView is detached from the window.
* A SpellCheckerSession is in charge of communicating with the spell checker service (which lives
* in another process) through TextServicesManager.
* The SpellChecker sends the TextView content to the spell checker service every 400ms, ie every
* time the service calls back with a result the SpellChecker schedules another check for 400ms
* later.
View TraceTest.kt
package com.example
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.FUNCTION
* @see TracingRunListener
View CrashingRunListener.kt
package com.example
import android.os.Bundle
import android.util.Log
import androidx.test.internal.runner.listener.InstrumentationResultPrinter
import org.junit.runner.Description
import org.junit.runner.notification.RunListener
View BugsnagLeakUploader.kt
package com.squareup.leakcanary
import com.squareup.leakcanary.BugsnagLeakUploader.ReportType.FAILURE
import com.squareup.leakcanary.BugsnagLeakUploader.ReportType.LEAK
import com.squareup.leakcanary.BugsnagLeakUploader.ReportType.NOT_FOUND
import com.squareup.leakcanary.BugsnagLeakUploader.ReportType.WONT_FIX_LEAK