Skip to content

Instantly share code, notes, and snippets.

View pyricau's full-sized avatar

py - Pierre Yves Ricau pyricau

View GitHub Profile
@pyricau
pyricau / JellyBeanSpanFixTextView.java
Last active October 8, 2021 07:16
A TextView to prevent a bug with spans on JellyBean: http://code.google.com/p/android/issues/detail?id=35466
// Copyright 2012 Pierre-Yves Ricau
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@pyricau
pyricau / LeakSlackUploadService.java
Created May 9, 2015 00:03
Sending Leak Traces to a Slack Channel (and HipChat, see the comments)
import android.util.Log;
import com.squareup.leakcanary.AnalysisResult;
import com.squareup.leakcanary.DisplayLeakService;
import com.squareup.leakcanary.HeapDump;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.http.Multipart;
import retrofit.http.POST;
import retrofit.http.Part;
import retrofit.mime.TypedFile;
@pyricau
pyricau / Example.kt
Created June 4, 2021 20:21
A test coroutine dispatcher to reproduce race conditions
// 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
@pyricau
pyricau / WindowSpy.kt
Last active September 15, 2020 20:34
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
pyricau / AndroidLeaks.kt
Created January 15, 2020 20:45
Fixing a SpellChecker leak in Android M
/**
* 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.
package com.squareup.leakcanary
import android.app.Application
import com.bugsnag.android.Client
import com.bugsnag.android.MetaData
import com.bugsnag.android.Severity.ERROR
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
@pyricau
pyricau / ThreadPreconditions.java
Created November 29, 2012 09:59
Check that your UI APIs are called from the UI Thread
public class ThreadPreconditions {
public static void checkOnMainThread() {
if (BuildConfig.DEBUG) {
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException("This method should be called from the Main Thread");
}
}
}
}
import java.util.concurrent.Callable;
public enum Lol implements Callable<CharSequence> {
ಠ_ಠ {
@Override public String call() {
return "Foo";
}
};
@pyricau
pyricau / ConvertirRepoSvnGit
Created July 28, 2011 09:55
Convertir un repo SVN en repo Git, avec ceintures et bretelles
# On sort la liste des users ayant commité sur le SVN
svn log --xml https://svn.codehaus.org/groovy | grep "<author>" | sort -u | sed 's/<[^>]*[>]//g' > users.txt
# Compléter le fichier users.txt pour qu'il ait le format suivant (sur certains SVN, le "no author" correspond au premier commit) :
user1 = User One <user1@mail.com>
user2 = User Two <user2@mail.com>
(no author) = No Author <no@author.com>
# Cloner en local le repo svn (je pars du principe que le svn a la forme classique trunk / branches / tags
git svn clone --username glaforge --stdlayout --no-metadata --authors-file users.txt https://svn.codehaus.org/groovy groovy