Skip to content

Instantly share code, notes, and snippets.

View Sedose's full-sized avatar
:shipit:

Sedose Sedose

:shipit:
  • Ukraine
View GitHub Profile
@Sedose
Sedose / Main.kt
Last active April 16, 2025 12:05
Showcase Kotlin + Mapstruct to do deepcopy data classes with nested properties. Also self referential type included
// org/example/Main.kt
package org.example
import org.mapstruct.Mapper
import org.mapstruct.control.DeepClone
import org.mapstruct.factory.Mappers
@Mapper(mappingControl = DeepClone::class)
interface DeepCopyMapper {
import java.io.OutputStream
import java.io.PrintStream
inline fun <T> withSystemOutRedirectedTo(stream: OutputStream, block: () -> T): T {
val originalOut = System.out
System.setOut(PrintStream(stream))
return try {
block()
} finally {
System.setOut(originalOut)
@Sedose
Sedose / core.clj
Created April 10, 2025 14:22
Body Mass Index (BMI) calculator. Run here https://onecompiler.com/clojure/43ee8z4my
(ns bmi-calculator.core)
(defn calculate-bmi [weight-kg height-m]
(/ weight-kg (* height-m height-m)))
(defn classify-bmi [bmi]
(cond
(< bmi 18.5) "Underweight"
(< bmi 24.9) "Normal weight"
(< bmi 29.9) "Overweight"
@Sedose
Sedose / find_all_tables_and_columns.sql
Last active April 5, 2025 04:52
PostgreSQL. Find all tables and columns
SELECT
table_schema,
table_name,
string_agg(column_name, ', ' ORDER BY ordinal_position) AS columns
FROM information_schema.columns
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
GROUP BY table_schema, table_name
ORDER BY table_schema, table_name;
@Sedose
Sedose / Readme.md
Last active October 26, 2025 14:09
composition-over-implementation-inheritance
@Sedose
Sedose / Readme.md
Last active April 3, 2025 10:57
Prompt: JPA/ Hibernate vs JOOQ/ QueryDSL/ Kotlin Exposed. When to use by default for everything related to DB. Based on feedbacks of developers. Model: ChatGPT o1

This document explains why teams commonly choose JPA/Hibernate and when they might prefer alternatives like jOOQ, QueryDSL, or Kotlin Exposed.

Why Teams Default to JPA/Hibernate

De-facto standard for Java/Kotlin ORM - widely known and supported • Library integration - many tools assume or work with JPA • Boilerplate reduction - handles simple CRUD and domain models well

When Teams Choose Alternatives

@Sedose
Sedose / Readme.md
Created April 3, 2025 10:43
Prompt: Pessimistic vs Optimistic locking in PostgreSQL. Model: ChatGPT o1

Pessimistic vs. Optimistic Locking in PostgreSQL

This document explains the differences between pessimistic and optimistic locking in PostgreSQL, their trade-offs, and when to use each approach.

Overview

Pessimistic and optimistic locking are two strategies for handling concurrent data updates. Both ensure data consistency but differ in conflict handling and performance implications.

Pessimistic Locking

Core Idea

import java.io.File
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
const val REPO_PATH = "/path/to/your/repo"
const val BRANCH_NAME = "develop"
const val REMOTE_NAME = "origin"
const val INTERVAL_SECONDS = 3600L
fun updateBranch() = File(REPO_PATH).takeIf { it.isDirectory }?.let { repoDir ->
@Sedose
Sedose / InOrderTraversal.kt
Created January 11, 2025 05:36
In order binary tree traversal in Kotlin
package org.example
fun main() {
val root = TreeNode(15).apply {
left = TreeNode(6).apply {
left = TreeNode(4)
right = TreeNode(9).apply {
left = TreeNode(7)
}
}
fn main() {}
pub struct Solution;
impl Solution {
pub fn license_key_formatting(input: String, k: i32) -> String {
let input: String = input
.chars()
.filter(|&c| c != '-')
.map(|c| c.to_ascii_uppercase())