Skip to content

Instantly share code, notes, and snippets.

View GGontijo's full-sized avatar
💭
Escovando bits..

Dercilio GGontijo

💭
Escovando bits..
View GitHub Profile
@GGontijo
GGontijo / DictToGeoJson.py
Created July 7, 2022 12:37
Simple geojson builder from a python dictionary, it works.
import json
class Core:
def json_gen(self, items_list: list):
self.geojson = {}
self.geojson['type'] = 'FeatureCollection'
self.features = []
for item in items_list:
@GGontijo
GGontijo / config_helper.py
Created September 19, 2022 17:22
Helper to import a configuration file written in .json
import json
class Config:
'''Singleton approach'''
_instance = None
def __init__(self) -> None:
CONFIG_FILE = 'conf.json'
with open(CONFIG_FILE, 'r') as config:
@GGontijo
GGontijo / rename.py
Last active September 24, 2022 11:58
Mass rename files in a folder
import os
for file in os.listdir('.'):
if file == 'rename.py':
continue
name = str(file).split(".")[0]
new_name = name + ".jpg"
os.rename(file, new_name)
print(name + " alterado para " + new_name)
from datetime import datetime
class Logger():
def log_time() -> str:
return datetime.now().strftime("%d/%m/%Y %H:%M:%S")
def log_date() -> str:
return datetime.now().strftime("%d_%m_%Y")
@GGontijo
GGontijo / minecraft_server_autobackup_world.sh
Last active September 28, 2023 12:03
Autobackup Minecraft Server Linux
#!/bin/bash
# Função para enviar uma mensagem ao chat do Minecraft usando rcon-cli
send_message() {
echo "Sending message to Minecraft chat: $1"
docker exec minecraft_server_minecraft-server_1 rcon-cli tellraw @a "{\"text\":\"$1\",\"color\":\"green\"}"
}
# Função para verificar se o servidor está em autopause
@GGontijo
GGontijo / fail2ban-telegram.sh
Created December 15, 2023 00:47
fail2ban notify ban through telegram
#!/bin/bash
#/etc/fail2ban/scripts/fail2ban-telegram.sh
# Sends text messages using Telegram
# to alert webmaster of banning.
# Require one argument, one of the following
# start
# stop
@GGontijo
GGontijo / npm-auth.conf
Created December 15, 2023 00:59
fail2ban nginx ban scanners and unauthorized access
#/etc/fail2ban/filter.d/npm-auth.conf
[INCLUDES]
[Definition]
failregex = ^ \[error\] \d+#\d+: \*\d+ user "(?:[^"]+|.*?)":? (?:password mismatch|was not found in "[^\"]*"), client: <HOST>, server: \S*, request: "\S+ \S+ HTTP/\d+\.\d+", host: "\S+"(?:, referrer: "\S+")?\s*$
@GGontijo
GGontijo / main.py
Created January 8, 2024 14:37
cooldown for python apis
last_execution = datetime.now(tz=pytz.timezone('America/Cuiaba'))
def cooldown():
global last_execution
now = datetime.now(tz=pytz.timezone('America/Cuiaba'))
if last_execution is not None:
difference_time = (now - last_execution).seconds
remaining_time = 120 - difference_time
if difference_time < 120:
raise Exception(f'Please wait {remaining_time} seconds before another try!')
@GGontijo
GGontijo / cli_command
Created February 3, 2024 13:12
linux find text pattern in texts and write something in front of them
palavra="teste"; texto_adicional="deu certo"; for arquivo in teste*; do grep -q "$palavra" "$arquivo" && sed -i "/$palavra/ s/$/ $texto_adicional/" "$arquivo" && echo "Texto adicionado em $arquivo"; done
@GGontijo
GGontijo / commands
Created March 6, 2024 14:10
Allow Google Chrome / Microsoft Edge to run as root in linux adding --no-sandbox flag to it's launchers
sed -i -e 's@Exec=/usr/bin/microsoft-edge-dev %U@Exec=/usr/bin/microsoft-edge-dev %U --no-sandbox@g' /usr/share/applications/microsoft-edge-dev.desktop
sed -i -e 's@Exec=/usr/bin/google-chrome-stable %U@Exec=/usr/bin/google-chrome-stable %U --no-sandbox@g' /usr/share/applications/google-chrome.desktop