Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@baybatu
baybatu / limit-number.py
Created June 26, 2016 06:27
Limiting input number between minimum and maximum values range in Python
View limit-number.py
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)
View CompleteableFutureWithExceptionHandling.java
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
View oreilly-book-downloader.sh
(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
View kubectl-exec-pipe-commands.md

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
View datagrip-database-connections.md

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
View fix-no-class-def-found-error.md

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
View tarih-ve-zaman-saklama-onerisi.md

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
View delete-redis-keys-by-pattern.md
@baybatu
baybatu / rabbitmq-delay-message-consume.md
Last active October 13, 2022 10:14
RabbitMQ: mesajı geciktirerek tüketmek
View rabbitmq-delay-message-consume.md

RabbitMQ: Mesajı Geciktirerek Tüketmek

  • delay-exchange: Geciktirilecek mesajın bırakıldığı exchange.
  • delay-queue: delay-exchange'e bağlı. Herhangi bir tüketicisi olmamalı.
  • ana-exchange: Geciktirilmeden tüketilmek istenen mesajların bırakılabileceği exchange.
  • ana-queue: ana-exchange'e bağlı kuyruk. Tüketicisi var.

delay-queue şu parametrelerle oluşturulur:

  • x-dead-letter-exchange: -- boş
  • x-message-ttl: 3000 -- mesajın bekletileceği milisaniye
@baybatu
baybatu / schedule-with-asyncio-eventloop.py
Last active October 5, 2022 21:19
I'm using schedule(https://github.com/dbader/schedule) library for simple scheduled job needs. However it does not have built-in asyncio support and cannot run coroutines as job. So, this scheduler example shows how to use schedule library with asyncio coroutines.
View schedule-with-asyncio-eventloop.py
import asyncio
import functools
from schedule import Scheduler
class AsyncScheduler(object):
"""
schedule (https://github.com/dbader/schedule) and asyncio integration example.
Jobs are executed in asyncio event loop without blocking another tasks.