Skip to content

Instantly share code, notes, and snippets.

View mazulo's full-sized avatar
🐍
Pythoning

Patrick Mazulo mazulo

🐍
Pythoning
View GitHub Profile
@mazulo
mazulo / .py
Last active April 18, 2018 03:51
Event Dict
{
'dates': {
3: {
'color': {
'main': u '#2B2B4A',
'primary': u '#5B4C7E',
'secondary': u '#DCCCFF'
},
'date': datetime.date(2018, 11, 4),
'theme': u 'Python',
@mazulo
mazulo / polymorphic_related_queryset.py
Last active November 13, 2023 16:35 — forked from AndySun25/polymorphic_related_queryset.py
django-polymorphic select_related monkey patch
@mazulo
mazulo / polymorphic_related_queryset.py
Created August 29, 2023 12:53 — forked from Finndersen/polymorphic_related_queryset.py
PolymorphicRelatedQuerySet which allows select_related() to return polymorphic child models instead of base model
@mazulo
mazulo / drf_optimize.py
Created August 29, 2023 12:58 — forked from jackton1/drf_optimize.py
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@mazulo
mazulo / Flask-SQLAlchemy Caching.md
Created October 31, 2023 15:20 — forked from j178/Flask-SQLAlchemy Caching.md
Flask SQLAlchemy Caching

Flask-SQLAlchemy Caching

The following gist is an extract of the article Flask-SQLAlchemy Caching. It allows automated simple cache query and invalidation of cache relations through event among other features.

Usage

retrieve one object

# pulling one User object

user = User.query.get(1)

@mazulo
mazulo / zellij-sessionizer
Created April 3, 2024 23:16 — forked from aimestereo/zellij-sessionizer
zellij-sessionizer: ThePrimeagen/tmux-sessionizer but for zellij
#!/usr/bin/env bash
# set your own root folders, all children folders will become options for in sessionizer menu
root_folders="$HOME/projects $HOME/work $HOME/.config"
function attach_session() {
local session_root=$1
local session_name=$(basename "$session_root" | tr . _)
cd $session_root
zellij attach --create $session_name