Skip to content

Instantly share code, notes, and snippets.

Matt Silber mattsilber

Block or report user

Report or block mattsilber

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mattsilber
mattsilber / KTools.kt
Created Feb 2, 2018
Pseudo-ternary boolean operator functions
View KTools.kt
fun <T: Any> Boolean.valueFromState(value: T, falseValue: T): T = valueIfTrueOrNull(value) ?: falseValue
infix fun <T: Any> Boolean.valueIfTrueOrNull(value: T): T? = if (this) value else null
val toCheck: Boolean = false
val int1 = toCheck.valueFromState(0, 1)
val int2 = toCheck.valueIfTrueOrNull(0) ?: 1
val int3 = toCheck valueIfTrueOrNull 0 ?: 1
@mattsilber
mattsilber / gradle.properties
Last active Dec 19, 2017
Gradle 4 replacement scripts for android values/manifest
View gradle.properties
# Disabled Aapt2 to fallback on xml file usage
android.enableAapt2=false
@mattsilber
mattsilber / VerifyErrorTest.java
Last active Feb 27, 2017
Android java.lang.VerifyError Rejecting class * because it failed compile-time verification (declaration of * appears in /data/app/**-1/base.apk)
View VerifyErrorTest.java
/*
Notes:
gradleVersion = '2.14.1'
com.android.tools.build:gradle:2.2.3
compileSdkVersion 25
buildToolsVersion "25.0.2"
minSdkVersion 15
targetSdkVersion 25
*/
@mattsilber
mattsilber / Drawable.java
Last active Sep 28, 2016
Instagram's crappy colors in a ShaderFactory
View Drawable.java
ShapeDrawable.ShaderFactory factory = new ShapeDrawable.ShaderFactory() {
public Shader resize(int width, int height) {
final int[] colors = new int[]{ 0xFFFCDB7C, 0xFFE21C4D, 0xFF4832DF };
final float[] anchors = new float[]{ 0, .5f, 1 };
return new RadialGradient(width / 10, height, (float) (width * .8), colors, anchors, Shader.TileMode.CLAMP);
}
};
# Drawable.setShaderFactory(factory);
@mattsilber
mattsilber / replace_dimens_sdp.sh
Last active Sep 27, 2018
Script for converting all dip-related dimens to their sdp equivalents for use with https://github.com/intuit/sdp
View replace_dimens_sdp.sh
for i in {320..1};
do
val="$(((${i} * 7) / 10))"
if [ "${val}" -lt "1" ]
then
val="1"
fi
#echo $val
@mattsilber
mattsilber / convert_icon.sh
Created Jun 9, 2016
Take an SVG File and use inkscape to convert it to a PNG for each Android icon sizes
View convert_icon.sh
destFileName="${1/.svg/.png}"
sizes=( 48 72 96 144 192 512 )
for size in "${sizes[@]}"
do
mkdir $size/
inkscape -z -e $size/$destFileName -w $size -h $size $1
done
You can’t perform that action at this time.