Skip to content

Instantly share code, notes, and snippets.

View ZakTaccardi's full-sized avatar

Zak Taccardi ZakTaccardi

View GitHub Profile
the below is command line output generated from the (further below) main method
Factorial of '31' is '738197504'
Factorial of '10' is '3628800'
Factorial of '5' is '120'
Factorial of '4' is '24'
Factorial of '3' is '6'
Factorial of '2' is '2'
Factorial of '1' is '1'
Factorial of '0' is '1'
@ZakTaccardi
ZakTaccardi / UserEndpointAsyncTask.java
Last active August 29, 2015 14:13
Encapsulating Google App Engine AsyncTask logic
@Override
protected AsyncTaskResult<String> doInBackground(User... users) {
int userCount = users.length;
if(apiService == null) { // Only do this once
UserApi.Builder builder = new UserApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// options for running against local devappserver
.setRootUrl("http://" + ServerUtil.getHost() + ":8080/_ah/api/");
//turn off compression when running against local devappserver
Utility.compressTrafficIfNecessary(builder);
@ZakTaccardi
ZakTaccardi / gist:2b6b4ddd36ccd0b6b000
Created February 24, 2015 20:05
Setting Background Drawable with Material Button
public BaseButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.MaterialButton,
0, 0);
try {
colorButtonNormal = a.getInteger(R.styleable.MaterialButton_mbColorButtonNormal, Color.CYAN);
@ZakTaccardi
ZakTaccardi / HomePresenter.java
Created May 13, 2015 17:33
Sharing a subscriber class between two observables
public class HomePresenter extends BasePresenter<HomeView> {
ArticleRepo articleRepo;
@Inject
public HomePresenter(ArticleRepo articleRepo) {
this.articleRepo = articleRepo;
}
@Override
public void onCreate(@Nullable PresenterBundle bundle) {
List<Integer> coolList = new ArrayList<Integer>();
coolList.add(1);
coolList.add(2);
coolList.add(3);
Observable.from(coolList).map(new Func1<Integer, Long>() {
@Override
public Long call(Integer integer) {
//runs on the IO background thread because we specify `Schedulers.io()`
return integer * 10000000000L;
/**
* A repository to store someone's favorite color.
*/
public interface FavoriteColorRepo {
/**
* Loads the user's favorite color.
* @return ex- "blue"
*/
public Observable<String> getFavoriteColor();
/**
* Handles getting a user.
*/
public interface UserModel {
/**
* @return the currently logged in user, or null if the user is not logged in
*/
Single<User> getUser();
}
//build.gradle for "server" module
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
@ZakTaccardi
ZakTaccardi / RxMap.kt
Created October 14, 2016 20:59
A basic RxMap
/**
* A reactive map implementation that allows you to observe a key and its value.
*/
class RxMap<K, V>(
private val map: AbstractMap<K, V> = HashMap(),
private val rxMap: AbstractMap<K, Relay<V, V>> = HashMap()
) : Map<K, V> {
/**
* @return a hot observable that emits the value for the specified key. When you subscribe,
@ZakTaccardi
ZakTaccardi / RxActivity.kt
Created December 13, 2016 15:47
RxActivity
/**
* Observe the activity events!
*/
class RxActivityDelegate : RxActivity {
private val relay = BehaviorRelay.create<ActivityLifecycleEvent>().toSerialized()
fun onCreate() {
relay.call(CREATE)
log("onCreate")