Skip to content

Instantly share code, notes, and snippets.

View Object905's full-sized avatar

Zverev Konstantin Object905

View GitHub Profile
@Object905
Object905 / fastapi_paginate.py
Last active May 15, 2021 17:55
Generic pagination for fastapi and sqlalchemy (easyli adapted to other orms/db drivers)
import math
from typing import Generic, List, Optional, TypeVar
from fastapi import Query
from pydantic.generics import GenericModel
from starlette.datastructures import URL
DEFAULT_PAGE_SIZE = 25
MAX_PAGE_SIZE = 100
from asyncio import Semaphore
from io import DEFAULT_BUFFER_SIZE
from os import PathLike
import aiofiles
import aiohttp
from zipstream import AioZipStream
async def download_files_into_zip(
from typing import Generic, TypeVar
import strawberry
from django.core.paginator import EmptyPage, Page, PageNotAnInteger, Paginator
from django.db.models.query import QuerySet
T = TypeVar("T")
MAX_PAGE_SIZE = 100
import strawberry
def filter_unset_input(input):
result = {}
for key in input.__annotations__.keys():
value = getattr(input, key)
if value != strawberry.arguments.UNSET:
result[key] = value
return result
@Object905
Object905 / dns-discovery.rs
Last active October 28, 2024 16:23
Pingora kubernetes/DNS ServiceDiscovery
use async_trait::async_trait;
use hickory_resolver::TokioAsyncResolver;
use http::Extensions;
use pingora::lb::discovery::ServiceDiscovery;
use pingora::lb::selection::{BackendIter, BackendSelection};
use pingora::lb::{Backend, Backends, LoadBalancer};
use pingora::protocols::l4::socket::SocketAddr;
use pingora::{Error, ErrorSource, ErrorType, Result as PingoraResult};
use std::fmt::Debug;
use std::net::{IpAddr, SocketAddrV4};
@Object905
Object905 / tile_downloader.py
Created March 21, 2024 13:35
Map tile server downloader
"""
Download tiles from tile sever "smart way" - fetchin for biggest zoom and then going down only if tile has some data
"""
from __future__ import annotations
import asyncio
import io
from itertools import batched
import math
@Object905
Object905 / compression.rs
Last active September 22, 2024 15:21
Pingora cache-example
use std::fmt::Debug;
use bytes::Bytes;
use lz4_flex;
use pingora::{Error, Result};
/// Content types that skip cache compression by default
pub const SKIP_COMPRESSION: &'static [&'static str] = &[
"image/avif",
"image/webp",