Skip to content
Permalink
Browse files

Added Dockerfile and new tests

  • Loading branch information
jrtapsell committed Feb 28, 2018
1 parent 260f1e4 commit 7a680ea3737e0ff287229d2d6566add40ccd4320
@@ -1,3 +1,4 @@
*.iml

# Created by https://www.gitignore.io/api/gradle,kotlin,intellij+all

@@ -5,17 +5,11 @@
- Any.i()

Converts anything to an integer

> "1".i() + "3".i()
< 4

- Any.s()

Converts anything to a string

> 1.s()
< "1"
## IO

- P(x)
@@ -35,7 +29,11 @@

- f(predicate)

Shortening of filter
Shortening of filter (optional index)

- F(folder)

Shortening of fold (optional index)

- c()

@@ -0,0 +1,18 @@
FROM gradle:alpine
USER root
ADD . ./

RUN gradle jar

FROM openjdk

WORKDIR /app

COPY --from=0 /home/gradle/build/libs/* app.jar
COPY runner/* ./
RUN chmod +x run.sh
RUN apt-get update && apt-get install zip
RUN curl -s "https://get.sdkman.io" | bash
RUN ["/bin/bash", "-c", "source /root/.sdkman/bin/sdkman-init.sh;sdk install kotlin"]

CMD ["/bin/bash", "-c", "/app/run.sh"]
@@ -0,0 +1,35 @@
buildscript {
ext.kotlin_version = '1.2.21'

repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

group "uk.co.jrtapsell"
version "1.0-SNAPSHOT"

apply plugin: 'java'
apply plugin: 'kotlin'

sourceCompatibility = 1.9

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile group: 'org.testng', name: 'testng', version: '6.13.1'

}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

This file was deleted.

BIN -373 Bytes (99%) gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
@@ -1,6 +1,5 @@
#Mon Feb 05 10:34:25 GMT 2018
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
@@ -0,0 +1,5 @@
package jotlin.lang

/**
* Generated by the Jotlin compiler.
*/
@@ -0,0 +1,10 @@
#!/bin/bash

cd /app

cat header.kt > script.kts
cat - >> script.kts

source /root/.sdkman/bin/sdkman-init.sh

kotlinc -script script.kts -cp . -include-runtime -d app.jar
@@ -1,3 +1,2 @@
rootProject.name = 'Jotlin'
rootProject.buildFileName = 'build.gradle.kts'

This file was deleted.

@@ -1,11 +1,36 @@
package jotlin.lang
/**
* Converts to an Integer.
*
* > "1".i()
* < 1
* @param radix
* The radix to use _(defaults to 10)_
*/
fun Any?.i(radix:Int=10) = toString().toInt(radix)

/**
* Converts to a String.
*
* > 1.s()
* < "1"
*/
fun Any?.s() = toString()
fun Any?.s() = toString()

/** Allows for the radix of s() to be set.
*
* > 1.s()
* < "1"
* > 10.s(2)
* < 2
*/
fun Int.s(radix: Int=10) = toString(radix)
/**
* Allows for the radix of s() to be set.
*
* > 1L.s()
* < "1"
* > 10L.s(2)
* < 2
*/
fun Long.s(radix: Int=10) = toString(radix)
@@ -1,35 +1,30 @@
package jotlin.lang

import java.util.Base64
import java.io.ByteArrayOutputStream
import java.util.zip.Deflater
import java.util.zip.Inflater

/** Prints whatever is passed to it, followed by a newline. */
fun Any.P(data: Any?) = println(this)
fun P(data: Any?) = println(data)

/** Prints multiple items as a list, followed by a newline. */
fun P(vararg data: Any?) = println(data.asList())
/** Prints multiple items. */
fun P(vararg data: Any?) = println(data.j(","))

/** Prints whatever is passed to it *without* a newline. */
fun Any.p(data: Any?) = print(this)
/** Prints multiple items as a list *without* a newline. */
fun p(vararg data: Any?) = print(data.asList())
/** Prints multiple items *without* a newline. */
fun p(vararg data: Any?) = print(data.j(","))

/** Deflates input as a Base64 encoded input. */
fun d(input: String): String {
val deflater = Deflater(9)
val deflater = Inflater()
deflater.setInput(Base64.getDecoder().decode(input))
deflater.finish()
val buffer = ByteArray(1000)
val buffer = ByteArray(1024)
val outputStream = ByteArrayOutputStream()
while (!deflater.finished()) {
val count = deflater.deflate(buffer)
val count = deflater.inflate(buffer)
outputStream.write(buffer, 0, count)
}
val size = deflater.totalOut
val temp = ByteArray(size - 6)
/*
Java gives a header, which nothing else likes.
https://stackoverflow.com/a/5698317/8041461
*/
return String(temp, 2, size-6)
}
val temp = outputStream.toByteArray()
return String(temp)
}
@@ -1,28 +1,84 @@
package jotlin.lang

/** Acts as a shortened map. */
infix fun <T,R> Iterable<T>.m(transform: (T)->R) = map(transform)
/** Acts as a shortened map. */
infix fun <T,R> Sequence<T>.m(transform: (T)->R) = map(transform)
/** Acts as a shortened map. */
infix fun <T,R> Array<T>.m(transform: (T)->R) = map(transform)

/** Acts as a shortened indexed map. */
infix fun <T,R> Iterable<T>.m(transform: (Int, T)->R) = mapIndexed(transform)
/** Acts as a shortened indexed map. */
infix fun <T,R> Sequence<T>.m(transform: (Int, T)->R) = mapIndexed(transform)
/** Acts as a shortened indexed map. */
infix fun <T,R> Array<T>.m(transform: (Int, T)->R) = mapIndexed(transform)

/** Acts as a shortened filter. */
infix fun <T> Iterable<T>.f(transform: (T)->Boolean) = filter(transform)
/** Acts as a shortened filter. */
infix fun <T> Sequence<T>.f(transform: (T)->Boolean) = filter(transform)
/** Acts as a shortened filter. */
infix fun <T> Array<T>.f(transform: (T)->Boolean) = filter(transform)

/** Acts as a shortened indexed filter. */
infix fun <T> Iterable<T>.f(transform: (Int, T)->Boolean) = filterIndexed(transform)
/** Acts as a shortened indexed filter. */
infix fun <T> Sequence<T>.f(transform: (Int, T)->Boolean) = filterIndexed(transform)
/** Acts as a shortened indexed filter. */
infix fun <T> Array<T>.f(transform: (Int, T)->Boolean) = filterIndexed(transform)

/** Acts as a shortened fold. */
fun <T,U> Iterable<T>.F(seed: U, transform: (U, T)->U) = fold(seed, transform)
/** Acts as a shortened fold. */
fun <T,U> Sequence<T>.F(seed: U, transform: (U, T)->U) = fold(seed, transform)
/** Acts as a shortened fold. */
fun <T,U> Array<T>.F(seed: U, transform: (U, T)->U) = fold(seed, transform)

/** Acts as a shortened indexed fold. */
fun <T,U> Iterable<T>.F(seed: U, transform: (Int, U, T)->U) = foldIndexed(seed, transform)
/** Acts as a shortened indexed fold. */
fun <T,U> Sequence<T>.F(seed: U, transform: (Int, U, T)->U) = foldIndexed(seed, transform)
/** Acts as a shortened indexed fold. */
fun <T,U> Array<T>.F(seed: U, transform: (Int, U, T)->U) = foldIndexed(seed, transform)

/** Counts each of the distinct items. */
fun <T> Iterable<T>.c() = groupingBy { it }.eachCount()
/** Counts each of the distinct items. */
fun <T> Sequence<T>.c() = groupingBy { it }.eachCount()
/** Counts each of the distinct items. */
fun <T> Array<T>.c() = groupingBy { it }.eachCount()

/** Joins to a string.*/
fun <T> Iterable<T>.j(sep:String=",", block:T.()->Any?={this}) = joinToString(sep) { it.block().toString() }
/** Joins to a string. */
fun <T> Sequence<T>.j(sep:String=",", block:T.()->Any?={this}) = joinToString(sep) { it.block().toString() }
/** Joins to a string. */
fun <T> Array<T>.j(sep:String=",", block:T.()->Any?={this}) = joinToString(sep) { it.block().toString() }

/** Converts to a sequence. */
fun <T> Iterable<T>._s() = asSequence()
/** Converts to a sequence. */
fun <T> Array<T>._s() = asSequence()

/** Converts to an iterable. */
fun <T> Sequence<T>._i() = asIterable()
/** Converts to an iterable. */
fun <T> Array<T>._i() = asIterable()

/** Converts to an array. */
inline fun <reified T> Sequence<T>._a() = toList().toTypedArray()
/** Converts to an array. */
inline fun <reified T> Iterable<T>._a() = toList().toTypedArray()

/** Converts to a mutable list. */
inline fun <reified T> Iterable<T>._l() = toMutableList()
/** Converts to a mutable list. */
inline fun <reified T> Sequence<T>._l() = toMutableList()
/** Converts to a mutable list. */
inline fun <reified T> Array<T>._l() = toMutableList()

/** Generates a sequence. */
fun <T: Any> g(nextFun: () -> T) = generateSequence(nextFun)
/** Generates a sequence. */
fun <T: Any> g(seed: T, nextFun: (T) -> T) = generateSequence(seed, nextFun)
@@ -1,2 +1,7 @@
package jotlin.lang

/** Creates a list. */
fun <T> l(vararg items: T) = mutableListOf(*items)

/** Creates an array. */
fun <T> a(vararg items: T) = items
@@ -1,4 +1,13 @@
package jotlin.lang

/** Creates a regex. */
fun R(input: String) = Regex(input)
/** Counts the number of times each character appears. */
fun c(input: String) = input.groupingBy { it }.eachCount()

/** Replaces the given regex with the given text. */
fun String.r(regex: Regex, text: String) = replace(regex, text)
fun String.r(find: String, replace: String) = replace(find, replace)
/** Replaces the given text with the given text. */
fun String.r(find: String, replace: String) = replace(find, replace)
/** Replaces the given regex with the given substitution. */
fun String.r(find: Regex, block:(MatchResult)->CharSequence) = replace(find, block)

0 comments on commit 7a680ea

Please sign in to comment.
You can’t perform that action at this time.