Skip to content

Instantly share code, notes, and snippets.

@bastman
bastman / find_duplicate_row_ids.sql
Last active Jun 25, 2020
postgres: explore primary keys
View find_duplicate_row_ids.sql
SELECT my_id, COUNT(my_id)
FROM my_table
GROUP BY my_id
HAVING COUNT(my_id) > 1;
@bastman
bastman / k8s-create-job-from-cronjob.sh
Last active Jun 16, 2020
k8s create job from cronjob (how to run a cronjob now + once)
View k8s-create-job-from-cronjob.sh
$ kubectl create job --from=cronjob/<CRONJOB-NAME> <NEW-JOB-NAME>
e.g.:
$ kubectl create job --from=cronjob/my-cron my-cron-manual-001
function k8s-cronjob-run() {
source_cronjob_name=$1
[ -z "$source_cronjob_name" ] && echo "Please provide source-cronjob-name !" && return
sink_run_id=$(date -u +"%Y-%m-%dt%H.%M.%Sz")
View jmespath-tricks.txt
Images[].{a:length(BlockDeviceMappings), b:@} | [?a>=`1`]
Images[?length(BlockDeviceMappings)>=`0`]
View gradle_init_kotlin.sh
$ gradle init --type kotlin-application --dsl kotlin
@bastman
bastman / SpringTransactions.kt
Created Feb 21, 2020
playground for spring transactions
View SpringTransactions.kt
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 Feb 17, 2020
round bigdecimal, double in kotlin
View RoundKt.kt
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 Feb 13, 2020
gradle-init-kotlin-app.sh
View 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 Dec 12, 2019
kotlin phantom types example - (generics, extensions)
View phantomtypes.kt
// phantom types
// https://proandroiddev.com/phantom-types-in-kotlin-afd3f59fde10
sealed class DoorState
object Open: DoorState()
object Closed: DoorState()
/*
class Door(val state: DoorState) {
You can’t perform that action at this time.