Skip to content

Instantly share code, notes, and snippets.

Images[].{a:length(BlockDeviceMappings), b:@} | [?a>=`1`]
Images[?length(BlockDeviceMappings)>=`0`]
$ gradle init --type kotlin-application --dsl kotlin
@bastman
bastman / SpringTransactions.kt
Created February 21, 2020 10:51
playground for spring transactions
fun PlatformTransactionManager.transactionTemplate(propagationBehavior:Int = TransactionDefinition.PROPAGATION_REQUIRED) = TransactionTemplate(this)
.apply {
this.propagationBehavior=propagationBehavior
}
fun <T>TransactionTemplate.tryExecute(block:(TransactionStatus)->T):Try<T> = Try { this.execute(block) as T }
@Component
class MyTx() {
@bastman
bastman / RoundKt.kt
Created February 17, 2020 15:25
round bigdecimal, double in kotlin
import java.math.*
fun main() {
println("Hello, world!!!")
val myValue=-1.25
val out = BigDecimal(myValue).setScale(1, RoundingMode.HALF_UP).toDouble();
println("$out")
}
@bastman
bastman / gradle-init-kotlin-app.sh
Last active February 13, 2020 06:54
gradle-init-kotlin-app.sh
$ sdk install gradle 6.1.1
$ sdk use gradle 6.1.1
$ gradle wrapper --gradle-version=6.1.1
$ ./gradlew init --type kotlin-application --dsl kotlin
@bastman
bastman / phantomtypes.kt
Created December 12, 2019 14:30
kotlin phantom types example - (generics, extensions)
// phantom types
// https://proandroiddev.com/phantom-types-in-kotlin-afd3f59fde10
sealed class DoorState
object Open: DoorState()
object Closed: DoorState()
/*
class Door(val state: DoorState) {
@bastman
bastman / awesome-secret-files-encrypt.md
Created November 27, 2019 06:58
how to encrypt/decrypt secret files ?

how to encrypt/decrypt secret files ?

mozilla sops is an editor of encrypted files that supports YAML, JSON, ENV, INI and BINARY formats and encrypts with AWS KMS, GCP KMS, Azure Key Vault and PGP

@bastman
bastman / annotations.kt
Created November 21, 2019 15:10
spring-kotlin: custom annotations example
/**
* Annotations: @RestApiQueryHandler, @RestApiMutationHandler
* as specialization of @Component
* see: @Service for impl.
*
*/
import org.springframework.core.annotation.AliasFor
import org.springframework.stereotype.Component
@kotlin.annotation.Target(AnnotationTarget.CLASS)