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 / 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 / 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 / kubectl-exec-pipe-commands.md
Last active July 31, 2024 11:25
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 / 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 / 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.
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.
@baybatu
baybatu / pywebio.md
Created June 15, 2022 08:10
PyWebIO
@baybatu
baybatu / export-psql-to-csv-file.md
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
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: https://community.cloudera.com/t5/Community-Articles/Testing-NiFi-Expression-Language-with-Groovy/ta-p/247208
@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:')
cli.help('print this message')
cli.D(args:2, valueSeparator:'=', argName:'attribute=value',
'set value for given attribute')
@baybatu
baybatu / get-all-table-properties-in-presto.md
Created August 5, 2021 08:25
Get all properties of a table in Presto