Skip to content

Instantly share code, notes, and snippets.


Zac Sweers ZacSweers

View GitHub Profile
mannodermaus /
Last active Aug 30, 2018
Custom TextView implementation to allow VectorDrawableCompat to work with compound Drawables
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
EricKuck / ButterknifeConductor.kt
Last active May 9, 2019
Kotterknife(ish) view binding for Conductor controllers
View ButterknifeConductor.kt
// Largely borrowed from Jake Wharton's Kotterknife (
// and paweljaneczek's PR for resetting cached views (
package com.bluelinelabs.conductor.butterknife
import android.view.View
import com.bluelinelabs.conductor.Controller
import java.util.Collections
import java.util.WeakHashMap
nickbutcher / 1_drawable_ic_hash_io16.xml
Last active Jun 16, 2020
Animated Stroke. The google I/O website this year ( has some funky animated lettering. I especially liked the animated stroke around the letters and wondered how you might implement that on Android. Turns out that AnimatedVectorDrawable makes this very easy! Here's how it looks:…
View 1_drawable_ic_hash_io16.xml
<?xml version="1.0" encoding="utf-8"?>
Copyright 2016 Google Inc.
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
MichaelEvans / appcompat.diff
Last active Mar 27, 2016
Changelog for Support Libraries v23.2.0 -> v24.0.0-alpha1
View appcompat.diff
diff -U 0 -N appcompat-v7-23.2.0_ff0f8a1a/$PanelFeatureState appcompat-v7-24.0.0-alpha1_4f276de6/$PanelFeatureState
--- appcompat-v7-23.2.0_ff0f8a1a/$PanelFeatureState 1969-12-31 19:00:00.000000000 -0500
+++ appcompat-v7-24.0.0-alpha1_4f276de6/$PanelFeatureState 2016-03-09 19:28:22.000000000 -0500
@@ -0,0 +1,5 @@
+public final class$PanelFeatureState {
+ public boolean qwertyMode;
+ public boolean hasPanelItems();
+ public void clearMenuPresenters();
diff -U 0 -N appcompat-v7-23.2.0_ff0f8a1a/ appcompat-v7-24.0.0-alpha1_4f276de6/
swankjesse /
Last active Feb 10, 2021
This OkHttp application interceptor will replace the destination hostname in the request URL.
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
/** An interceptor that allows runtime changes to the URL hostname. */
public final class HostSelectionInterceptor implements Interceptor {
private volatile String host;
dlew /
Created Mar 1, 2016
Automated onError() message generation
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
jerrellmardis / ExponentialBackoff
Last active Jun 3, 2019
Exponential Backoff using Rx.retryWhen()
View ExponentialBackoff
// retries up to 3 times while exponentially backing off with each retry
.retryWhen(errors ->
Observable.range(1, MAX_RETRIES), (n, i) -> i
retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS)
neworld /
Last active Sep 15, 2020
How to make faster Android build without sacrificing new api lint check

Original solution sacrifices new api lint check.

Here my solution:

int minSdk = hasProperty('minSdk') ? minSdk.toInteger() : 16

apply plugin: ''

android {
    compileSdkVersion 23
public void readTwice()
Observable.fromCallable(() -> {
RedditData inflatedModel = null;
Response response = makeRequest();
String diskValue = null;
try {
File file = new File(getContext().getCacheDir(), "file");
BufferedSink cacheBody = Okio.buffer(Okio.sink(file));
aggrolite /
Last active Aug 13, 2019
Writing a reddit bot with Go and OAuth2