Skip to content

Instantly share code, notes, and snippets.

View mgp's full-sized avatar
🤗

Michael Parker mgp

🤗
View GitHub Profile
@mgp
mgp / ObservableUtilsTest.java
Created June 3, 2015 15:33
ObservableUtilsTest.java
package org.khanacademy.core.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.khanacademy.core.util.test_util.Observables.collectAll;
import static org.khanacademy.core.util.test_util.Observables.collectFirst;
import org.khanacademy.core.base.BaseTestCase;
import org.khanacademy.core.exceptions.TestException;
@mgp
mgp / ObservableUtils.java
Created June 3, 2015 15:33
ObservableUtils.java
package org.khanacademy.core.util;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Optional;
import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;
@mgp
mgp / gist:8a175c90edb864c847ab
Created April 9, 2015 23:10
Previous RAC to dim
let exerciseTransitioningSignal = exerciseTransitioningSubject
.startWithBoxedValue(false)
.takeUntil(rac_willDeallocSignal())
controlsEnabledSubscription = exerciseTransitioningSignal
.combineLatestWith(isReachableSignal)
.map {
let tuple = $0 as! RACTuple
let isExerciseTransitioning = (tuple.first as! Box<Bool>).value
let isReachable = (tuple.second as! Box<Bool>).value
@mgp
mgp / gist:dfe381800ee2cc3fa3e2
Created April 9, 2015 00:33
Failed use of an anonymous inner class
override func loadView() {
// Create a KAExerciseControlsDelegate implementation that invokes methods on the delegate
// of this instance.
weak var weakSelf = self
class ViewDelegate: KAExerciseControlsDelegate {
// Invokes the given block with the view controller and its delegate, if both are still
// allocated.
private func callControllerDelegate(caller: (ExerciseControlsViewDelegate, ExerciseControlsViewController) -> Void) {
if let strongSelf = weakSelf, strongDelegate = strongSelf.delegate {
caller(strongDelegate, strongSelf)
@mgp
mgp / gist:3da4b06d308f5b1d0490
Created March 12, 2015 01:16
Load an article
/*
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, TopicTutorialListFragment.newInstance(subject))
.addToBackStack("subject")
.commit();
*/
System.out.println("navigating");
Article article = new Article("xbdcfe503", "An Introduction to the Protestant Reformation");
package org.khanacademy.core.topictree.models;
/**
* An enumeration over all exercise frameworks.
*/
public enum ExerciseFramework {
KHAN_EXERCISES,
PERSEUS,
}
package org.khanacademy.core.topictree.models;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
/**
* Uniquely identifies an {@link Exercise} instance.
*/
public final class ExerciseDescriptor {
package org.khanacademy.core.topictree.models;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import org.khanacademy.core.topictree.identifiers.ContentItemIdentifiable;
import org.khanacademy.core.topictree.identifiers.ContentItemIdentifier;
import org.khanacademy.core.topictree.identifiers.ContentItemKind;
/**
@mgp
mgp / gist:6ca63f80283d1090a243
Created February 26, 2015 22:43
OwnedDelegateAlertView
//
// ViewController.swift
// deinit-failure
//
// Created by Mike Parker on 2/26/15.
// Copyright (c) 2015 Mike Parker. All rights reserved.
//
import UIKit
/**
UIAlertViewDelegate used when the user can only go back, and so the associated handler
has no parameters.
*/
private class BackOnlyErrorDelegate: NSObject, UIAlertViewDelegate {
private let handler: () -> Void
private init(handler: () -> Void) {
self.handler = handler
}