Skip to content

Instantly share code, notes, and snippets.

View dlew's full-sized avatar

Daniel Lew dlew

View GitHub Profile
@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
@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 / 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

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 / script.sh
Created November 9, 2018 16:36
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@dlew
dlew / artifact-hunter.py
Created November 1, 2017 13:59
Simple Python script that tells you all the current artifact spots on a Stardew Valley save
import xml.etree.ElementTree as ET
tree = ET.parse('/path/to/save/file')
root = tree.getroot()
locations = root.find('locations')
for location in locations:
name = location.find('name').text
objects = location.find('objects')
for thing in objects:

When Mac OS X first launched they did so without an existing poll function. They later added poll() in Mac OS X 10.3, but we quickly discovered that it was broken (it returned a non-zero value when asked to wait for nothing) so in the curl project we added a check in configure for that and subsequently avoided using poll() in all OS X versions to and including Mac OS 10.8 (Darwin 12). The code would instead switch to the alternative solution based on select() for these platforms.

With the release of Mac OS X 10.9 “Mavericks” in October 2013, Apple had fixed their poll() implementation and we’ve built libcurl to use it since with no issues at all. The configure script picks the correct underlying function to use.

Enter macOS 10.12 (yeah, its not called OS X anymore) “Sierra”, released in September 2016. Quickly we discovered that poll() once against did not act like it should and we are back to disabling the use of it in preference to the b

@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());
/**
* Returns the Java Compilation task if javac was configured to compile the source files.
* @deprecated prefer {@link #getJavaCompiler} which always return the java compiler task
* irrespective of which tool chain (javac or jack) used.
*/
@Nullable
@Deprecated
JavaCompile getJavaCompile() throws IllegalStateException;
/**