Skip to content

Instantly share code, notes, and snippets.

@viniciusao
viniciusao / README.md
Created December 30, 2022 22:37
Authentik docker-compose file and Locust test script.

Tested on windows 10 (wsl2 ubuntu).

  • Authentik (Proxy too) + Traefik + App + Portainer docker-compose file.
  • Locust load testing script.
@viniciusao
viniciusao / common_programming_concepts.rs
Created December 5, 2022 01:42
Common programming concepts in rust (The book).
// Some points that made me surprised:
// - Variable's states: mutability and immutability.
// - Strong typing.
// - Statements and expressions, e.g. syntactic scope is an expression.
// - Loop labels and break as an expression.
use std::io;
use rand::Rng;
const MAX_INPUT_NUMBER: u8 = u8::MAX; // Constant variable (3.1) and Scalar `u8` data type (3.2).
@viniciusao
viniciusao / area_pydantic.py
Last active July 4, 2023 23:14
typing.NamedTuple with pydantic.
from contextlib import suppress
from typing import NamedTuple
from pydantic import create_model_from_namedtuple, BaseModel, root_validator
class FunctionNumber101(NamedTuple):
width: float
height: float
@viniciusao
viniciusao / area.py
Last active September 23, 2022 20:31
NamedTuple typing normal
from typing import NamedTuple
class FunctionNumber101(NamedTuple):
width: float
height: float
def area(self):
if self.width <= 0 or self.height <= 0:
raise ValueError("width and height must be positive")
@viniciusao
viniciusao / create_model.py
Last active May 11, 2023 08:55
Dynamic pydantinc model creation
from pydantic import create_model
def create_pydantic_model(name: str, **kwargs):
"""
Create a pydantic model.
:param name: name of the BaseModel class to create.
:param kwargs: BaseModel' fields.
"""
@viniciusao
viniciusao / test_insert.py
Created June 24, 2022 16:27
Pytest mock database: test same name
def test_same_name(session_same_name):
s, models = session_same_name
username = s.query(models['User'].__class__).first().name
actorname = s.query(models['Actor'].__class__).first().name
assert username == actorname
@viniciusao
viniciusao / conftest.py
Created June 24, 2022 16:11
Pytest mock database: Fixture
import pytest
from pytest_mock_resources import create_postgres_fixture
from sqlalchemy.orm import Session
from model import Actor, User
pg = create_postgres_fixture(
*[Actor, User]
)
@viniciusao
viniciusao / model.py
Created June 24, 2022 16:09
Pytest mock database: Tabelas
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = "user"
__table_args__ = {"schema": "names"}