Skip to content

Instantly share code, notes, and snippets.

View rafalkrupinski's full-sized avatar
🥕

Raphael Krupinski rafalkrupinski

🥕
View GitHub Profile
@rafalkrupinski
rafalkrupinski / route.tsx
Created September 12, 2023 08:40
Get roles from Zitadel token with next-auth
import NextAuth, {Profile} from "next-auth";
import ZitadelProvider from "next-auth/providers/zitadel";
import {CallbacksOptions} from "next-auth/src/core/types";
const ZITADEL_PROJECT_ID = process.env.ZITADEL_PROJECT_ID!;
type ProjectURN = string;
type AllProjectsURN = 'urn:zitadel:iam:org:project:roles';
type RoleKey = string;
type OrganizationId = string;
@rafalkrupinski
rafalkrupinski / iter_chunks.py
Created January 16, 2023 19:50
Create chunks of given size out of an iterator
def iter_chunks(iter: Iterator[T], size: int) -> Iterator[Iterable[T]]:
"""Create chunks of given size out of an iterator"""
chunk: list[T] = []
for idx, elem in enumerate(iter):
chunk.append(elem)
if idx + 1 % size == 0:
yield chunk
chunk = []
if chunk:
yield chunk
@rafalkrupinski
rafalkrupinski / type_filtered_map_view.py
Last active January 11, 2023 23:05
In this example, the TypeFilteredDictView class takes two arguments d which is a dictionary and value_type which is the type you want to filter by. The class implements the __getitem__, __iter__ and __len__ methods of the collections.abc.MappingView interface, so that it behaves like a view of the original dictionary. The class internally use di…
import collections.abc
class TypeFilteredDictView(collections.abc.MappingView):
def __init__(self, d, value_type):
self._d = d
self._value_type = value_type
def __getitem__(self, key):
return self._d[key]
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from openapi_core import create_spec
from openapi_core.schema.schemas.models import Schema
from openapi_core.shortcuts import RequestBody, Response
# Connect to the SQL database
engine = create_engine("postgresql://user:password@host/dbname")
Base = automap_base()