Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan O'Sullivan dan-osull

View GitHub Profile
View dataclass_constructor.py
from dataclasses import dataclass
from typing import Self
@dataclass
class Example:
field1: str
field2: str
@classmethod
def from_input_data(cls, data) -> Self:
@dan-osull
dan-osull / fastapi_postgres_async_example.py
Created Oct 28, 2022
Async PostgreSQL with FastAPI dependency injection & SQLAlchemy
View fastapi_postgres_async_example.py
import os
from abc import ABC, abstractmethod
from typing import AsyncIterator, Optional
import uvicorn
from dotenv import load_dotenv
from fastapi import Depends, FastAPI
from fastapi.responses import JSONResponse
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
View async_fastapi_cache.py
import asyncio
from functools import wraps
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
def cache_response(func):
"""
View Switch-HyperVGpuPartitionAdapter.ps1
param(
[Parameter(Mandatory)][string]$vmName
)
$InformationPreference = "Continue"
$ErrorActionPreference = "Stop"
try {
$vmPartitionAdapter = Get-VMGpuPartitionAdapter -VMName $vmName
if ($vmPartitionAdapter) {
Write-Information "Removing Partition Adapter. Checkpoints work."