Skip to content

Instantly share code, notes, and snippets.

@ahmedhosnypro
ahmedhosnypro / AutoSizeText.kt
Created June 17, 2024 18:40
Composable function that displays text with automatic font size adjustment to prevent overflow.
/**
* Composable function that displays text with automatic font size adjustment to prevent overflow.
adapted from https://github.com/philipplackner/ComposeAutoResizedText/blob/master/app/src/main/java/com/plcoding/composeautoresizedtext/AutoResizedText.kt
*/
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
@ahmedhosnypro
ahmedhosnypro / SideBorder.kt
Last active February 9, 2024 05:24
Jetpack Compose, Border on One Side only: [topBorder, rightBorder, bottomBorder, leftBorder]
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
fun Modifier.topBorder(
color: Color,
height: Float,
) = this.drawWithContent {
drawContent()
@ahmedhosnypro
ahmedhosnypro / ReorderedVerticalGridWithSwipeToDelete.kt
Created September 13, 2023 04:48
Jetpack Compose: Reorderable Vertical Grid with Swipe to Delete
//....
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.AnchoredDraggableState
import androidx.compose.foundation.gestures.DraggableAnchors
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.anchoredDraggable
import androidx.compose.foundation.interaction.MutableInteractionSource
@ahmedhosnypro
ahmedhosnypro / Compose_Button_Colors.kt
Created August 16, 2023 16:34
Change button colors in jetback compose
Button{
...
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.White,
contentColor = Color.Black
),
...
}
@ahmedhosnypro
ahmedhosnypro / CircularQueue.kt
Created July 15, 2023 04:12
Kotlin CircularQueue
@Suppress("UNCHECKED_CAST")
class CircularQueue<T>(
private val capacity: Int,
) {
private val elements: Array<T?> = arrayOfNulls<Any?>(capacity) as Array<T?>
private var front = 0
private var rear = 0
private var count = 0
@ahmedhosnypro
ahmedhosnypro / application.properties
Created June 23, 2023 18:11
SpringBoot Postgresql
#postgresql
#spring.datasource.url=jdbc:postgresql://localhost:5332/postgresql
#spring.datasource.username=postgresql
#spring.datasource.password=root
#spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
#spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true
#h2
spring.datasource.url=jdbc:h2:file:../recipes_db
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
@ahmedhosnypro
ahmedhosnypro / docker-compose.yml
Created March 16, 2023 13:34
PostgreSQL composer for intellij
services:
db:
container_name: postgres
image: postgres:14.1
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
PGDATA: /data/postgres
volumes:
- db:/data/postgres
ReadWriteLock lock = new ReentrantReadWriteLock();
// write
lock.writeLock().lock();
gson.toJson(data, writer);
lock.writeLock().unlock();
// read
lock.readLock().lock();
var objectMap = readData();
@ahmedhosnypro
ahmedhosnypro / ArgumentTokenizer.java
Created July 5, 2022 02:39
Tokenizes the given String into String tokens
import java.util.LinkedList;
import java.util.List;
abstract class ArgumentTokenizer {
private static final int NO_TOKEN_STATE = 0;
private static final int NORMAL_TOKEN_STATE = 1;
private static final int SINGLE_QUOTE_STATE = 2;
private static final int DOUBLE_QUOTE_STATE = 3;
private ArgumentTokenizer() {