Learned or Solved Something Today?

Dump it here! Let others learn from you

Write a kotlin hack
Showing 11 of 11 from page 1

metabox posted in #kotlin #beginners #tutorial

Kotlin - How to get maxMemory, freeMemory, totalMemory, used memory in megabytes and understand the differences between them

If you are new in kotlin or JVM based system and want to know how to get free memory total memory and max memory from the runtime class here s I have shared some example to answer some beginners quest

metabox posted in #kotlin #beginners #tutorial

Kotlin 1 Liner – Get number of available processors / CPU cores from runtime

An example Kotlin code snippet to show you how to get the number of available processors cores CPUs in your environment Get Available CPU s in Kotlin Runtime getRuntime availableProcessors You can als

anonymous posted in #kotlin #snippets #testing

Fixing WebTestClient Exception: Timeout on blocking read for 5000 MILLISECONDS

In Spring webflux tests I was having this timeout out issue and I wanted to increase timeout in the webclient Exception java lang IllegalStateException Timeout on blocking read for 500 MILLISECONDS a

anonymous posted in #kotlin #beginners #file #snippets

How To Read Entire Text / JSON File in 1 Line of Kotlin Code

I wanted to read an entire json file which contains my test request I found this very quick and super simple 1 line to read an entire file as string Quickest Solution File path my test json readText S

anonymous posted in #kotlin #beginners #file #snippets

How to get absolute path of my project or current working directory in Kotlin

Super simple trick to get the path of of your project folder in kotlin You can also use this example snippet for your java or spring project as well Example location of your main file Users my user co

anonymous posted in #kotlin #snippets #logging

Simple Trick for Getting a Logger Instance on Package Level Without Specifying Class

If you want to define a top level logger and access it from functions in the same file Here s how you can achieve this You can use this when you need A static logger without specifying the class name

anonymous posted in #kotlin #http #request #tutorial

Example HttpClient to send GET, POST, PUT, Patch requests in Kotlin Using OKHTTP3

Making requests become super easy in favor of okhttp3 This example implementation would help you to understand and create your own http client in kotlin and send requests Dependencies Let s start with

anonymous posted in #kotlin #beginners #springframework #snippets

How to Read All HTTP Headers in Kotlin Spring REST Controllers

If you are looking for reading and accessing request headers from your spring boot kotlin application, here are some example implementation that you can follow. Reading Header in Kotlin From Spring Http Request To read headers you can use @RequestHe

ikrum posted in #kotlin #java #gradle #build #snippets

Example build.gradle.kt to build a shadow jar for java and kotlin application | Fat Jar In Kotlin DSL

If you need an all in one Jar (Fat Jar) in Gradle with the Kotlin DSL syntax, Here is an example of how you can build a shadow jar for both java and kotlin application. Difference between Java vs Kotlin App If you are building kotlin spring-boot app

anonymous posted in #kotlin #snippets #encryption

How to generate HMAC SHA 256 Signature in Kotlin

Creating and validating signature is commonly use to verify the authenticity of a request. Heres a tiny kotlin function to generate HMAC signature from string data. Using the signature generator val signature = createSignature("myStringData", "mySec

anonymous posted in #kotlin #snippets #beginners #springwebflux

Spring WebFlux - Kotlin Middleware to Log Request

Today I've spent too much time writing a middleware in kotlin for spring webflux to log my request. As I am super new, It was pretty difficult to understand some of the complex examples on few tutorial found online. So I wanted to share the basic tem

fb