Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / CartesianChallenge.md
Last active May 19, 2019 22:01
A simple Java challenge in Cartesian space.

A simple Java challenge. This really stumped me the first time I ran across it. I made it work but looking at the code made absolutley no sense. Give it a try and let me know how you do.

Consider the following values:

 8  1  3 
 4  0  2 
 7  6  5 
  1. Store the values in a two-dimensional array of int.
  2. Move the 0 up by modifying a single index and swapping two values.
@alwarren
alwarren / README.md
Last active July 21, 2019 17:46
Coursera Algorithms II WordNet Junit5 Test Suite

Coursera Algorithms II WordNet Junit5 Test Suite

Note

  1. This test suite is not exaustive.
  2. It requires removing the org.* restriction from auto import rules if you are using the IntelliJ project included in the course zip file. This is because the Junit5 development team used the based package org.junit.* instead of junit.* in many of the new libraries.
  3. It requires adding Junit5 dependencies.
@alwarren
alwarren / BaseballElimination.java
Last active June 17, 2019 05:08
Coursera Algorithms II BaseballElimination Junit5 Test Suite
/**
* Name: Al Warren
* Date: 6/16/2019
* Description: Test suite for an Immutable object type BaseballElimination.
*
* API Requirements:
*
* public BaseballElimination(String filename) // create a baseball division from given filename in format specified below
* public int numberOfTeams() // number of teams
* public Iterable<String> teams() // all teams