Skip to content

Instantly share code, notes, and snippets.

View vittxr's full-sized avatar
🤠
Working

Vitor Schirmer vittxr

🤠
Working
View GitHub Profile
@vittxr
vittxr / handle_token.js
Created October 22, 2024 11:39
store fastapi token in postman collection
// Parse the response JSON
var response = pm.response.json();
// Store the access token and token type in collection variables
pm.collectionVariables.set("auth_token", response.access_token);
pm.collectionVariables.set("auth_token_type", response.token_type);
@vittxr
vittxr / launch.json
Last active October 23, 2024 12:36
vscode debug file for flask.
{
"version": "1.0.0",
"configurations": [
{
"name": "Python: Flask",
"type": "debugpy",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "main.py",
@vittxr
vittxr / launch.json
Last active March 20, 2025 18:02
vscode debug file for fastapi.
{
"version": "1.0.0",
"configurations": [
{
"name": "FASTAPI DEBUG",
"type": "debugpy",
"request": "launch",
"module": "fastapi",
"args": [
"dev"
@vittxr
vittxr / logging_cursor.py
Last active July 25, 2024 13:43
A custom logging cursor class for the Python library `mysql.connector`.
from contextlib import contextmanager
import mysql.connector
from mysql.connector.cursor_cext import CMySQLCursorDict
from mysql.connector.abstracts import MySQLConnectionAbstract
class LoggingCursor(CMySQLCursorDict):
def __init__(self, *args, **kwargs):
print(*args)
super(LoggingCursor, self).__init__(*args, **kwargs)
@vittxr
vittxr / allObjectValuesAreTrue.js
Last active May 2, 2024 18:34
check if all objects values are true, including nested objects.
export async function allObjectValuesAreTrue(obj) {
return (
Object.values(obj).filter((v) => {
if (!(typeof v === 'boolean')) {
return !allObjectValuesAreTrue(v);
}
return !v;
}).length === 0
);
}
@vittxr
vittxr / folder_to_json.py
Last active September 9, 2024 19:02
generate a json of a folder structure
import os
import json
from typing import Any, Literal
def create_folder_structure_json(
path: str, ignore: list[str] = [], ignore_files: bool = False
) -> dict[str, Any]:
"""
Recursively creates a dict representation of the folder structure starting from the given path.
@vittxr
vittxr / RequestParams.py
Created February 27, 2024 17:35
a pydantic class to validate the client-side query params sent with the request.
from typing import Optional, Any
from pydantic import BaseModel, field_validator, Field
import string
# the order of the list matters
WHERE_OPERATORS = [">=", "<=", "!=", "=", ">", "<", "LIKE", "NOT LIKE"]
class RequestParams(BaseModel):
"""
Represents the request parameters that client-side can use to filter/sort data.
@vittxr
vittxr / format_data_with_joins.py
Last active February 6, 2024 13:19
format sql-data-result to a more readable data output.
from typing import TypedDict, Any, NotRequired
import json
class RightTable(TypedDict):
name: str
label: NotRequired[str]
def extract_right_table_data(