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 /
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 /
Last active January 11, 2023 06:01 — forked from kencharos/
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 /
Created December 28, 2022 20:03
oreilly book downloader
(docker run kirinnee/orly:latest login BOOK_ID > "mybook.epub"
baybatu /
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.


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 /
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>(
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(
baybatu /
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 /
Last active October 5, 2022 21:19
I'm using 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.
import asyncio
import functools
from schedule import Scheduler
class AsyncScheduler(object):
schedule ( and asyncio integration example.
Jobs are executed in asyncio event loop without blocking another tasks.
baybatu /
Created June 15, 2022 08:10
baybatu /
Created February 16, 2022 05:51
export psql query result to csv file
\copy (select column1, column2 from mytable) To '/tmp/dump.csv' With CSV DELIMITER ',' HEADER
baybatu / nifi-test-el.groovy
Created September 29, 2021 19:10
Nifi Expression Language Tester
// usage: groovy nifi-test-el.groovy '${now():toNumber():minus(3999900000):format("yyyy-MM-dd HH:mm:ss", "GMT")}'
// source:
@Grab(group='org.apache.nifi', module='nifi-expression-language', version='1.4.0')
import org.apache.nifi.attribute.expression.language.*
def cli = new CliBuilder(usage:'groovy testEL.groovy [options] [expressions]',
header:'Options:')'print this message')
cli.D(args:2, valueSeparator:'=', argName:'attribute=value',
'set value for given attribute')