Skip to content

Instantly share code, notes, and snippets.

@dlew
dlew / RxActivityLifecycleCallbacks.java
Created November 26, 2014 21:35
RxActivityLifecycleCallbacks
package rx.android.lifecycle;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import rx.Observable;
import rx.subjects.BehaviorSubject;
import java.util.Map;
public class LazyListManagerUtils {
public static <T> List<T> add(List<T> list, T item) {
if (list == null) {
list = new ArrayList<T>();
list.add(item);
}
else if (!list.contains(item)) {
list.add(item);
}
@dlew
dlew / gist:3100299
Created July 12, 2012 19:23
Easier findVewById()
@SuppressWarnings("unchecked")
public static <T extends View> T findView(Activity activity, int id) {
return (T) activity.findViewById(id);
}
@SuppressWarnings("unchecked")
public static <T extends View> T findView(View view, int id) {
return (T) view.findViewById(id);
}

Keybase proof

I hereby claim:

  • I am dlew on github.
  • I am danlew (https://keybase.io/danlew) on keybase.
  • I have a public key ASD8v3oTeKIyAZP1WwjzP1Wxej0F_V6CqXZOdQ9A61iewAo

To claim this, I am signing this object:

@dlew
dlew / build.gradle
Last active September 11, 2019 18:35
Sample gradle.build for Crashlytics
// Follow the five numbered instructions for setting up Crashlytics
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
// 1. Add the Crashlytics Maven repository to your build script.
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
@dlew
dlew / thing.kt
Last active January 31, 2021 02:30
Gson -> Moshi name snafu detector
@Test
fun verifySerializedNameMatchesJsonName() {
// Reflections library
Reflections("com.foobar").getTypesAnnotatedWith(JsonClass::class.java)
.flatMap { clz ->
// FieldUtils is in Apache Commons
FieldUtils.getAllFieldsList(clz).filter { !Modifier.isStatic(it.modifiers) }
}
.forEach { field ->
val serializedNameAnnotation = field.declaredAnnotations.find { it is SerializedName } as? SerializedName
@dlew
dlew / File.java
Created March 1, 2016 20:46
Automated onError() message generation
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());
@dlew
dlew / gist:debc5ea214678bf0739a8ec92dabe095
Created November 5, 2021 17:56
Privacy Policy for Apps That Collect No Data
This app collects no private data, period. Your data will not be used in any way, because we won't have it.
@dlew
dlew / trombonechamp.kt
Created September 24, 2022 14:36
Trombone Champ hacky trombone code
import be.tarsos.dsp.AudioEvent
import be.tarsos.dsp.io.jvm.AudioDispatcherFactory
import be.tarsos.dsp.pitch.PitchDetectionHandler
import be.tarsos.dsp.pitch.PitchDetectionResult
import be.tarsos.dsp.pitch.PitchProcessor
import be.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm
import java.awt.Robot
import java.awt.event.InputEvent
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit