Skip to content

Instantly share code, notes, and snippets.

View kmdupr33's full-sized avatar

Matt Dupree kmdupr33

View GitHub Profile
public static void main (String args[]) {
System.out.println("Hello world!");
}
package com.philosophicalhacker.philosopy;
/**
* This class contains some methods for evaluating arguments that
* attempt to defend the moral permissibility of pirating.
*
* It also contains a <code>main()</code> method that uses
* this class to show that several of the arguments made in
* defense of pirating aren't really that compelling.
*
@kmdupr33
kmdupr33 / LeakySubscriber.java
Last active February 19, 2016 10:21
Shows how Subscribers can leak
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
@Override
public void onClick(View v) {
mApiService.submitCredentials(mCredentials)
.subscribe(new Subscriber<RegistrationResponse>() {
@Override
public void onCompleted() {
@kmdupr33
kmdupr33 / NotSoLeakySubscriber.java
Created March 24, 2015 23:24
Show the straightforward way to avoid leaking your subscriber
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
...
@Override
protected void onDestroy() {
super.onDestroy();
mSubscribtion.unsubscribe();
}
public class WeakSubscriberDecorator<T> extends Subscriber<T> {
private final WeakReference<Subscriber<T>> mWeakSubscriber;
public WeakSubscriberDecorator(Subscriber<T> subscriber) {
this.mWeakSubscriber = new WeakReference<Subscriber<T>>(subscriber);
}
public class SafeObservable<T> extends Observable<T> {
/**
* Creates an Observable with a Function to execute when it is subscribed to.
* <p/>
* <em>Note:</em> Use {@link #create(rx.Observable.OnSubscribe)} to create an Observable, instead of this constructor,
* unless you specifically have a need for inheritance.
*
* @param f {@link rx.Observable.OnSubscribe} to be executed when {@link #subscribe(Subscriber)} is called
*/
@Override
public void onStop() {
super.onStop();
if (mInitStarred != mStarred) {
if (UIUtils.getCurrentTime(this) < mSessionStart) {
// Update Calendar event through the Calendar API on Android 4.0 or new versions.
Intent intent = null;
if (mStarred) {
// Set up intent to add session to Calendar, if it doesn't exist already.
intent = new Intent(SessionCalendarService.ACTION_ADD_SESSION_CALENDAR,
@kmdupr33
kmdupr33 / SessionDetailActivitiyInitmInitStarred.java
Last active August 29, 2015 14:19
SessionDetailActivitiyInitmInitStarred
private void onSessionQueryComplete(Cursor cursor) {
final boolean inMySchedule = cursor.getInt(SessionsQuery.IN_MY_SCHEDULE) != 0;
//...
if (!mIsKeynote) {
showStarredDeferred(mInitStarred = inMySchedule, false);
}
public void testSquare() {
MathNerd mathNerd = new MathNerd();
int result = mathNerd.square(2);
assertEquals(result, 4);
}
public void testSquare() {
MathNerd mathNerd = new MathNerd();
int result = mathNerd.square(2);
assertTrue(mathNerd.didDoMath());
}