Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
@jarshwah
jarshwah / rabbitmq_to_cloudwatch.sh
Created June 5, 2019 13:23
Send RabbitMQ queue length to Cloudwatch
#! /bin/bash
# This script reads rabbitmq statistics and report them as CloudWatch metrics.
# https://gist.github.com/GoodMirek/2dc39100d18c72eed3f0f3569e221f4f
# RabbitMQ::messages_ready
# RabbitMQ::messages_unacknowledged
# RabbitMQ::consumers
# Dimensions: QueueName, InstanceId, VHost
@jarshwah
jarshwah / tests.py
Last active June 7, 2019 12:41
Unit test for confirming there are no outstanding migrations
from django.core.management import call_command
from django.test import TestCase
class MigrationsTestCase(TestCase):
def test_no_outstanding_migrations(self):
"""No migrations need to be generated"""
try:
result = call_command("makemigrations", "--dry-run", "--check", "--no-input", "-v", "0")
except SystemExit:
self.fail("There were outstanding migrations")
import pickle
import six
from django_redis.serializers.pickle import PickleSerializer
def compat_pickle_loads(value, **kwargs):
if six.PY2:
return _py2_pickle_loads(value)
return _py3_pickle_loads(value, **kwargs)
#!/bin/bash
# ~/.osx — http://mths.be/osx
# Close any open System Preferences panes, to prevent them from overriding
# settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
# Ask for the administrator password upfront
def pytest_configure(config):
config.addinivalue_line(
"markers", "enable_inline_css: run css postprocessing over generated emails"
)
@pytest.fixture(autouse=True)
def disable_inline_css(request, monkeypatch):
if "enable_inline_css" in request.keywords:
return
@jarshwah
jarshwah / models.py
Created December 21, 2022 22:04
annotating your manager for useful type hints
class MyModel(models.Model):
name = models.CharField()
objects: models.QuerySet["MyModel"]
MyModel.objects.filter().first()
@jarshwah
jarshwah / README.md
Created May 14, 2024 11:07
Use postgres unlogged tables when testing

In theory this should speed up tests running on Postgres as no WAL will be written, at the cost of completely hosing the test database if the instance crashes (which shouldn't be a problem with a test database).

When comparing builds with and without this patch applied though I had really inconsistent findings. Some builds ran much faster, but most ran much slower.

We already start postgres with the following CLI options which minimises WAL anyway, which likely renders the UNLOGGED change mostly redundant:

-c max_wal_senders=0
-c wal_level=minimal
-c min_wal_size=1024