Skip to content

Instantly share code, notes, and snippets.

Róbert Papp TWiStErRob

View GitHub Profile
@TWiStErRob
TWiStErRob / README.md
Last active Feb 28, 2019
Kotlin Script (kts) with dependencies to call a JSON web endpoint, including tests
View README.md
@TWiStErRob
TWiStErRob / build.gradle
Created Feb 9, 2019
Automatically add `dagger.formatGeneratedSource` if `dagger-compiler` is present in `annotationProcessor` configuration.
View build.gradle
allProjects { project ->
tasks.withType(JavaCompile).configureEach { JavaCompile task ->
task.doFirst {
// annotationProcessorPath is populated around afterEvaluate, but can't use that in configureEach
if (hasDagger(task.options.annotationProcessorPath)) {
task.options.compilerArgs += [
// disable formatting, why wait if it looks almost the same?!
'-Adagger.formatGeneratedSource=disabled'
]
}
View protractorAPICheatsheet.md
@TWiStErRob
TWiStErRob / Example.java
Last active Feb 11, 2017
JUnit Jupiter extension for creating JFixture objects into tests
View Example.java
public class Example {
public static <T1, T2> Predicate<Pair<T1, T2>> expand(BiPredicate<? super T1, ? super T2> func) {
return objects -> func.test(objects.getValue0(), objects.getValue1());
}
}
View README.md

See SO answer.

You can pan (click background), zoom (mousewheel), drag nodes around. Middle click to add more nodes (at mouse).

@TWiStErRob
TWiStErRob / OkHttpProgressGlideModule.java
Last active May 12, 2020
Full POC for showing progress of loading in Glide v3 via OkHttp v2
View OkHttpProgressGlideModule.java
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@TWiStErRob
TWiStErRob / TravelingSalesmanHeldKarpX.java
Last active Dec 31, 2015
Programmatic version of Tushar Roy's Held-Karp TSP video (https://www.youtube.com/watch?v=-JjA4BLQyqE)
View TravelingSalesmanHeldKarpX.java
package problems.tushar;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.*;
import static problems.tushar.TravelingSalesmanHeldKarpX.Algo.*;
import static problems.tushar.TravelingSalesmanHeldKarpX.Utils.*;
/**
@TWiStErRob
TWiStErRob / LimitOutput.java
Created Nov 26, 2015
LeetCode helper methods for console debugging
View LimitOutput.java
static {
System.setOut(new java.io.PrintStream(new java.io.FilterOutputStream(System.out) {
int count = 10 * 1024;
@Override public void write(int b) throws IOException {
if (count > 0) {
super.write(b);
--count;
}
}
@Override public void write(byte[] b, int off, int len) throws IOException {
@TWiStErRob
TWiStErRob / SquareFrameLayout.java
Created Sep 30, 2015
Make GridView or GridLayoutManager items square.
View SquareFrameLayout.java
package net.twisterrob.android.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
public class SquareFrameLayout extends FrameLayout {
public SquareFrameLayout(Context context) {
super(context);
}
@TWiStErRob
TWiStErRob / BitmapBitmapResourceDecoder.java
Last active Oct 24, 2016
Glide 3.6.0 proof of concept for loading a Bitmap as Bitmap through Glide
View BitmapBitmapResourceDecoder.java
class BitmapBitmapResourceDecoder implements ResourceDecoder<Bitmap, Bitmap> {
private final BitmapPool pool;
public BitmapBitmapResourceDecoder(Context context) {
this(Glide.get(context).getBitmapPool());
}
public BitmapBitmapResourceDecoder(BitmapPool pool) {
this.pool = pool;
}
@Override public Resource<Bitmap> decode(Bitmap source, int width, int height) throws IOException {
You can’t perform that action at this time.