Skip to content

Instantly share code, notes, and snippets.

@alwarren
alwarren / Spy.java
Last active June 12, 2019 16:21
A generic class to retrive public methods and their names from a class.
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import static java.lang.System.out;
public class Spy {
public static List<Method> publicMethods(Class<?> clazz) {
@alwarren
alwarren / Euclid.java
Last active May 12, 2019 14:26
Euclidean calculations on one-dimensional array indices. A work in progress.
/**
* Euclidean calculations on one-dimensional array indices
*/
class Euclid {
/**
* Calculate the euclidean distance between two array indices
*
* @param current index
* @param goal index
* @return the distance from current to goal
@alwarren
alwarren / Compare.java
Last active May 1, 2019 15:11
Using JUnit5 to unit test adherence to the API specification of an immutable data type Point.
import org.junit.jupiter.params.converter.*;
import java.lang.annotation.*;
/*******************************************************************************
* Name: Compare.java
* Date: 4/30/2019
* Description: JUnit5 Parameterized Test Parameter Annotation
******************************************************************************/
@Target({ ElementType.ANNOTATION_TYPE, ElementType.PARAMETER })
@alwarren
alwarren / DequeSpecification.java
Last active April 24, 2019 13:52
Deque Specification Unit Tests
/**
* Description: A generic data type Deque.
*
* API Requirements:
*
* public class Deque<Item> implements Iterable<Item> {
* public Deque() // construct an empty deque
* public boolean isEmpty() // is the deque empty?
* public int size() // return the number of items on the deque
* public void addFirst(Item item) // add the item to the front
@alwarren
alwarren / KotlinGradleConversion.md
Last active April 24, 2019 15:41
Documents the process of converting a new Android project to Kotlin Gradle DSL.

Conversion from Gradle to Kotlin DSL

Tips

  • IMPORTANT: Things can break badly if you don't do things in the correct order. Make backups or if you're using version control, create branches that you can recover from.
  • Do changes step-wise. That is, for all gradle files change single quotes, then do syntax changes, then do the plugins block.
  • Sync Gradle often. Make each type of change for files then
@alwarren
alwarren / SrtFile.kt
Created April 4, 2019 19:59
Parse an SRT File (single line subtitles) [Kotlin]
import java.io.File
import java.nio.charset.Charset
class SrtFile(private val file: File, private val defaultCharset: Charset = Charset.forName("UTF-8")) {
private val _subtitles by lazy { parse() }
val subtitles: List<Subtitle> get() = _subtitles
private fun parse(): MutableList<Subtitle> {
val list = mutableListOf<Subtitle>()
@alwarren
alwarren / app.build.gradle.kts
Last active March 31, 2019 00:44
Android Kotin DSL
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
}
android {
compileSdkVersion(Versions.compileSdk)
defaultConfig {
@alwarren
alwarren / build.gradle
Last active February 6, 2019 01:43
Kotlin Build System
import java.text.DateFormat
import java.text.SimpleDateFormat
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: 'buildsystem/dependencies.gradle'
addRepos(repositories)
dependencies {
classpath deps.android_gradle_plugin
classpath deps.kotlin.kotlin_gradle_plugin
@alwarren
alwarren / colors_android_api_28.xml
Last active November 13, 2021 17:19
Android Colors
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/colors.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
@alwarren
alwarren / AndroidNotes.md
Created February 3, 2019 09:22
Android things I just can't seem to keep straight.

Android things I just can't seem to keep straight.

Theme Variants

  • Light means your environment is light - daytime.
  • Dark means your environment is dark - night time.

Colors

  • colorPrimary is the app bar
  • colorPrimaryDark is the status bar