Skip to content

Instantly share code, notes, and snippets.

View s1monw1's full-sized avatar
☁️
Hello, cloud.

Simon Wirtz s1monw1

☁️
Hello, cloud.
View GitHub Profile
@s1monw1
s1monw1 / build.grade.kts
Created December 1, 2017 23:46
Blog Post Example Script
import org.gradle.kotlin.dsl.extra
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion
val kotlinCoroutinesVersion = "0.19.3"
val vertxVersion = "3.5.0"
val nexusRepo = "http://x.x.x.x:8080/nexus/content/repositories/releases"
class LazyContextAware<out T>(private val initializer: (Any?) -> T) : ReadOnlyProperty<Any?, T> {
private object UNINITIALIZED_VALUE
private var prop: Any? = UNINITIALIZED_VALUE
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return if (prop == UNINITIALIZED_VALUE) {
synchronized(this) {
return if (prop == UNINITIALIZED_VALUE) {
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.jfrog.bintray.gradle.BintrayPlugin
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.gradle.api.publish.maven.MavenPom
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.jfrog.bintray.gradle.BintrayExtension
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion
@s1monw1
s1monw1 / hello.kt
Created April 11, 2018 18:12
Kotlin Hello World
fun main(args: Array<String>) {
println("Hello Kotlin World")
}
data class PageableDTO(val offset: Int, val limit: Int, val sortBy: String? = null, val ascending: Boolean? = null)
fun PageableDTO.injectDefaults() =
copy(sortBy = if (sortBy?.isNotEmpty() == true) sortBy else "created_ts", ascending = ascending ?: true)
fun main(args: Array<String>) {
val pageableDTO = PageableDTO(1, 2)
val withDefaults = pageableDTO.injectDefaults()
}
@s1monw1
s1monw1 / singleexp.kt
Last active September 2, 2022 21:34
Medium Java vs Kotlin single expression
fun trueOrFalse() = Random().nextBoolean()
public class SingleExpFun {
private BooleanSupplier trueOrFalse = new Random()::nextBoolean;
private boolean getNext(){
return trueOrFalse.getAsBoolean();
}
}
public class Overloader {
public void test(int a, boolean printToConsole) {
if (printToConsole) {
System.out.println("int a: " + a);
}
}
public void testWithoutPrint(int a) {
test(a, false);
}
public void test(int a) {
fun test(a: Int, printToConsole: Boolean = true) {
if (printToConsole) println("int a: " + a)
}
fun testWithoutPrint(a: Int) = test(a, false)
fun main(args: Array) {
testWithoutPrint(2)
test(2)
}
class Turtle {
fun penDown()
fun penUp()
fun turn(degrees: Double)
fun forward(pixels: Double)
}
with(Turtle()) {
penDown()
for(i in 1..4) {