Skip to content

Instantly share code, notes, and snippets.

View ronaldgrn's full-sized avatar
🦊
cache all the things

Petronald Green ronaldgrn

🦊
cache all the things
View GitHub Profile
@ronaldgrn
ronaldgrn / bs4_xxl.css
Last active April 18, 2022 13:28
Boostrap 4 xxl grid
/* Adapted from bootstrap 4.6.0 */
.container-xxl {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
@ronaldgrn
ronaldgrn / viewsets.py
Created February 27, 2021 22:44
drf viewset multiple field lookup
class MultiLookupModelViewSet(ModelViewSet):
"""
Allows you to perform lookups on one or more fields
"""
lookup_fields = ["pk"] # Override with your lookup fields
def get_object(self):
"""
Returns the object the view is displaying.
@ronaldgrn
ronaldgrn / cert_cleanup.py
Created July 24, 2020 16:21
lua-resty-auto-ssl: Delete expired (or near expired) certs from redis
import redis
import json
from datetime import datetime, timedelta
from redis.exceptions import ResponseError
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
now = datetime.now()
three_days_from_now = now + timedelta(days=3)
keys_to_purge = []
@ronaldgrn
ronaldgrn / timescale--db--backend--base.py
Created June 23, 2020 00:46 — forked from dedsm/timescale--db--backend--base.py
WeRiot Django Timescale integration
import logging
from django.contrib.gis.db.backends.postgis.base import \
DatabaseWrapper as PostgisDBWrapper
from django.db import ProgrammingError
from .schema import TimescaleSchemaEditor
logger = logging.getLogger(__name__)
@ronaldgrn
ronaldgrn / django_include_raw
Created June 11, 2020 14:44
Django: Include a raw template without rendering
@register.simple_tag(name='include_raw')
def do_include_raw(template_name):
from django.template.exceptions import TemplateDoesNotExist
from django.template.engine import Engine
from django.template.loaders.app_directories import Loader
from django.utils.safestring import mark_safe
loader = Loader(Engine.get_default())
for origin in loader.get_template_sources(template_name):