Skip to content

Instantly share code, notes, and snippets.

View AndrewReitz's full-sized avatar

Andrew Reitz AndrewReitz

View GitHub Profile
@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();
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 {
@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
@AndrewReitz
AndrewReitz / watermark.sh
Last active January 2, 2016 07:29
Quick and dirty way to add a water mark to all images in a folder.
#!/bin/bash
WATERMARK="$1" #1st param image to be the water mark
#2nd param is path to folder you want all jpg, jpeg or png to
#have the water mark added to
for image in $2/*{.jpg,.jpeg,.png}
do
#gravity is the position the water mark will go
#50 is the opacity of the image
#the second $image is the output file, currently
@AndrewReitz
AndrewReitz / .bashrc
Last active January 2, 2016 10:59
My .bashrc so I can add things and remember them elsewhere
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
#Exports
@AndrewReitz
AndrewReitz / downloadtable.js
Created January 8, 2014 03:39
Download a table on a website with JavaScript
// Place to store all the strings for the CSV
var stringBuilder = [];
// Get the table, this one happens to be adminlist
// Could probably make the more generic
var table = document.getElementsByClassName('adminlist')[0];
var tbody = table.getElementsByTagName('tbody')[0]
var rows = tbody.getElementsByTagName('tr');
// Loop through each row
@AndrewReitz
AndrewReitz / GenericsExampleProblem.java
Last active January 3, 2016 02:29
Generic Types Example Problem (INCOMPLETE)
public class GenericsExampleProblem {
public static void main(String[] args) {
Class myClass = MyClass.class;
Method[] myClassMethods = myClass.getDeclaredMethods();
for (Method method : myClassMethods) {
// Skip any other methods
// This must be done this way instead of with getMethod(String Name, Class<?>... params) since
// we can not possibly know the params until at run time
if (!method.getName().equals("myMethod")) {
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;