Skip to content

Instantly share code, notes, and snippets.

@vbsteven
vbsteven / prepend.sh
Created July 19, 2019 09:11
Prepend one file to another in bash
# this will find all folders with a file named versions.tf
# and prepend its contents to the file main.tf in the same directory
for p in $(find -name "versions.tf"); do
main=$(echo $p | sed 's/versions/main/' );
echo -e "$(cat $p)\n\n$(cat $main)" > $main;
done
@vbsteven
vbsteven / CustomerRestDocs.kt
Created May 1, 2019 14:19
Spring Rest Docs documentationConfiguration with JUnit5 and Kotlin
package io.license.core.restdocs
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.restdocs.RestDocumentationContextProvider
import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName
@vbsteven
vbsteven / build.gradle
Created April 10, 2019 07:29
Kotlinx.deserialization example
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21"
classpath "org.jetbrains.kotlin:kotlin-serialization:1.3.21"
@vbsteven
vbsteven / not_calling_constructor.kt
Created April 9, 2019 09:17
Gson constructor test in Kotlin
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
val json = """
{
"History":
[
{"Added": 2000}
]
@vbsteven
vbsteven / Validators.kt
Created April 8, 2019 16:27
Custom Spring annotation and validator in Kotlin
package io.license.core.validation
import javax.validation.Constraint
import javax.validation.ConstraintValidator
import javax.validation.ConstraintValidatorContext
import javax.validation.Payload
import kotlin.reflect.KClass
@Target(AnnotationTarget.FIELD)
@vbsteven
vbsteven / build.gradle.kts
Last active March 8, 2020 17:18
Minimal Gradle Kotlin DSL for Junit5 project
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
val kotlinVersion = "1.3.21"
kotlin("jvm") version kotlinVersion
java // required by JUnit
}
group = "io.quantus"
version = "1.0-SNAPSHOT"
@vbsteven
vbsteven / ApiModule.java
Created November 19, 2015 10:54
Retrofit ApiModule I frequently use to provide custom app-level http caching
package io.quantus.winterinantwerpen.api;
import android.content.Context;
import android.location.LocationManager;
import android.util.Log;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
[color]
ui = auto
[alias]
co = checkout
br = branch
ci = commit
st = status -sb
visual = qgit4
df = diff
dfs = diff --staged
@vbsteven
vbsteven / TestArray.java
Last active November 19, 2015 09:58
Two Java implementations for a small language benchmark Matthew Jackowski did. http://www.marcinkliks.pl/2015/02/22/swift-vs-others/
/**
* Created by @vbsteven on 09/10/15.
*
* Run with "javac TestArray.java && java TestArray"
*/
public class TestArray {
public static void main(String[] args) {
long sum = 0;
;; json formatting functions
;; replace region with json formatted version
(defun json-format ()
(interactive)
(save-excursion
(shell-command-on-region (mark) (point) "python -m json.tool" (buffer-name) t)
)
)