Skip to content

Instantly share code, notes, and snippets.

@omidp
omidp / CategoryDetailEntity.java
Last active September 6, 2024 06:59
Hibernate query cache
@Entity
@Table(name = "category_detail")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = "id")
public class CategoryDetailEntity {
@Id
@Column(name = "category_id")
@omidp
omidp / PowersetCombination.java
Last active August 1, 2024 12:03
PowersetCombination with backtracking
import java.util.ArrayList;
import java.util.List;
public class PowersetCombination {
// Method to generate all k-combinations of a given set
public static <T> List<List<T>> generateCombinations(List<T> set, int k) {
List<List<T>> combinations = new ArrayList<>();
generateCombinations(set, k, 0, new ArrayList<>(), combinations);
return combinations;
@omidp
omidp / Chain.java
Created July 29, 2024 19:32
Java chain result functional way
public static void main(String[] args){
int i = ((ThenResult<String>) ()-> "1")
.then(s->Integer.parseInt(s))
.result()
}
public interface ThenResult<T> {
T result();
@omidp
omidp / RateLimiterConfig.java
Created September 24, 2023 18:10
RateLimiterServlet
import io.github.resilience4j.ratelimiter.RateLimiter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.Duration;
@Configuration
public class RateLimiterConfig {
@Bean
@omidp
omidp / application.properties
Created March 18, 2023 11:34
Spring boot application.properties for production
## Postgresql configuration
set Postgresql max_connections to 250
## HikariCP configuration
spring.datasource.hikari.minimumIdle=0
spring.datasource.hikari.maximum-pool-size=90
spring.datasource.hikari.maxLifetime=900000
spring.datasource.hikari.data-source-properties.useServerPrepStmts=false
@omidp
omidp / uuidtobin
Created December 21, 2022 16:11
java uuid to db binary 16
public byte[] getByte(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
@omidp
omidp / macCheatSheet
Created July 14, 2022 07:16
mac cheatsheet
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull \;
@omidp
omidp / sync
Created March 24, 2022 10:30
sync
import java.util.*;
import java.util.concurrent.locks.*;
/**
* A bank with a number of bank accounts that uses locks for serializing access.
*/
public class Bank
{
private final double[] accounts;
@omidp
omidp / GatewayContext.java
Last active February 27, 2022 16:55
scg-body-cache
import org.springframework.util.MultiValueMap;
public class GatewayContext {
public static final String CACHE_GATEWAY_CONTEXT = "cacheGatewayContext";
/**
* cache json body