Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amir-shehzad
amir-shehzad / pickle_deal.py
Created March 17, 2024 07:04 — forked from HacKanCuBa/pickle_deal.py
How pickle changes according to how the interpreter gets called
"""Pickle dumps test.
When pickle dumps a class, it will include the FQDN for the module. In this example,
we see how an imported class gets dumped including its module information, whereas
a local one has the current module name, which could be `__main__` or other depending
on how the interpreter was called!
If you save this file as `pickle_deal.py` and then in a python terminal you import it
`import pickle_deal`, you will see the following printed:
b'\x80\x04\x95)\x00\x00\x00\x00\x00\x00\x00\x8c\x0bpickle_deal\x94\x8c\x07Decimal\x94\x93\x94\x8c\x07123.456\x94\x85\x94R\x94.'
@amir-shehzad
amir-shehzad / sqlalchemy_helpers.py
Created March 17, 2024 07:04 — forked from HacKanCuBa/sqlalchemy_helpers.py
SQLAlchemy handy helper functions
import functools
from contextlib import asynccontextmanager, contextmanager
from time import monotonic
from typing import Annotated, Any, AsyncGenerator, Generator, Hashable, Iterable, Literal, Optional, Sized, Union, overload
from sqlalchemy import event
from sqlalchemy.dialects.mysql.asyncmy import AsyncAdapt_asyncmy_cursor
from sqlalchemy.engine import URL, Connection, Engine, Row, create_engine
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import Session, sessionmaker
@amir-shehzad
amir-shehzad / cache_helpers.py
Created March 17, 2024 07:04 — forked from HacKanCuBa/cache_helpers.py
Cache handy helpers
"""Handy cache helpers.
These are not yet production ready, as I haven't toroughly tested them, but close.
---
Mandatory license blah blah:
Copyright (C) 2023 HacKan (https://hackan.net)
This Source Code Form is subject to the terms of the Mozilla Public
@amir-shehzad
amir-shehzad / gunicorn.py
Created March 17, 2024 07:01 — forked from HacKanCuBa/gunicorn.py
A config file of gunicorn(http://gunicorn.org/) contains fundamental configuration.
"""Gunicorn config file.
by HacKan (https://hackan.net)
Find it at: https://gist.github.com/HacKanCuBa/275bfca09d614ee9370727f5f40dab9e
Based on: https://gist.github.com/KodeKracker/6bc6a3a35dcfbc36e2b7
Changelog
=========
See revisions to access other versions of this file.