Skip to content

Instantly share code, notes, and snippets.

View ClausPolanka's full-sized avatar

Claus Polanka ClausPolanka

View GitHub Profile
@ClausPolanka
ClausPolanka / build.gradle.kts
Created December 4, 2023 12:17
Gradle custom tasks to compile with different Java versions
plugins {
id("java")
}
tasks.register("compileOn11", JavaCompile::class.java) {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
source = sourceSets["main"].allSource.asFileTree
classpath = sourceSets["main"].compileClasspath
@ClausPolanka
ClausPolanka / build.gradle.kts
Created November 6, 2023 17:51
Minimal Kotlin-Script Gradle build file for a Kotlin project using JUnit 5
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
@ClausPolanka
ClausPolanka / build.gradle.kts
Created November 6, 2023 17:20
Minimal Kotlin-Script Gradle build file for a Kotlin project (only compiling)
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
}
repositories {
mavenCentral()
}
class StandardType : ItemType {
override fun update(item: Item, on: LocalDate): Item {
val degredation = when {
on.isAfter(item.sellByDate) -> 2
else -> 1
}
return item.withQuality(item.quality - degredation)
}
@ClausPolanka
ClausPolanka / Redirectstdinout.java
Last active August 8, 2022 13:24
How to replace System.in and System.out in JUnit tests
private final InputStream systemIn = System.in;
private final PrintStream systemOut = System.out;
private ByteArrayInputStream testIn;
private ByteArrayOutputStream testOut;
@BeforeEach
public void setUpOutput() {
testOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(testOut));
@ClausPolanka
ClausPolanka / .zshrc
Last active January 7, 2022 12:33
My current .zshrc file
#
# Reset Mac default Path variable
#
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
#
# Add custom, local installations to PATH
#
@ClausPolanka
ClausPolanka / IOSP.kt
Created February 26, 2021 09:06
IOSP
fun main(args: Array<String>) {
errorHandled {
inCase(args.isEmpty(),
onEmpty = {
val peers = sortedPeers()
show(peers)
},
onNonEmpty = {
updatePeer(args)
val peers = sortedPeers()
package wordcount.io;
import wordcount.domain.Stopwords;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Collection;
package test.wordcount.fakes;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import static java.lang.String.join;
import static java.lang.System.lineSeparator;
public class FileSystemStopwordsTest {
private static final String STOPWORDS_FILE_PATH = "stopwords.txt";
private TestFileSystemStopwords stopwordsFile = new TestFileSystemStopwords(STOPWORDS_FILE_PATH);
private Stopwords fileSystemStopwords = new FileSystemStopwords(STOPWORDS_FILE_PATH);
@Test
public void stopwordsReturnsStopwordsFromFile() {
stopwordsFile.addStopword("stopword");
Collection<String> words = fileSystemStopwords.stopwords();