Skip to content

Instantly share code, notes, and snippets.

View martintreurnicht's full-sized avatar

Martin Treurnicht martintreurnicht

  • Step Mobile inc
  • Oakland, California
View GitHub Profile
@martintreurnicht
martintreurnicht / NonNullableMutableMap.kt
Last active October 13, 2016 18:45
NonNullableMutableMap
interface NonNullableMutableMap<K,V> : MutableMap<K,V> {
override fun get(key: K): V
operator fun set(key: K, value: V) = put(key, value)
}
fun <K,V> MutableMap<K,V>.withoutNullValues(default: () -> V): NonNullableMutableMap<K, V> {
if (this is NonNullableMutableMap) return this
return NonNullableMapWrapper(this, default)
}
@martintreurnicht
martintreurnicht / DynamoDbHelper.java
Last active February 3, 2016 16:38
Create Dynamo DB table when they don't exist
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex;
import com.amazonaws.services.dynamodbv2.model.Projection;
import com.amazonaws.services.dynamodbv2.model.ProjectionType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException;
import com.amazonaws.auth.AWSCredentials;
@martintreurnicht
martintreurnicht / ColorUtil
Created November 28, 2014 14:47
Lighten and darken colors in android
public static int lighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = lightenColor(red, fraction);
green = lightenColor(green, fraction);
blue = lightenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}