Skip to content

Instantly share code, notes, and snippets.

@bastman
bastman / git_revert_to_commit_hash.sh
Created November 2, 2018 11:49
git_revert_to_commit_hash.sh
# see: https://gist.github.com/l1x/3863190
#http://stackoverflow.com/a/6457473/127508
git checkout 56e05fced -- .
git add .
git commit -m 'Revert to 56e05fced'
And to prove that it worked:
git diff 56e05fced
@bastman
bastman / start_idea.sh
Created October 15, 2018 14:32
open intellij from terminal
open -a /Applications/IntelliJ\ IDEA.app
@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 / acklistener.kt
Last active September 3, 2018 10:49
spring_kafka_without_annotations
@Bean
fun container(
): KafkaMessageListenerContainer<String, String> {
val listener = object : AcknowledgingMessageListener<String, String> {
override fun onMessage(record: ConsumerRecord<String, String>, acknowledgment: Acknowledgment) {
logger.info { "Received: ${record.value()}" }
val event: NewMailEvent = deserializeEvent(eventJson = record.value()) ?: return
try {
newMailEventHandler.handle(newMailEvent = event)
} catch (all: Exception) {
@bastman
bastman / postgres_alter_enum.txt
Last active October 27, 2021 04:11
postgres - update enum values
// https://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/
ADD VALUE (PG 9.x)
=========
# PG 9.6: works from flyway.
ALTER TYPE AUDIT_DATABASE_EVENT_TYPE ADD VALUE 'foo';
RENAME VALUE (PG 10.x)
=============
# PG 10.+: works from flyway (not supported in PG 9.x)
@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 / forwardCompose.kt
Created August 11, 2018 08:07
FP forwardCompose: andThen, andAlso
/**
* Example: forward compose
*
* see:
* - https://discuss.kotlinlang.org/t/pipe-forward-operator/2098/43
* - https://hackernoon.com/funktionale-function-composition-for-kotlin-1f6e3e3c3a83
*
* val composition = ::sqrt thenAlso ::println then ::sqrt thenAlso ::println
* val result:Double = composition(16.0)
*/
@bastman
bastman / binder.kt
Created April 19, 2018 06:21
Extensions for binding configuration properties in spring boot (kotlin)
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.convertValue
import org.springframework.boot.context.properties.bind.Bindable
import org.springframework.boot.context.properties.bind.Binder
import org.springframework.core.env.Environment
/*
Example:
val stuff:MyAwesomeDataClass = bindEnvironmentProperties(
@bastman
bastman / postgres_time_constraints.md
Last active March 24, 2018 10:07
postgres timestamp constraints

´´´

DROP TABLE A;

CREATE TABLE A ( id CHARACTER VARYING(255) NOT NULL PRIMARY KEY, modified_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),

category CHARACTER VARYING(255) NOT NULL, is_active boolean NOT NULL DEFAULT TRUE

@bastman
bastman / codegen.sh
Created March 15, 2018 12:23
swagger-codegen-kotlin: generate kotlin client / model from swagger.json
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
-i /local/swagger.json \
-l kotlin \
-o /local/out/kotlin
# help
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli help generate