Skip to content

Instantly share code, notes, and snippets.

View AndrewReitz's full-sized avatar

Andrew Reitz AndrewReitz

View GitHub Profile
@AndrewReitz
AndrewReitz / PushTester.groovy
Last active August 29, 2015 14:04
SmartThings Test Pusher
/**
* PushTester
*
* Copyright 2014 Andrew Reitz
*
*/
definition(
name: "PushTester",
namespace: "com.andrewreitz",
author: "Andrew Reitz",
@AndrewReitz
AndrewReitz / Repository.java
Created August 13, 2014 15:30
Repository pattern using RxJava
import java.util.LinkedHashMap;
import java.util.Map;
import rx.Observer;
import rx.Subscription;
import rx.subjects.PublishSubject;
abstract class Repository<K, V> {
private final Cache<K, V> cache;
@AndrewReitz
AndrewReitz / randomdots.scala
Last active August 29, 2015 14:06
Random Dots
def randDots:String = {
val nLines = 100
val width = 80
Seq.range(0, nLines*width).map(a=>if(scala.util.Random.nextBoolean())"." else " ").grouped(width).map(_.mkString("")).mkString("\n")
}
while(true){
println(randDots)
Thread.sleep(scala.util.Random.nextInt(5000))
}
@AndrewReitz
AndrewReitz / RxCursor
Created November 22, 2014 14:58
Anbdroid RxCursorLoader
Observable.create(new Observable.OnSubscribe<T>() {
@Override public void call(Subscriber<? super T> subscriber) {
final Cursor cursor = cursorLoader.getCursor();
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(cursor));
cursor.moveToNext();
}
}
@AndrewReitz
AndrewReitz / ಠ__ಠ.java
Last active August 29, 2015 14:10
@ಠ__ಠ
package lol;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
@AndrewReitz
AndrewReitz / check.gradle
Created February 9, 2015 03:19
Android Checkstyles
// Checkstyle
apply plugin: 'checkstyle'
checkstyle {
showViolations true
configFile = rootProject.file('codequality/checkstyle.xml')
}
def isLibraryPlugin = project.plugins.findPlugin('android-library') != null
def setupCheck = { variant ->
def name = variant.buildType.name
@AndrewReitz
AndrewReitz / consolewarmer.scala
Created February 12, 2015 17:25
Console Warmer
var n = 60
var n2 = 20
while (true) {
n = n + (if (scala.util.Random.nextBoolean()) 1 else -1)
n = n max 0 min 80
n2 = n2 + (if (scala.util.Random.nextBoolean()) 1 else -1)
n2 = n2 max 0 min 80
for (i <- 0 until (n min n2)) print(" ")
if (n2 < n) print("░") else print("█")
for (i <- 0 until (n max n2) - (n min n2)) print(" ")
@AndrewReitz
AndrewReitz / lol.groovy
Created March 3, 2015 21:26
How much do you hate me now?
char z = Character.class.getDeclaredMethods()[0].toString().charAt(6)
char x = javax.sql.RowSet.class.getName().charAt(5)
Object o = ClassLoader.getSystemClassLoader()
.loadClass(
javax.crypto.Cipher.class.getName().split(String.format("\\%s", x))[0].substring(0, 4) +
x +
java.lang.annotation.Annotation.class.getName().split(String.format("\\%s", x))[1] +
x +
Character.toUpperCase(java.sql.Connection.class.getName().split(String.format("\\%s", x))[1].charAt(0)) +
@AndrewReitz
AndrewReitz / extraAndroidTasks.gradle
Last active August 29, 2015 14:17
Extra Android Gradle Tasks
// Adds extra tasks to improve android usage
project.android.applicationVariants.all {
it.buildType*.name.each { buildType ->
def adb = new File(project.android.sdkDirectory as File, '/platform-tools/adb')
def buildTypeString = buildType.capitalize()
task "run$buildTypeString"(type: Exec, dependsOn: "install$buildTypeString", group: 'run') {
description = "Builds and runs the $buildTypeString of the application."
/**
* 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();