Skip to content

Instantly share code, notes, and snippets.

@bastman
bastman / testcafe.sh
Last active November 25, 2019 17:55
testcafe docker example
# clone the testcafe example repo
$ git clone [email protected]:DevExpress/testcafe.git
$ cd testcafe
# run docker headless
$ docker run --rm -it -v ${PWD}:/tests tomdesinto/testcafe:latest testcafe 'chromium:headless --no-sandbox' '/tests/examples/basic/test.js'
# run docker chrome
$ docker run --rm -it -v ${PWD}:/tests tomdesinto/testcafe:latest testcafe 'chromium --no-sandbox' '/tests/examples/basic/test.js'
@bastman
bastman / docker-compose.yml
Last active February 11, 2019 11:07
spring-boot: cli arguments, properties, etc examples
command: ["java"]
args: [
"-jar",
"-Dspring.profiles.active=dev,flyway-migrate",
"-Dlogging.level.com.zaxxer.hikari=debug",
"-Dspring.datasource.hikari.maximumPoolSize=50",
"-Xms32m",
"-Xmx1024m",
"/opt/app/app.jar --debug"
]
@bastman
bastman / isNullable.kt
Created February 10, 2019 12:54
kotlin: isNullable
inline fun <reified T> query(content: String, query: String): T {
try {
val expression: Expression<JsonNode> = compile(query = query)
val resultNode: JsonNode = search(content = content, expression = expression)
val converted: T = converter.convertValue(resultNode)
val isNullable: Boolean = null is T
if (converted == null && !isNullable) {
error("Failed to convert to (non-nullable) instance of ${T::class} from $resultNode .")
}
@bastman
bastman / 001.Makefile
Created February 5, 2019 06:17
Makefile - help
.PHONY : help
.DEFAULT_GOAL := help
help : Makefile
@sed -n 's/^##//p' $<
## foo : do foo
foo:
@echo "FOOOOOO"
## bar : do bar
bar:
@bastman
bastman / Listener.kt
Created January 25, 2019 08:30
spring-kafka-consumer: seek to beginning example
class MyListener() : ConsumerSeekAware
override fun onPartitionsAssigned(
assignments: MutableMap<TopicPartition, Long>?,
callback: ConsumerSeekAware.ConsumerSeekCallback?
) {
logger.info { "on partitions assigned: ${assignments?.toMap()}" }
if (fromBeginning && !soughtToBeginning.get()) {
val assignedTopicPartitions = assignments?.map { it.key } ?: error("no assignments found")
@bastman
bastman / http4_client_basic_auth.kt
Last active January 11, 2019 14:34
http4-client: basic auth
private val lowLevelClient = OkHttp() // ApacheClient()
private val client = ClientFilters.BasicAuth(
user = config.apiUser, password = config.apiPassword
).then(lowLevelClient)
@PreDestroy
fun preDestroy() {
logger.info { "CLOSE http client" }
lowLevelClient.close()
}
@bastman
bastman / gist:f52c7f02daf930537c1d475403262790
Created January 8, 2019 13:42
webflux 5.1 reactor - set timeout
https://stackoverflow.com/questions/46235512/spring-5-webflux-how-to-set-a-timeout-on-webclient
@bastman
bastman / ab.sh
Last active January 7, 2019 15:18
siege benchmark on k8s
$ docker run --rm -it ubuntu bash
$ kubectl run --rm -it ubuntu --image=ubuntu bash
$ apt-get update
$ apt-get install apache2-utils
@bastman
bastman / k8s-local-deployment.yml
Created November 17, 2018 10:42
how to deploy a local build docker image to local k8s (docker-edge) - without registry
# the trick: setting the imagePullPolicy to Never.
# see:
# - https://stackoverflow.com/questions/50739405/docker-for-macedge-kubernetes-reference-local-image
# or: https://github.com/dockersamples/example-voting-app/blob/master/kube-deployment.yml
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: local-nginx-sebtest
labels:
@bastman
bastman / Jackson.kt
Last active November 13, 2018 08:07
Kotlin Extensions for Jackson Json (and spring-boot): e.g. ParameterizedTypeReference, TypeReference
package example.util.jackson
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.springframework.core.ParameterizedTypeReference
import java.lang.reflect.Type
interface ToJson {
val objectMapper: ObjectMapper