Skip to content

Instantly share code, notes, and snippets.

@omernaci
omernaci / docker-compose.yml
Created January 28, 2024 13:26
Zookeeper, Kafka, Schema Registry, Kafka UI
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:6.2.0
environment:
ZOOKEEPER_CLIENT_PORT: 2181
volumes:
- zookeeper_data:/var/lib/zookeeper/data
- zookeeper_logs:/var/lib/zookeeper/log
@omernaci
omernaci / OrderValidation.java
Created January 17, 2024 10:54
Cyclomatic Complexity
// Reduce complexity of the code
public boolean isOrderValid(Order order) {
if (order != null) {
if (order.getItems() != null && !order.getItems().isEmpty()) {
for (OrderItem item : order.getItems()) {
if (item.getQuantity() > 0) {
// Validate item
} else {
return false;
}
@omernaci
omernaci / AccountOpenedEventHandler.java
Created December 13, 2023 10:22
Event Driven Architecture - Event Versioning
public class AccountOpenedEvent {
private String accountId;
private String customerDetails;
private String accountOpeningDetails;
private int version; // Add a version field
}
@Component
public class AccountOpenedEventHandler {
private List<AccountOpenedEventProcessor> processors;
@omernaci
omernaci / kubernetes-commands.csv
Created June 30, 2023 10:37
Kubernetes Basic Command List
Description Command
Create a pod kubectl create pod <pod-name> --image=<image-name>
Get pods kubectl get pods
Describe a pod kubectl describe pod <pod-name>
Delete a pod kubectl delete pod <pod-name>
Create a deployment kubectl create deployment <deployment-name> --image=<image-name>
Get deployments kubectl get deployments
Scale a deployment kubectl scale deployment <deployment-name> --replicas=<replica-count>
@omernaci
omernaci / BigDecimalExample.java
Created April 13, 2023 17:36
Java BigDecimal Best Practice
import java.math.BigDecimal;
import java.math.RoundingMode;
public class BigDecimalExample {
public static void main(String[] args) {
// Creating BigDecimal objects using the String constructor
BigDecimal value1 = new BigDecimal("123.456");
BigDecimal value2 = new BigDecimal("123.4560");
// Performing arithmetic operations with the HALF_UP rounding mode
@omernaci
omernaci / terminal-operations.csv
Created April 9, 2023 21:24
Java Stream Terminal Operations
Operation Type Description
forEach Terminal Performs an action for each element of this stream.
count Terminal Returns the count of elements in this stream.
reduce Terminal Performs a reduction on the elements of this stream using the provided identity value and accumulation function.
collect Terminal Performs a mutable reduction operation on the elements of this stream using a Collector.
anyMatch Terminal Returns whether any elements of this stream match the provided predicate.
allMatch Terminal Returns whether all elements of this stream match the provided predicate.
noneMatch Terminal Returns whether no elements of this stream match the provided predicate.
findFirst Terminal Returns an Optional describing the first element of this stream or an empty Optional if the stream is empty.
findAny Terminal Returns an Optional describing some element of the stream or an empty Optional if the stream is empty.
@omernaci
omernaci / intermediate-operations.csv
Last active April 9, 2023 21:27
Java Stream Intermediate Operations
Operation Type Description
filter Stateless Returns a new stream consisting of elements that match the given predicate.
map Stateless Returns a new stream consisting of the results of applying the given function to the elements of this stream.
flatMap Stateless Returns a new stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.
sorted Stateful Returns a stream consisting of the elements of this stream sorted according to the provided Comparator.
peek Stateless Returns a stream consisting of the elements of this stream additionally performing the provided action on each element as elements are consumed from the resulting stream.
limit Stateless Returns a stream consisting of the elements of this stream truncated to be no longer than the specified maximum size.
skip Stateless Returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the
@omernaci
omernaci / bin.sh
Created August 27, 2020 05:18
Install docker Without Internet Connection on CentOS
# download docker rpm package connectivity machine : curl https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm -o docker.rpm
# copy it to server via scp/ssh
yum install -y docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm -o docker.rpm
systemctl start docker
systemctl enable docker
@omernaci
omernaci / bin.sh
Created August 27, 2020 05:14
Install docker-compose Without Internet Connection
# https://github.com/docker/compose/releases/ download docker-compose
# copy it to server via scp/ssh
mv docker-compose-Linux-x86_64 docker-compose
sudo mv docker-compose /usr/local/bin/
sudo chmod +x /usr/local/bin/docker-compose
@omernaci
omernaci / RestTemplateHelper.java
Created October 21, 2019 07:18 — forked from slmanju/RestTemplateHelper.java
Generic RestTemplate wrapper
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;