Skip to content

Instantly share code, notes, and snippets.

RetrofitService.doTheThing(params) // Your typical API call
.subscribeOn(Schedulers.io()) // 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
dlew / gist:f7026c13fa09fe6df0d6
Last active August 29, 2015 14:06
Why I hate mixing implicit/explicit styles
<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
dlew / gist:b808900466685749f1bd
Last active August 29, 2015 14:08
Everything you need to do to change the color of the title of your ActionBar.
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
@dlew
dlew / gist:8c754d9b5e5b145d23ca
Created March 9, 2015 20:53
Wrapping with transformers
private CompositeSubscription subscriptions = new CompositeSubscription();
public <T> Observable<T> subscribe(Observable<T> observable) {
subscriptions.add(observable.subscribe());
return observable;
}
public <T> Observable.Transformer<T, T> subscribeTransformer() {
return new Observable.Transformer<T, T>() {
@Override
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
dlew / androidmanifest.xml
Created May 1, 2015 20:05
Fully supporting "note to self" and "take a note" on Android
<activity
android:name="com.yourapp.ui.NoteTaker">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.google.android.voicesearch.SELF_NOTE" />
<data android:mimeType="*/*" />
</intent-filter>
/**
* 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;
/**
@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:
@dlew
dlew / gist:3fee09af5ff946997551
Last active December 24, 2017 05:04
Android library artifact tasks
if (project.android.hasProperty('libraryVariants')) {
android.libraryVariants.all { variant ->
Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
group = 'artifact'
description "Generates Javadoc for $variant.name"
// Source files from the variant
source = variant.javaCompiler.source
// Classpath from the variant + android.jar