This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# refactor of https://lukeplant.me.uk/blog/posts/double-checked-locking-with-django-orm/ | |
# untested | |
def double_checked_lock_iterator(queryset): | |
for item_pk in queryset.values_list("pk", flat=True): | |
with transaction.atomic(): | |
try: | |
yield queryset.select_for_update(skip_locked=True).get(id=item_pk) | |
except queryset.model.DoesNotExist: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="{% static 'app.js' %}" data-csrftoken="{{ csrf_token }}"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOGGING = { | |
"version": 1, | |
"disable_existing_loggers": False, | |
"filters": { | |
"require_debug_true": { | |
"()": "django.utils.log.RequireDebugTrue", | |
}, | |
}, | |
"formatters": { | |
"rich": {"datefmt": "[%X]"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import StringIO | |
from django.core.management import call_command | |
from django.test import TestCase | |
class PendingMigrationsTests(TestCase): | |
def test_no_pending_migrations(self): | |
out = StringIO() | |
try: | |
call_command( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoginRequiredMiddleware: | |
def __init__(self, get_response: GetResponse) -> None: | |
self.get_response = get_response | |
def __call__(self, request: HttpRequest) -> HttpResponse: | |
return self.get_response(request) | |
def process_view( | |
self, | |
request: HttpRequest, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Alternative version that uses internal-poking technique from: | |
https://www.enterprisedb.com/blog/postgresql-10-identity-columns-explained | |
""" | |
from __future__ import annotations | |
import argparse | |
from typing import Any | |
from django.core.management.base import BaseCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Users/chainz/Downloads/Authlib-1.0.1-py2.py3-none-any/Authlib-1.0.1.dist-info/LICENSE b/Users/chainz/Downloads/Authlib-1.1.0-py2.py3-none-any/Authlib-1.1.0.dist-info/LICENSE | |
similarity index 100% | |
rename from /Users/chainz/Downloads/Authlib-1.0.1-py2.py3-none-any/Authlib-1.0.1.dist-info/LICENSE | |
rename to /Users/chainz/Downloads/Authlib-1.1.0-py2.py3-none-any/Authlib-1.1.0.dist-info/LICENSE | |
diff --git a/Users/chainz/Downloads/Authlib-1.0.1-py2.py3-none-any/Authlib-1.0.1.dist-info/METADATA b/Users/chainz/Downloads/Authlib-1.1.0-py2.py3-none-any/Authlib-1.1.0.dist-info/METADATA | |
similarity index 99% | |
rename from /Users/chainz/Downloads/Authlib-1.0.1-py2.py3-none-any/Authlib-1.0.1.dist-info/METADATA | |
rename to /Users/chainz/Downloads/Authlib-1.1.0-py2.py3-none-any/Authlib-1.1.0.dist-info/METADATA | |
index da8bbee..58ce39e 100644 | |
--- a/Users/chainz/Downloads/Authlib-1.0.1-py2.py3-none-any/Authlib-1.0.1.dist-info/METADATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def adam_get_line_offsets(text: str) -> list[int]: | |
offsets = [0] | |
n = 0 | |
text_index = text.index | |
offsets_append = offsets.append | |
while True: | |
try: | |
n = text_index('\n', n) + 1 | |
except ValueError: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
def main(argv=None): | |
parser = argparse.ArgumentParser( | |
description="Replace curly quotes with straight versions." | |
) | |
parser.add_argument( | |
"file", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime as dt | |
import time | |
import unittest | |
def aws_age_seconds(ec2_launch_time): | |
""" | |
Parse the ec2 launch time string and return how old it is in seconds. | |
""" | |
# Strip trailing subsecond part |
NewerOlder