Skip to content

Instantly share code, notes, and snippets.

View lloiacono's full-sized avatar

Leandro Loiacono lloiacono

  • Warehousing1
  • Berlin
View GitHub Profile
@lloiacono
lloiacono / zshrc
Created July 2, 2018 07:19
history datetime
#Temp
HISTTIMEFORMAT="%d/%m/%y %T "
#Persistent
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.zshrc
source ~/.zshrc
@lloiacono
lloiacono / es_array.sh
Created October 7, 2018 18:38
ES painless script example: remove element from array
curl -X POST \
http://some:port/indexname/_doc/docId/_update \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"script": {
"lang": "painless",
"inline": "ctx._source.first_name.remove(ctx._source.first_name.length - 1)"
}
}'
@lloiacono
lloiacono / jpeg_optim.sh
Created November 23, 2018 10:14
Jpeg optimization
find . -type f -name '.jpeg' -o -name '.jpg' -exec jpegoptim --strip-all --max=83 -p {} \;
@lloiacono
lloiacono / find_match_before_search.sh
Created November 29, 2018 13:56
Find first occurrence of STRING before search STRING
awk '/company_id/ {search_string=$0} /empty_before_import": true/ {print search_string FILENAME " " NR}' error_queue.*.log
@lloiacono
lloiacono / kafka-tools.sh
Created February 12, 2019 12:31
Kafka-tools
#!/usr/bin/env bash
##
# Source this in your .bashrc
##
set -o pipefail
kafka_avro_schema_id() {
if [ $# -ne 2 ]; then
echo "Usage $0 <bootstrap-server> <topic[:part:[:offset]]>"
@lloiacono
lloiacono / fail2ban-allstatus.sh
Created February 15, 2019 08:06 — forked from kamermans/fail2ban-allstatus.sh
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@lloiacono
lloiacono / mx_bukl_lookup.sh
Created February 15, 2019 08:37
Bulk MX lookup with awk and dig
awk '{printf("%s ",$1); system("dig -t mx +short " $0)}' somefile.csv
@lloiacono
lloiacono / rabbitmq_set_get_heartbeat.sh
Created July 4, 2019 09:43
RabbitMQ hearbeat set and get
# Set
rabbitmqctl eval 'application:set_env(rabbit, heartbeat, 1800).'
# Get
rabbitmqctl eval 'application:get_env(rabbit, heartbeat).'
@lloiacono
lloiacono / awk_commands
Created April 30, 2020 21:25
AWK useful
# filter lines by arbitrary value and sorts desc, lines ending with XXXms
grep 'T18:4' /var/log/some/some.log | grep 'ms' | awk '{if($NF-0>500){print $NF-0,$0}}' | sort -rg -k 1 | head -10
# grep text between strings
grep 'T11' /var/log/some/some.log | grep 'someText' | grep -o -P '(?<=TEXT_A).*(?=TEXT_B)' | sort | uniq -c | sort -r | head -50
@lloiacono
lloiacono / mongoDBQueryKiller.js
Created November 17, 2020 16:30
MongoDB query killer
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid