Skip to content

Instantly share code, notes, and snippets.

View ayharano's full-sized avatar

Alexandre Yukio Harano ayharano

View GitHub Profile
@ayharano
ayharano / sqlalchemy-rds-iam-pgsql.py
Created December 9, 2025 22:15 — forked from gdamjan/sqlalchemy-rds-iam-pgsql.py
SQLAlchemy with RDS IAM Authentication
'''
Example of IAM Authentication to Postgres RDS from Python and SQLAlchemy. Uses SQLAlchemy events to
run a callback just before making a db connection and adding it to the internal pool. The callback
sets the connection parameters including the password/token.
https://docs.sqlalchemy.org/en/14/core/events.html#sqlalchemy.events.DialectEvents.do_connect
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Python.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.generate_db_auth_token
@ayharano
ayharano / README.md
Created November 26, 2025 18:02 — forked from liviaerxin/README.md
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload
@ayharano
ayharano / download_mvp.py
Created October 2, 2024 14:18
Download file from SQLA table
import os
import tempfile
from http import HTTPStatus
from typing import Annotated
import sqlalchemy as sa
from fastapi import APIRouter, BackgroundTasks, Depends, FastAPI, HTTPException
from fastapi.responses import FileResponse
from sqlalchemy import select
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column, undefer
@ayharano
ayharano / deny_snippet.json
Created March 7, 2024 14:10 — forked from astuyve/deny_snippet.json
Deny cloudwatch permissions from Lambda to save money
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@ayharano
ayharano / repl_example.py
Created September 15, 2023 13:30
List methods and attributes for a Python object instance
>>> class X:
... def __init__(self):
... self._a = None
... @property
... def a(self):
... return self._a
... @a.setter
... def a(self, val):
... self._a = val
...
@ayharano
ayharano / pyenv_only_latest.sh
Created June 13, 2023 13:28
pyenv versions
# install latest
for i in {7..11}; do V=$(pyenv install --list | grep "^[[:space:]]*3\.${i}\.[0-9]*" | tail -n 1 | sed 's,[[:space:]]*,,g'); echo "${V}"; yes n | pyenv install ${V}; echo; echo; done
# forced uninstall everything but latest
for i in {7..11}; do for V in $(pyenv versions | grep "^[[:space:]]*3\.${i}\.[0-9]*" | ghead -n -1 | sed 's,[[:space:]]*,,g'); do echo "${V}"; yes n | pyenv uninstall --force ${V}; done; echo; echo; done
@ayharano
ayharano / rj_campos_dos_goytacazes.py
Created December 31, 2022 16:57
rj_campos_dos_goytacazes.py with tentative end_date search
import calendar
import re
from datetime import date, timedelta
from string import punctuation
import dateparser
from scrapy import Request
from gazette.items import Gazette
from gazette.spiders.base import BaseGazetteSpider
@ayharano
ayharano / Changes are coming to pip-B4GQCBBsuNU.pt-BR.vtt
Last active October 1, 2020 19:51
A Portuguese translation to "Changes are coming to pip" video: https://www.youtube.com/watch?v=B4GQCBBsuNU
WEBVTT
Kind: captions
Language: pt-BR
00:00:00.000 --> 00:00:02.838
Uma grande mudança chega
a pip em outubro.
00:00:02.938 --> 00:00:07.362
Será um grande alicerce para tornar mais fácil
#!/usr/bin/env bash
INPUT_FILE="${1}"
TIME_START="${2}" # expected format HH:MM:SS
TIME_DURATION="${3}" # expected format HH:MM:SS
OUTPUT_FILE="${4}"
BASE="$(basename "${INPUT_FILE}")"
SHM_AUDIO_FILE="/dev/shm/audio_${BASE}"
SHM_VIDEO_FILE="/dev/shm/video_${BASE}"
@ayharano
ayharano / README.md
Created June 20, 2019 23:36 — forked from joyrexus/README.md
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")