Skip to content

Instantly share code, notes, and snippets.

@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@bastman
bastman / jwtUntrusted.kt
Last active March 26, 2024 07:40
kotlin parse jwt untrusted - ignore signature
// see: https://github.com/auth0-blog/spring-boot-jwts/blob/master/src/main/java/com/example/security/TokenAuthenticationService.java
//Example:
val json:String= JwtUntrusted.parseClaimsUntrustedToJson("Bearer xxx")
object JwtUntrusted {
// requires (gradle): compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.0'
private val JSON = jacksonObjectMapper()
fun removeSignature(jwt:String) = jwt.replaceAfterLast(".", "").trim()
@bastman
bastman / cartesianProduct.kt
Last active November 11, 2023 07:14
Kotlin collections - leftJoin,innerJoin, ...
infix fun <T,O>List<T>.cartesianProduct(others:List<O>):List<Pair<T,O>> =
flatMap{ t:T->
others.map { o-> Pair(t,o) }
}
inline fun <T, O, R> List<T>.mapCartesianProduct(others: List<O>, transform: (Pair<T, O>) -> R): List<R> =
flatMap { t: T ->
others.map { o -> transform(Pair(t, o)) }
}
@bastman
bastman / railway.kt
Created July 27, 2023 14:57
railway-oriented-programming (kotlin, playgorund)
package com.example.demo
// based on ...
// https://www.reddit.com/r/Kotlin/comments/15b16px/little_example_of_railway_oriented_programming_in/
// https://github.com/GabrielLasso/Kotlin-railway-example
fun main() {
val pipeline: (data: Either<Throwable, Person>) -> Either<Throwable, Response> =
(::validate `→` ::save `→` ::notify `→` ::buildResponse)
@bastman
bastman / exposed-tricks.kt
Last active June 26, 2023 12:32
exposed tricks
# =========
# demo: https://github.com/JetBrains/Exposed/tree/master/src/test/kotlin/demo
# dml tests: https://github.com/JetBrains/Exposed/blob/master/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DMLTests.kt
# ===== GIS
https://github.com/JetBrains/Exposed/issues/459
# === native
@bastman
bastman / ExampleTest.kt
Last active June 4, 2023 21:25
junit5: Testfactory DSL (kotlin) - dynamic, nested tests ...
package com.example
import com.example.testutils.junit5.testFactory
import com.example.testutils.springTest.BootWebMockMvcTest
import mu.KLogging
import org.amshove.kluent.shouldEqual
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestFactory
import org.springframework.beans.factory.annotation.Autowired
import java.math.BigDecimal
@bastman
bastman / README.md
Last active May 11, 2023 07:55
parse erb templates from command line (standalone, cli, json)

Goal

  • provide cli command to render erb template
  • template params (bindings) to be provided using json format
  • use inputs from file (template.erb, params.json)
  • use inputs from cli options / parameters
  • render output to stdout OR to file

Why ?

@bastman
bastman / auth0.kt
Last active March 3, 2023 09:48
kotlin-spring-security-auth0-api-utils: extensions for auth0 (e.g. handle custom claims)
package com.example.auth0utils
import com.auth0.jwk.JwkProviderBuilder
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.exceptions.JWTDecodeException
import com.auth0.jwt.exceptions.JWTVerificationException
import com.auth0.jwt.interfaces.DecodedJWT
import com.auth0.spring.security.api.JwtAuthenticationEntryPoint
import com.auth0.spring.security.api.JwtAuthenticationProvider
@bastman
bastman / gist:87b6f5cc018da63e446ba25d72a79fb0
Created October 9, 2018 12:11
bash_profile: make autocomplete
# .bashrc: see: https://stackoverflow.com/questions/33760647/makefile-autocompletion-on-mac
function _makefile_targets {
local curr_arg;
local targets;
# Find makefile targets available in the current directory
targets=''
if [[ -e "$(pwd)/Makefile" ]]; then
targets=$( \
grep -oE '^[a-zA-Z0-9_-]+:' Makefile \
@bastman
bastman / collections.kt
Last active February 1, 2023 03:15
kotlin: How to join 2 collections by a foreign key predicate
data class Off(val id: Int, val offName: String)
data class Prop(val id: Int, val propName: String, val offId: Int)
data class Joined(val off: Off, val props: List<Prop>)
fun main(args: Array<String>) {
val offs: List<Off> = listOf(
Off(id = 1, offName = "Off A"),
Off(id = 2, offName = "Off B")
)
val props: List<Prop> = listOf(