Skip to content

Instantly share code, notes, and snippets.


Daniel Lew dlew

View GitHub Profile
View gist:680175f035de85af3e29
RetrofitService.doTheThing(params) // Your typical API call
.subscribeOn( // Execute API call on IO thread
.observeOn(AndroidSchedulers.mainThread()) // Execute observers on Android's main thread
.subscribe(results -> handle(results)); // Handling the results of the API call
dlew / gist:f7026c13fa09fe6df0d6
Last active Aug 29, 2015
Why I hate mixing implicit/explicit styles
View gist:f7026c13fa09fe6df0d6
<style name="Widget" />

<style name="Widget.Button" />

<style name="Widget.Button.Alternative" parent="@android:style/SomeOtherStyle />

All buttons either use Widget.Button or Widget.Button.Alternative.

I decide to change something in Widget.Button.

dlew / gist:b808900466685749f1bd
Last active Aug 29, 2015
Everything you need to do to change the color of the title of your ActionBar.
View gist:b808900466685749f1bd
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBarStyle</item>
<style name="MyActionBarStyle" parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">@style/MyTitleTextStyle</item>
<style name="MyTitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
dlew / gist:8c754d9b5e5b145d23ca
Created Mar 9, 2015
Wrapping with transformers
View gist:8c754d9b5e5b145d23ca
private CompositeSubscription subscriptions = new CompositeSubscription();
public <T> Observable<T> subscribe(Observable<T> observable) {
return observable;
public <T> Observable.Transformer<T, T> subscribeTransformer() {
return new Observable.Transformer<T, T>() {
import rx.Observable;
import rx.subjects.PublishSubject;
public class Property<T> {
private T value;
private PublishSubject<T> property;
public Property() {
property = PublishSubject.create();

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 /
Created Mar 1, 2016
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)",
dlew / androidmanifest.xml
Created May 1, 2015
Fully supporting "note to self" and "take a note" on Android
View androidmanifest.xml
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="" />
<data android:mimeType="*/*" />
View gist:9fd280bbc057af800213
* 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.
JavaCompile getJavaCompile() throws IllegalStateException;
dlew /
Created Nov 1, 2017
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: