Skip to content

Instantly share code, notes, and snippets.

View soudmaijer's full-sized avatar

Stephan Oudmaijer soudmaijer

View GitHub Profile
@soudmaijer
soudmaijer / SpringBootKotlinApplication.kt
Last active November 6, 2024 14:00
Separation of different application responsibilities
import jakarta.validation.Valid
import org.apache.logging.log4j.LogManager
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Table
import org.springframework.data.repository.CrudRepository
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
package nl.sourcelabs;
import com.hexadevlabs.gpt4all.LLModel;
import java.nio.file.Path;
import java.time.LocalDateTime;
public class Gpt4allJavaExample {
private String modelPath = "/Users/soudmaijer/gpt4all/models/ggml-gpt4all-j-v1.3-groovy.bin";
@soudmaijer
soudmaijer / SpringBootCamelApplication.kt
Last active February 21, 2023 08:36
Spring Boot application integrating Apache Camel
package nl.sourcelabs.springbootcamel
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
@SpringBootApplication
class SpringBootCamelApplication {
fun using_with() {
val stringBuilder = StringBuilder()
stringBuilder.append("Hello")
stringBuilder.append(", Kotlin!")
print(stringBuilder.toString())
}
fun using_also(a: Int): Int {
val b = a * 10
if (b > 100) print(">100")
import java.io.IOException
fun bar() {
throw IOException()
}
package nl.sourcelabs.kotlinflowboot.server
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
suspend fun loadImage200(name: String) {
delay(2000) // simulate slow behaviour
}
fun loadImage404(name: String) {
throw RuntimeException("Image not found: $name")
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() {
lateinit var a: Deferred<Nothing>
lateinit var b: Deferred<Unit>
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import java.lang.Thread.sleep
fun main() {
val a = GlobalScope.async { throw RuntimeException() }
val b = GlobalScope.async { delay(2000).also { println("I leaked!") } } // Will not be printed!
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import java.lang.Thread.sleep
fun main() {
val a = GlobalScope.async { throw RuntimeException() }
val b = GlobalScope.async { delay(2000).also { println("I leaked!") } } // Will not be printed!