Skip to content

Instantly share code, notes, and snippets.

bastman / DoubleExt.kt
Last active Jul 27, 2021
fun Double.round(decimals:Int)
View DoubleExt.kt
// see discussion on alternatives here:
fun Double.round(decimals:Int, roundingMode:RoundingMode=RoundingMode.HALF_EVEN):Double =
toBigDecimal().setScale(decimals, roundingMode).toDouble()
# ???
fun Double.round2(decimals: Int): Double {
val locale:Locale = Locale.US
val aTxt:String = String.format(locale, "%.${decimals+1}f", this)
val aDouble:Double = aTxt.toDouble()
bastman / jmespath-groupBy.kt
Created Jul 14, 2021
groupBy impl for JMESPath (proof-of-concept)
View jmespath-groupBy.kt
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.fasterxml.jackson.databind.node.ObjectNode
import io.burt.jmespath.Adapter
import io.burt.jmespath.JmesPath
import io.burt.jmespath.JmesPathType
import io.burt.jmespath.RuntimeConfiguration
import io.burt.jmespath.function.ArgumentConstraints
import io.burt.jmespath.function.BaseFunction
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 /
Last active Jun 16, 2020
k8s create job from cronjob (how to run a cronjob now + once)
$ kubectl create job --from=cronjob/<CRONJOB-NAME> <NEW-JOB-NAME>
$ kubectl create job --from=cronjob/my-cron my-cron-manual-001
function k8s-cronjob-run() {
[ -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`]
$ gradle init --type kotlin-application --dsl kotlin
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 {
fun <T>TransactionTemplate.tryExecute(block:(TransactionStatus)->T):Try<T> = Try { this.execute(block) as T }
class MyTx() {
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();