Skip to content

Instantly share code, notes, and snippets.

View hkakutalua's full-sized avatar
🎯
Focusing

Henrick hkakutalua

🎯
Focusing
View GitHub Profile
@hkakutalua
hkakutalua / Taming Recursion - Introduction.md
Last active February 6, 2022 21:56
Taming Recursion - Introduction

Taming Recursion - An Introduction

[[Image]]

Recursion, which ends up being way simpler for some problems, can seem very hard for you to wrap your head around, or to follow down the recursive rabbit-hole to understand how it produces the values it does (spoiler: doing this may be a mistake).

But do not despair, I'm here to help you learn a very good framework to think recursively in any programming language and almost any problem.

Every code example will be in Scala a programming language that combines the object-oriented and functional programming paradigms. It will be very straightforward to translate the examples from Scala to your language of choice since the syntax is very much approachable.

@hkakutalua
hkakutalua / challenge_1_chat_application.md
Created January 31, 2022 15:05
Chat Application - Challenge Project

Chat Application

A very simple instant messaging application to practice Scala, Kafka, and Docker.

Features

Enter Chat Room

The user should be able to enter the chat room with its id name, name and age. The id name it is used so he can be persisted temporarily to later reenter to read messages not yet read.

Leave Chat Room

The user should be able to leaver the chat room.

@hkakutalua
hkakutalua / SpringFoxConfig.java
Created August 24, 2020 14:32
Configure JsonNullable as simple type for Spring Fox
@Configuration
@EnableSwagger2
public class SpringFoxConfiguration {
@Bean
@Primary
public Docket swaggerSpringfoxApiDocket(List<SwaggerCustomizer> swaggerCustomizers,
ObjectProvider<AlternateTypeRule[]> alternateTypeRules) {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
@hkakutalua
hkakutalua / Cart.kt
Created July 19, 2020 10:49
Changed fetch to FetchType.EAGER
@Entity
@Table(name = "carts")
class Cart : DomainEntity() {
@OneToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL], orphanRemoval = true)
private val _items = mutableListOf<ProductItem>()
...
}
@hkakutalua
hkakutalua / PostgresDbCleanerExtension.kt
Created July 19, 2020 10:28
PostgresDbCleanerExtension cleanTablesData
@Throws(SQLException::class)
private fun cleanTablesData(tablesNames: List<TableData>, connection: Connection) {
if (tablesNames.isEmpty()) {
return
}
val stringBuilder = StringBuilder("TRUNCATE ")
for (i in tablesNames.indices) {
if (i == 0) {
stringBuilder.append(tablesNames[i].fullyQualifiedTableName)
} else {
@hkakutalua
hkakutalua / PostgresDbCleanerExtension.kt
Created July 19, 2020 10:26
PostgresDbCleanerExtension loadTablesToClean
@Throws(SQLException::class)
private fun loadTablesToClean(connection: Connection): List<TableData> {
val databaseMetaData = connection.metaData
val resultSet = databaseMetaData.getTables(
connection.catalog, null, null, arrayOf("TABLE"))
val tablesToClean = mutableListOf<TableData>()
while (resultSet.next()) {
val table = TableData(
schema = resultSet.getString("TABLE_SCHEM"),
@hkakutalua
hkakutalua / PostgresDbCleanerExtension.kt
Last active August 30, 2023 07:46
PostgresDbCleanerExtension
class PostgresDbCleanerExtension : BeforeEachCallback {
companion object {
private val LOGGER = LoggerFactory.getLogger(PostgresDbCleanerExtension::class.java)
private val TABLES_TO_IGNORE = listOf(
TableData("databasechangelog"),
TableData("databasechangeloglock")
)
}
@hkakutalua
hkakutalua / CartsControllerTests.kt
Created July 19, 2020 10:16
Test wth PostgresDbCleanerExtension
@SpringBootTest
@ExtendWith(PostgresDbCleanerExtension::class)
internal class CartsControllerTests {
@Autowired
lateinit var cartsRepository: CartsRepository
@Autowired
lateinit var webApplicationContext: WebApplicationContext
...
@RestController
@RequestMapping("carts/{cart_id}/items")
class CartItemsController(
private val cartsRepository: CartsRepository,
private val productsRepository: ProductsRepository) {
@PostMapping
fun addItemToCart(
@PathVariable("cart_id") cartId: UUID,
@RequestBody cartItem: CartItemInputModel
@hkakutalua
hkakutalua / CartItemsControllerTests.kt
Created July 19, 2020 04:57
LazyInitializationException
val product = productsRepository.findByIdOrNull(cartItem.productId)
if (product == null) {
return ResponseEntity.notFound().build()
}
val cart = cartsRepository.findByIdOrNull(cartId)
if (cart == null) {
return ResponseEntity.notFound().build()
}