Skip to content

Instantly share code, notes, and snippets.

View baybatu's full-sized avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@baybatu
baybatu / create-rabbitmq-exchange-queue-using-rest-api.sh
Created April 2, 2019 06:35
Create RabbitMQ queue and exchange with binding using REST API
# create exchange
curl -i -u guest:guest -H "content-type:application/json" \
-XPUT -d'{"type":"fanout","durable":true}' \
http://localhost:15672/api/exchanges/%2f/my.exchange.name
# create queue
curl -i -u guest:guest -H "content-type:application/json" \
-XPUT -d'{"durable":true,"arguments":{"x-dead-letter-exchange":"", "x-dead-letter-routing-key": "my.queue.dead-letter"}}' \
http://localhost:15672/api/queues/%2f/my.queue
@baybatu
baybatu / list-used-nodeports-on-kubernetes.sh
Created April 12, 2023 15:03
List all used node ports on kubernetes cluster. kudos @hasansama
kubectl get svc --all-namespaces -o go-template="{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{printf \"\n\"}}{{end}}{{end}}{{end}}" | sort
@baybatu
baybatu / limit-number.py
Created June 26, 2016 06:27
Limiting input number between minimum and maximum values range in Python
def limit(num, minimum=1, maximum=255):
"""Limits input 'num' between minimum and maximum values.
Default minimum value is 1 and maximum value is 255."""
return max(min(num, maximum), minimum)
@baybatu
baybatu / CompleteableFutureWithExceptionHandling.java
Last active January 11, 2023 06:01 — forked from kencharos/Comp.java
CompletableFuture sample (with simple error handling)
package com.example;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CompleteableFutureWithExceptionHandling {
public static void main(String[] args) {
@baybatu
baybatu / oreilly-book-downloader.sh
Created December 28, 2022 20:03
oreilly book downloader
(docker run kirinnee/orly:latest login BOOK_ID username@mail.com:pass) > "mybook.epub"
@baybatu
baybatu / kubectl-exec-pipe-commands.md
Last active December 14, 2022 11:35
Piping bash commands in kubectl exec

Bash commands connected using pipe(|) are not executed correctly in kubectl exec.

Example:

kubectl exec -ti <POD> -- pg_dump -h localhost -t my_table | psql -d <TARGET_DB> -h localhost

Here I want to run the pg_dump command first and redirect the output to the psql command as input using pipe(|). But kubectl takes commands only until pipe character, pg_dump in my case and psql has been run on host machine instead of inside the <POD>. The solution is to wrap all commands using double quote(") and run these commands using bash -c.

@baybatu
baybatu / datagrip-database-connections.md
Last active December 2, 2022 17:55
Import & Export database connection properties in DataGrip

on macOS

default folder in /Users/USERNAME/Library/Preferences/DataGrip2018.1/projects contains database connection properties.

DataGrip2018.1 states your DataGrip version

@baybatu
baybatu / fix-no-class-def-found-error.md
Last active November 3, 2022 11:54
Resolving java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache error in a spring-boot application

The following stacktrace can occur on a spring-boot app. Consider changing the scope of dependencies that use groovy runtime as test.

{"@timestamp":"2022-11-03T12:32:33.865+03:00","@version":"1","message":"Application run failed","logger_name":"org.springframework.boot.SpringApplication","thread_name":"main","level":"ERROR","level_value":40000,"stack_trace":"java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
@baybatu
baybatu / tarih-ve-zaman-saklama-onerisi.md
Last active October 13, 2022 11:21
Tarih ve zamanların veritabanında saklanmasıyla alakalı bir öneri

Tablolarda tarih ve zamanı ayrı kolonlarda tutmak hatalı sorgulama yapma ihtimalini artırır. Arama için verilen bir zamanın değerini değiştirip arama yapılıyorsa bu durumda bug çıkma ihtimali var. Örnek tablo verisinin şu şekilde olduğunu düşünelim:

id tarih zaman
1 09/12/2021 23:50
2 09/12/2021 23:52
3 09/12/2021 23:55
@baybatu
baybatu / delete-redis-keys-by-pattern.md
Last active October 13, 2022 11:21
Delete Redis keys by pattern