Skip to content

Instantly share code, notes, and snippets.

View CDRussell's full-sized avatar

Craig Russell CDRussell

View GitHub Profile

Maven + Google Play Services

The recently released version of Google Play Services presents itself as a library project with string and attribute resources coupled with a .jar in the libs/ folder that has been compiled against internal APIs.

While this is convenient for users of IDEs or Ant, it presents a problem for those using proper build systems (e.g., Maven, Gradle) with dependency management. Inside the .jar there are a lot of classes which reference static attributes on the com.google.android.gsm.R class. This means that

@CDRussell
CDRussell / ChangeValidator.java
Last active November 9, 2020 16:49
Solution to the Coin Change Problem in Java
package com.ncr.mobile;
import java.util.List;
public class ChangeValidator
{
private ChangeValidator()
{
}
@CDRussell
CDRussell / CDRCoinChangeValidator.m
Created November 7, 2013 15:22
Solution to the Coin Change Problem in Objective-C
// just the method body; complete the rest of the class declaration yourself.
+ (BOOL)isValidAmount:(int)target forDenominations:(NSArray *)denominations
{
if(denominations.count == 0)
return NO;
if(target < 0)
return NO;
@CDRussell
CDRussell / Assert.java
Created July 21, 2015 10:56
Asserts that two Strings containing JSON are equal.
public static void assertEqualsJson(String expected, String actual) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
assertEquals(objectMapper.readTree(expected), objectMapper.readTree(actual));
}
@CDRussell
CDRussell / Assert.java
Created July 21, 2015 10:59
Asserts two BigDecimals are equal. Will fail if compareTo() returns a non-zero result.
public static void assertEqualsBigDecimal(BigDecimal expected, BigDecimal actual) {
int result = expected.compareTo(actual);
if(result < 0) {
fail(String.format("Expected is less than actual; {expected=%s, actual=%s}", expected.toPlainString(), actual.toPlainString()));
} else if (result > 0) {
fail(String.format("Expected is greater than actual; {expected=%s, actual=%s}", expected.toPlainString(), actual.toPlainString()));
}
}
@CDRussell
CDRussell / RobolectricUnitTest.java
Created August 24, 2015 08:57
Base class to be used for all Robolectric unit tests.
package test;
import android.app.Application;
import com.tescobank.mobile.BuildConfig;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmSchema;
import io.realm.exceptions.RealmMigrationNeededException;
@CDRussell
CDRussell / TaskHelper
Last active June 2, 2016 08:32
Helper functions for working with Tasks from BoltsAndroid
import java.util.concurrent.Executor;
import bolts.Task;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public abstract class TaskHelper {
public static void assertTaskFinishedSuccessfully(Task<?> task) {
assertTrue(task.isCompleted());
@CDRussell
CDRussell / YourApplication.java
Last active July 3, 2017 12:19
Disabling Crashlytics on DEBUG Builds
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
configureCrashReporting();
}
private void configureCrashReporting() {
CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder()
@CDRussell
CDRussell / SimpleRange.kt
Last active August 8, 2017 06:29
Kotlin Simple rangeTo Example
if (i in 1..10) {
println("$i is within the range of 1-10")
} else {
println("$i is not in range of 1-10")
}