Skip to content

Instantly share code, notes, and snippets.

View marksweb's full-sized avatar

Mark Walker marksweb

View GitHub Profile
@marksweb
marksweb / uuid_mixin.py
Last active October 18, 2025 15:29
UUID mixin for django models
from uuid import uuid4
from django.db import models
from django.utils.translation import gettext_lazy as _
class UUIDMixin(models.Model):
"""
Mixin for models contain a unique UUID
"""
@marksweb
marksweb / do.sh
Created October 8, 2025 20:16
shell script to aid running a project locally with docker compose
#!/bin/bash
COLUMNS="`tput cols`"
LINES="`tput lines`"
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
DOCKER_COMPOSE="docker compose"
_requires() {
@marksweb
marksweb / conftest.py
Created August 2, 2025 10:01
Models as pytest fixtures
from django.apps import apps
def create_model_fixture(model):
"""
This injects the model names as fixtures.
eg def test_something(MyModel):
will make the `MyModel` available in a test.
"""
@marksweb
marksweb / conf.py
Created December 1, 2023 21:56
Using lazy settings in django apps
# myapp/conf.py
from core.settings import Settings
DEFAULTS = {
'TEMP_DIR': '/tmp/'
}
settings = Settings(DEFAULTS)
@marksweb
marksweb / settings.py
Created October 4, 2023 20:32
Single settings example
import os
import re
import sys
from django.db.models import options
import sentry_sdk
from base.utils.sanitize import sanitize
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
@marksweb
marksweb / sanitize.py
Created June 1, 2023 22:06
Python casting utility
# pylint: disable=inconsistent-return-statements
def sanitize(value, output_type):
"""
Handy wrapper function for individual sanitize functions.
:param value: Input value to be sanitized
:param output_type: Class of required output
:type output_type: bool or int

Keybase proof

I hereby claim:

  • I am marksweb on github.
  • I am markwalker (https://keybase.io/markwalker) on keybase.
  • I have a public key ASBR5scDMn5FSCoMk5ovovTddzHzwsn_lnJQ8vs-amP6hgo

To claim this, I am signing this object: