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 / 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
@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 / 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 / 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 / polymorphic_related_queryset.py
Last active November 13, 2023 16:35 — forked from AndySun25/polymorphic_related_queryset.py
django-polymorphic select_related monkey patch

Keybase proof

I hereby claim:

  • I am mazulo on github.
  • I am mazulo (https://keybase.io/mazulo) on keybase.
  • I have a public key ASCkxka9caOCa0dclPTTyIY8aujEfVxrNIUw8Z9BjXlZAwo

To claim this, I am signing this object:

@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 / filter_object_by_key.js
Created February 12, 2018 21:59
Filter an object based in its keys
Object.keys(object).filter(function (key) {
return key != "key";
}).reduce(function(obj, key) {
obj[key] = object[key];
return obj;
}, {});
#include <stdio.h>
float medescolar(float n1, float n2, float n3, float n4) {
// Cria variável que irá conter o valor da média
float media = 0;
// Cáculo simples da média: soma-se as notas e divide-se pela quantidade
// de notas
media = (n1 + n2 + n3 + n4) / 4;
return media;
@mazulo
mazulo / fix.py
Created May 17, 2016 11:06
fix bug in simplemooc
# old
@login_required
def undo_enrollment(request, slug):
course = get_object_or_404(Course, slug=slug)
enrollment = get_object_or_404(
Enrollment,
user=request.user,
course=course
)
if request.method == 'POST':