Skip to content

Instantly share code, notes, and snippets.

View cb109's full-sized avatar
💭
🍴 🐘

Christoph Bülter cb109

💭
🍴 🐘
View GitHub Profile
@cb109
cb109 / closeVuetifyDialog.js
Created June 1, 2023 13:12
Close opened Vuetify Dialog from outside any Vue app (Vuetify 1.5.x)
document.querySelector('.v-dialog--active').__vue__.$options._renderChildren[0].context.isActive = false
@cb109
cb109 / 1_dropzone.html
Last active January 10, 2023 13:12
Integrate Dropzone UI with jquery AJAX POST and django-filer FilerImageField
<head>
<link rel="stylesheet" href="/static/css/dropzone.css">
<script type="text/javascript" src="/static/js/dropzone.js"></script>
</head>
<form
id="my-dropzone-form"
class="dropzone"
action="/cannot-be-empty-but-is-not-used-instead-see-submit.js"
></form>
@cb109
cb109 / django_admin_autocomplete_field_label_as_link.js
Last active January 6, 2023 13:33
Turn Django admin autocomplete_field labels into links to the chosen model instance
@cb109
cb109 / setup_graylog_server.md
Last active January 29, 2025 10:16
Setup a self-hosted Graylog server

Setup a self-hosted Graylog server (e.g. for Django applications)

So other machines can send their logs to the central server for inspection/debugging.

For ease of setup we are going to use the official docker-compose setup here. The example below will be using Debian 11.

  1. Get a VPS with at least 4GB of RAM (less may crash as opensearch demands some resources).
  2. ssh to that VPS.
  3. Install Docker:
@cb109
cb109 / size_of_databases.sql
Created October 10, 2022 10:52
MySQL Size of Databases and Tables
SELECT
table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (GB)"
FROM
information_schema.TABLES
GROUP BY
table_schema;
@cb109
cb109 / track_data.py
Last active July 25, 2022 08:08 — forked from dcramer/track_data.py
Tracking changes on properties in Django
# Tested against Django 3.2.14.
from django.db.models.base import DEFERRED
def track_data(*fields):
"""Tracks property changes on a model instance.
Simplified version of David Cramer's gist:
https://gist.github.com/dcramer/730765
@cb109
cb109 / stop_recursion.py
Created July 19, 2022 09:16
Stop infinite recursion
import inspect
import traceback
from typing import Callable
def stop_recursion(function: Callable):
"""Decorator to stop recursion of given function early.
Avoids 'RecursionError: maximum recursion depth exceeded' if
preventing the cause of the recursion is not possible.
@cb109
cb109 / gunicorn.sh
Created June 15, 2022 08:50
Set gunicorn workers based on available cores
# https://docs.gunicorn.org/en/stable/design.html#how-many-workers
let num_workers=2*$(nproc --all)+1
gunicorn --workers $num_workers
@cb109
cb109 / on_change_rerun_relevant_tests.sh
Last active July 25, 2022 12:26
On file changed, re-run relevant pytests only
pip install pytest-watch pytest-testmon
# Build db on first run.
pytest --testmon
# Watch for changes, rerun tests.
ptw -- <pytest-options>
# Together: Watch for changes, rerun tests relevant with changed file(s) only!
ptw -- --testmon <pytest-options>