Skip to content

Instantly share code, notes, and snippets.

View AndrewReitz's full-sized avatar

Andrew Reitz AndrewReitz

View GitHub Profile
@AndrewReitz
AndrewReitz / ImmutableList.java
Created March 20, 2017 15:18
Simple Java Immutable List
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.RandomAccess;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;

Keybase proof

I hereby claim:

  • I am AndrewReitz on github.
  • I am areitz (https://keybase.io/areitz) on keybase.
  • I have a public key whose fingerprint is 6513 2A0E 64C9 3BC1 EDB4 BA62 0221 9C76 97C0 FB6E

To claim this, I am signing this object:

@AndrewReitz
AndrewReitz / DrawableStartButton.java
Created February 7, 2017 16:05
DrawableStartButton, and Icon Drawable for Android
/** A button that allows you to add a drawable to the start of the text. */
public class DrawableStartButton extends FrameLayout {
/** The textview that sits on top of the framelayout that contains the image and the text. */
@BindView(R.id.drawable_start_textview) TextView textview;
public DrawableStartButton(Context context, AttributeSet attrs) {
// Trick the framelayout to look like a button
this(context, attrs, R.attr.drawableStartButton);
}
@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 / RxFibN.java
Created June 16, 2014 23:16
RxJava implementation of Fibonacci Number
public class Main {
public static void main(String[] args) {
rxFibN(20).subscribe(new Action1<Integer>() {
@Override public void call(Integer result) {
System.out.println(result);
}
});
}
static Observable<Integer> rxFibN(final int n) {
@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;