Skip to content

Instantly share code, notes, and snippets.

View AndrewReitz's full-sized avatar

Andrew Reitz AndrewReitz

View GitHub Profile
@AndrewReitz
AndrewReitz / GitHubAvatar.groovy
Last active January 20, 2017 15:07
Code Golf: Git Hub Avatar Generator
package cash.andrew
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
import java.time.LocalDateTime
// 0xffffff + 1
// so that random returns a value from 0 to 0xffffff
final int MAX_COLOR_VALUE = 16777216
@AndrewReitz
AndrewReitz / BetterRecyclerAdapter.java
Created May 24, 2016 17:15
Abstracts away the view holder so you can just make awesome views.
package ws.🍉💩;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A recycler view adapter that makes life better.
*
@AndrewReitz
AndrewReitz / signing.gradle
Created May 18, 2016 13:26
Android Signing Extras
ext.keystorePassword = project.hasProperty('keystorePassword')?project.getProperty('keystorePassword'):System.getenv('KEYSTORE_PASSWORD')?:''
ext.aliasKeyPassword = project.hasProperty('aliasKeyPassword')?project.getProperty('aliasKeyPassword'):System.getenv('ALIAS_KEY_PASSWORD')?:''
ext.storeKeyAlias = project.hasProperty('storeKeyAlias')?project.getProperty('storeKeyAlias'):System.getenv('STORE_KEY_ALIAS')?:''
@AndrewReitz
AndrewReitz / ViewUtils.java
Last active April 15, 2016 13:56
View Utils Android Helpers for View Stuff
package com.andrewreitz.utils;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.widget.TextView;
/**
// Does what you expect
println ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()).minusYears(10).toInstant()
// throws an exception java.time.DateTimeException: Unable to obtain ChronoZonedDateTime from TemporalAccessor: class java.time.Instant
println ZonedDateTime.from(Instant.now()).minusYears(10).toInstant()
package com.smartthings.android.common.http;
import com.inkapplications.preferences.IntPreference;
import com.smartthings.android.di.annotation.HttpDisasterRate;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.ResponseBody;
@AndrewReitz
AndrewReitz / Checkerboard.groovy
Created February 15, 2016 20:32
Write Image in Groovy/Java
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
def image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB)
for (x in 0..99) {
for (y in 0..99) {
int color = (x + y) % 2 == 0 ? 0x000000 : 0xffffff
image.setRGB(x, y, color)
}
}
@AndrewReitz
AndrewReitz / androidExtras.gradle
Last active December 22, 2015 21:08
Run Lint Tasks on Every Build (Android)
// Adds extra tasks to improve android usage
project.android.applicationVariants.all { variant ->
def adb = new File(project.android.sdkDirectory as File, '/platform-tools/adb')
def variantName = variant.name.capitalize()
def flavor = variant.flavorName
def buildType = variant.buildType.name
def parseArgs = { String input ->
def args = []
def m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(input);
while (m.find()) {
args.add(m.group(1))
}
return args
}
run {
/**
* Create a string representation of an object. This will include all fields that are not
* transient or static. The returned string will be in the form of `full_class_name{fieldName='value'}`
* This will also include all super types values as well in the string.
*
* @param object The object to get a string representation from.
* @return String representation of the object.
*/
public static String toString(Object object) {
Class<?> aClass = object.getClass();