Skip to content

Instantly share code, notes, and snippets.

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Lean
file_extensions:
- lean
scope: source.lean
contexts:
main:
- include: comments
"""
Example usage:
dj shell < wagtail_list_allowed_subpages.py
Returns markdown formatted list of which page types can be added under which.
"""
def list_valid_page_subpages(readable=False, shorten=False):
from wagtail.core.models import Page
@Macorreag
Macorreag / animacionconmani.ipynb
Last active October 4, 2022 01:36
Configuración de Colab para crear animaciones con la librería de manim
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ruped24
ruped24 / auto-remove-sublime3-license-popup.py
Last active August 13, 2023 02:37
Auto-remove SublimeText3 license popup
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
# forked from egel/auto-remove-sublime-license-popup
# https://gist.github.com/egel/b7beba6f962110596660
from commands import getoutput as cl
from threading import Event, Thread
from sublime_plugin import EventListener
@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
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`.

======================== DEP XXX: Simplified routing syntax

  • DEP: XXX
  • Author: Tom Christie
  • Implementation Team: Tom Christie
  • Shepherd: Tim Graham
  • Status: Draft
  • Type: Enhancement
@coredumperror
coredumperror / responsive_image.py
Last active October 17, 2023 15:59 — forked from davecranwell/responsive_image.py
Responsive image tag for Wagtail CMS
from django import template
from wagtail.wagtailimages.models import SourceImageIOError
from wagtail.wagtailimages.templatetags.wagtailimages_tags import ImageNode
register = template.Library()
@register.tag(name="responsiveimage")
def responsiveimage(parser, token):
bits = token.split_contents()[1:]
@soar
soar / markdownblock.py
Last active April 1, 2018 12:52
Wagtail Markdown - simplest way
# django
from django import forms
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.forms import Media, widgets
from django.utils.functional import cached_property
# wagtail
from wagtail.utils.widgets import WidgetWithScript
from wagtail.wagtailcore import blocks
@nealtodd
nealtodd / package_dev.sh
Last active July 6, 2016 10:57
Debugging / testing a third party package without hacking the pip installed version
cd somewhere
git clone https://github.com/[OWNER]/[REPO].git --branch [SPECIFIC BRANCH] --single-branch
cd [REPO]
python setup.py develop
# Usually, restart dev server to prevent it using already loaded site-packages modules.
# Hack away on code in [REPO], python will use this one rather than the one in site-packages.
# When done, to switch back:
python setup.py develop --uninstall
cd ..
rm -rf [REPO]