Skip to content

Instantly share code, notes, and snippets.

@ivanlonel
ivanlonel / aws_s3_rename_files.py
Last active April 1, 2021 00:32
Renaming files in AWS S3
import boto3
import json
import logging
import argparse
import itertools
# Bucket.delete_objects allows a maximum of 1000 objects to be deleted in a single request
def break_in_chunks(iterable, max_size):
if max_size == 0:
@ivanlonel
ivanlonel / logging_queue.py
Last active April 1, 2021 02:24
Configure a QueueHandler and a QueueListener for logging withoug blocking asyncio coroutines. Based on Martijn Pieters' blog post: https://www.zopatista.com/python/2019/05/11/asyncio-logging/
import queue
import asyncio
import logging
from logging.handlers import QueueHandler, QueueListener
from contextlib import contextmanager
class LocalQueueHandler(QueueHandler):
def emit(self, record: logging.LogRecord) -> None:
# There is no need to self.prepare() records that go into a local, in-process queue.
@ivanlonel
ivanlonel / shortest_common_supersequence.py
Created March 24, 2021 02:14
Shortest Common Supersequence and Longest Common Subsequence generator functions
from __future__ import annotations
from typing import Any
from collections.abc import Iterable, Iterator
import difflib
import itertools
def longest_common_subsequence(seq1: Iterable[Any], seq2: Iterable[Any]) -> Iterator[Any]:
a = list(seq1)
b = list(seq2)
lcs = (a[block.a:(block.a + block.size)] for block in difflib.SequenceMatcher(None, a, b).get_matching_blocks())
@ivanlonel
ivanlonel / Tutorial_LabelImg.md
Last active March 14, 2022 13:00
Como utilizar LabelImg para criar anotações de imagens no formato YOLO

Utilizando LabelImg para criar anotações de imagens no formato Darknet/YOLO

LabelImg é uma ferramenta de anotação de imagens desenvolvida em Python com interface gráfica baseada em Qt.

As anotações podem ser salvas em três diferentes formatos:

Demonstração

@ivanlonel
ivanlonel / pgd.user.js
Last active April 11, 2023 21:51
Preencher Acompanhamento das Atividades - PGD
// ==UserScript==
// @name Preencher Acompanhamento das Atividades - PGD
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Preenche automaticamente os campos "Status", "Início", "Fim" e "Tempo gasto para realizar a atividade" da página de acompanhamento das atividades do PGD
// @author ChatGPT
// @match http://w3.programagestao.sda.ibge.gov.br/SDA-ProgramaGestao/planoTrabalho.jsf
// @icon https://www.google.com/s2/favicons?sz=64&domain=gov.br
// @grant none
// ==/UserScript==
@ivanlonel
ivanlonel / decrypt_dbeaver.py
Last active April 20, 2023 17:23 — forked from felipou/decrypt_dbeaver.py
DBeaver password decryption script - for newer versions of DBeaver
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
# requires pycryptodome lib (pip install pycryptodome)
import argparse
import contextlib
import os
import json
from Crypto.Cipher import AES
@ivanlonel
ivanlonel / geohash_grid.sql
Last active May 1, 2026 06:00
Returns a grid of all rectangles represented by geohashes of a given length that intersect a given geometry
-- https://dbfiddle.uk/n5dn_Rbj
CREATE OR REPLACE FUNCTION geohash_grid(
original_geometry geometry,
geohash_precision integer
)
-- Given a geometry and a geohash length, returns a grid of all rectangles
-- represented by geohashes of that length that intersect the geometry.
RETURNS TABLE (geohash text, geom geometry(polygon))
LANGUAGE SQL
@ivanlonel
ivanlonel / geohash12_int8.sql
Last active April 23, 2026 20:32
Converts geohash between text and integer formats in Postgres
-- Converts geohash (up to 12 characters) between text and bigint formats in Postgres
-- https://dbfiddle.uk/UzF6gQzu
-- The geohash length is stored in the 4 least significant bits,
-- so that the relative order of the resulting int8 is the same
-- as that of the the original text string:
-- gzzzzzzzzzzz < h < h0 < h00 < h01 < h1
-- -4 < 1 < 2 < 3 < 562949953421315 < 18014398509481986
@ivanlonel
ivanlonel / pluscode_grid.sql
Last active May 1, 2026 06:06
Given a geometry and a plus code length (2, 4, 6, 8, 10, 11, 12, 13, 14, or 15), returns a grid of all rectangles represented by plus codes of that length that intersect the geometry.
-- https://dbfiddle.uk/m-oWZnKN
-- This uses function pluscode_decode, implemented here:
-- https://github.com/google/open-location-code/blob/main/plpgsql/pluscode_functions.sql
CREATE OR REPLACE FUNCTION pluscode_grid(
original_geometry geometry,
pluscode_length integer
)
-- Given a geometry and a plus code length (2, 4, 6, 8, 10, 11, 12, 13, 14, or 15),
@ivanlonel
ivanlonel / pyqgis_standalone_processing.py
Created June 8, 2024 00:33
How to run Processing algorithms in standalone PyQGIS applications
import sys
from pathlib import Path
from qgis.core import QgsApplication
from qgis.core.contextmanagers import qgisapp
with qgisapp(guienabled=False, sysexit=False):
# Required before importing processing:
sys.path.append(str(Path(QgsApplication.prefixPath()) / "python/plugins"))