Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@baybatu
baybatu / use-git-profile-by-directory.md
Created Jun 30, 2021
Using git profiles by current directory
View use-git-profile-by-directory.md

~/.gitconfig:

[includeIf "gitdir:~/workspace/project1/**"]
    path = .gitconfig.project1
[includeIf "gitdir:~/workspace/project2/**"]
    path = .gitconfig.project2

~/.gitconfig.project1:

@baybatu
baybatu / limit-number.py
Created Jun 26, 2016
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)
View pywebio.md
@baybatu
baybatu / create-rabbitmq-exchange-queue-using-rest-api.sh
Created Apr 2, 2019
Create RabbitMQ queue and exchange with binding using REST API
View create-rabbitmq-exchange-queue-using-rest-api.sh
# 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 / export-psql-to-csv-file.md
Created Feb 16, 2022
export psql query result to csv file
View export-psql-to-csv-file.md
\copy (select column1, column2 from mytable) To '/tmp/dump.csv' With CSV DELIMITER ',' HEADER
@baybatu
baybatu / ZonedDateTimeAsUTC.java
Last active Feb 15, 2022
Setting zoned date time as UTC in a new java.util.Date object
View ZonedDateTimeAsUTC.java
/*
*
* Methods manipulate milliseconds field (fastTime) in java.util.Date object.
*
* UTC : 12/10/2017 11:15:00
* Local date time : 12/10/2017 14:15:00 +03:00
*
* @return new java.util.Date
* UTC : 12/10/2017 14:15:00
* Local date time : 12/10/2017 17:15:00 +03:00
@baybatu
baybatu / nifi-test-el.groovy
Created Sep 29, 2021
Nifi Expression Language Tester
View nifi-test-el.groovy
// 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 / delete-redis-keys-by-pattern.md
Last active Sep 17, 2021
Delete Redis keys by pattern
View delete-redis-keys-by-pattern.md
@baybatu
baybatu / delete-index-by-pattern-in-es.py
Created Jun 10, 2021
delete index by pattern in Elasticsearch with Python
View delete-index-by-pattern-in-es.py
# usage
# python delete-index-by-pattern-in-es.py http://ES_HOST:9200 my-es-index-*
# indexes matched with pattern you entered will be deleted
from elasticsearch import Elasticsearch
import sys
es_host = sys.argv[1]
index_pattern = sys.argv[2]
print(f"es_host:{es_host} ; index_pattern:{index_pattern}")