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;
@ZakTaccardi
ZakTaccardi / build.gradle
Created August 26, 2015 01:24
Automatic per-variant google_services.json configurations with Gradle
//append code below to existing build.gradle
def appModuleRootFolder = '.'
def srcDir = 'src'
def googleServicesJson = 'google-services.json'
task switchToDebug(type: Copy) {
def buildType = 'debug'
description = 'Switches to DEBUG google-services.json'
from "${srcDir}/${buildType}"
public void elementClicked(int position){
if (view != null){
final int word = view.getWordByPosition(int position)
view.doAnimationStuff();
view.launchActivityWithWord(word);
}
}
//because there are no android dependencies here, it becomes easy to implement Mockito style behavioral testing.
/**
* A repository to store someone's favorite color.
*/
public interface FavoriteColorRepo {
/**
* Loads the user's favorite color.
* @return ex- "blue"
*/
public Observable<String> getFavoriteColor();
@ZakTaccardi
ZakTaccardi / CartControllerImpl.java
Last active January 10, 2017 19:23
A controller that loads a shopping cart (think online shopping).
/**
* A controller that loads a shopping cart (think online shopping).
*/
public class CartControllerImpl implements CartController {
final CartModel model;
final TaxModel taxModel;
final CurrencyUnit currencyUnit;
final MoneyFormatter moneyFormatter;
final RxBus rxBus;
/**
* 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();
}