Skip to content

Instantly share code, notes, and snippets.

View WilliamStam's full-sized avatar

William Stam WilliamStam

View GitHub Profile
@WilliamStam
WilliamStam / benchy_oracledb.py
Created January 12, 2024 13:06
Sqlalchemy oracle connections
# Sqlalchemy Async
# Records: 164
# Time: 15.389007091522217
# Average: 0.30778014183044433
# -
# Sqlalchemy Sync
# Records: 164
# Time: 15.195691585540771
# Average: 0.30391383171081543
# -
@WilliamStam
WilliamStam / benchy.py
Created January 12, 2024 09:56
benchmark oracle connections
import asyncio
import dataclasses
import time
import oracledb
from sqlalchemy import text, URL
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy import create_engine
@WilliamStam
WilliamStam / test.py
Created December 14, 2023 12:56
Fastapi event system
import dataclasses
import logging
from typing import Annotated, Callable, Dict, List
from fastapi import Depends, FastAPI
from fastapi.dependencies.models import Dependant
from fastapi.dependencies.utils import get_dependant, solve_dependencies
from starlette.requests import Request
from utilities.events import EventsCollection
@WilliamStam
WilliamStam / app.py
Last active December 14, 2023 09:56
Fastapi help needed - event system
import dataclasses
import logging
from typing import Annotated, Callable, Dict, List
from fastapi import Depends, FastAPI
logger = logging.getLogger(__name__)
class EventsCollection():
@WilliamStam
WilliamStam / authentication_dependency.py
Last active December 14, 2023 09:57
FastAPI authentication
import logging
import typing
from fastapi import Depends, HTTPException
from starlette.requests import Request
from domain.user.model import ProfileModel
from exception import HTTPForbiddenException
from permissions import permissions as system_permissions
from utilities.permission import Permission
@WilliamStam
WilliamStam / app.py
Created November 15, 2023 08:30
Litestar gist to prove i was wrong and litestar is right
import logging
from pathlib import Path
from litestar import Controller, Litestar, Request, Router, get
from litestar.connection import ASGIConnection
from litestar.exceptions import PermissionDeniedException
from litestar.handlers import BaseRouteHandler
from litestar.logging import LoggingConfig
from litestar.openapi import OpenAPIConfig
from litestar.openapi.spec import Components, SecurityScheme
<button
type="button"
onclick="printit(['file1.pdf','file2.pdf'])"
>
Print pdf
</button >
<div id='pdf-viewer'></div >
@WilliamStam
WilliamStam / config.js
Created October 7, 2022 07:20
Update postman collection from source (openapi3 to postman)
/*
postman makes finding the collection id and uid rather.... "interesting".
step 1: import your collections from files (collection not api) -
on the left menu in postman go to "collections", import, select your file
if you import the file under "api" you will end up with 2 that look the same for step 2.
step 2: setup a GET request in postman to https://api.getpostman.com/collections
add a "header" and call it "X-Api-Key" and the value is the api key setup in secret.js. click send