Skip to content

Instantly share code, notes, and snippets.

View AndrewReitz's full-sized avatar

Andrew Reitz AndrewReitz

View GitHub Profile
@AndrewReitz
AndrewReitz / profiler.scenarios
Created May 13, 2019 19:20
Sample Scenarios
config {
tasks = ["help"]
}
cleanAssemble {
tasks = ["assemble"]
cleanup-tasks = ["clean", "cleanBuildCache"]
}
abiAssemble {
@AndrewReitz
AndrewReitz / build.gradle
Created May 5, 2019 15:28
Example of dependencies in groovy gradle file
dependencies {
implementation("com.jakewharton.rxbinding2:rxbinding:2.2.0")
implementation("com.jakewharton:process-phoenix:2.0.0")
implementation("com.jakewharton.timber:timber:4.7.1")
implementation("com.jakewharton.byteunits:byteunits:0.9.1")
debugImplementation("com.readystatesoftware.chuck:library:1.1.0")
releaseImplementation("com.readystatesoftware.chuck:library-no-op:1.1.0")
buildFlavorOneImplementation("com.squareup.leakcanary:leakcanary-android:1.6.3")
@AndrewReitz
AndrewReitz / settings.gradle.kts
Last active May 3, 2019 01:05
My settings.gradle.kts for my kotlin raytracing project
include(
"raytracer-core",
"raytracer-math",
"raytracer-console",
"raytracer-parsing"
)
rootProject.name = "kotlin-raytracer"
rootProject.children.forEach {
@AndrewReitz
AndrewReitz / LazySetters.kt
Created March 28, 2019 18:30
Like lazy in kotlin but you can also have setters.
fun <T: Any> lazy(initializer: () -> T): LazySetter<T> = LazySetter(initializer)
class LazySetter<T: Any>(private val initializer: () -> T) {
private var _value: T? = null
var value: T
get() = _value ?: initializer()
set(value) { _value = value }
}
inline operator fun <reified T: Any> LazySetter<T>.setValue(thisRef: Any?, property: KProperty<*>, value: T) {
@AndrewReitz
AndrewReitz / serialVersionTest.kts
Created March 14, 2019 16:41
create two giant projects one with and one without serialVersionUID and benchmark compilation of them
#!/bin/bash
//usr/bin/env echo '
/**** BOOTSTRAP kscript ****\'>/dev/null
command -v kscript >/dev/null 2>&1 || curl -L "https://git.io/fpF1K" | bash 1>&2
exec kscript $0 "$@"
\*** IMPORTANT: Any code including imports and annotations must come after this line ***/
import java.io.File
import java.util.concurrent.TimeUnit
@AndrewReitz
AndrewReitz / ImmutableList.java
Last active December 25, 2018 22:56
Immutable List Stuff
import android.support.annotation.NonNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.RandomAccess;
@AndrewReitz
AndrewReitz / configLoader.gradle
Created October 6, 2017 18:31
Gradle Property / Configuration Loader
/**
* Grabs a configuration value from configuration property or system properties (in that order) if
* one exits. Otherwise the default value will be used. If a default value is not provided an empty
* string will be used.
*
* @param values Map containing the property name to look for (propertyName), the system environment
* variable name to look for (environmentPropertyName), and the default value if any to use
* if a value was not found.
* @return the first found value, project property, then system, then default value. If no default
* value was provided an empty string will be returned.
[ratpack-compute-27-6] ERROR ratpack.exec.Execution - Uncaught execution exception
ratpack.registry.NotInRegistryException: No object for type 'ratpack.handling.Context' in registry
at ratpack.registry.Registry.get(Registry.java:136)
at ratpack.registry.Registry.get(Registry.java:120)
at ratpack.retrofit.internal.RatpackCallFactory$RatpackCall.promise(RatpackCallFactory.java:83)
at ratpack.retrofit.internal.RatpackCallFactory$RatpackCall.enqueue(RatpackCallFactory.java:70)
at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:101)
at ratpack.retrofit.internal.RatpackCallAdapterFactory$SimpleCallAdapter.lambda$adapt$0(RatpackCallAdapterFactory.java:135)
at ratpack.exec.internal.DefaultExecution.lambda$null$1(DefaultExecution.java:119)
at ratpack.exec.internal.DefaultExecution$SingleEventExecStream.exec(DefaultExecution.java:423)
@AndrewReitz
AndrewReitz / KeyboardHider.java
Last active May 19, 2017 15:03
KeyboardHider (Android)
/**
* Provides a simple way to hide a keyboard, because google didn't
*/
@Singleton
public final class KeyboardHider {
private final InputMethodManager inputMethodManager;
@Inject KeyboardHider(InputMethodManager inputMethodManager) {
this.inputMethodManager = checkNotNull(inputMethodManager, "inputMethodManager == null");
@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;