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
<?xml version="1.0" encoding="UTF-8"?> | |
<opml version="1.1"> | |
<head> | |
<title>Adam Johnson's AWS Old Reader Category</title> | |
<dateCreated>Tue, 01 Dec 2020 12:13:15 GMT</dateCreated> | |
<dateModified>Tue, 01 Dec 2020 12:13:15 GMT</dateModified> | |
<ownerName>me@adamj.eu</ownerName> | |
<ownerEmail>me@adamj.eu</ownerEmail> | |
</head> | |
<body> |
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 subprocess | |
from colorsys import hsv_to_rgb | |
from textwrap import dedent | |
from django.core.management.base import BaseCommand | |
from django.db import DEFAULT_DB_ALIAS, connections | |
from django.db.migrations.loader import MigrationLoader | |
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
from __future__ import annotations | |
import base64 | |
import itertools | |
import random | |
from dataclasses import dataclass | |
from functools import cached_property | |
from math import ceil, floor, log2, log10 | |
from django.db import models |
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 copy import deepcopy | |
import pytest | |
from django.contrib.auth.models import User | |
users = [ | |
User(username="a"), | |
User(username="b"), | |
] |
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
- hosts: localhost | |
connection: local | |
gather_facts: no | |
vars: | |
mylist: | |
- a | |
- b | |
- c | |
tasks: | |
- debug: |
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
- debug: | |
msg: '{{ last|default("") }} -> {{ item }}' | |
- set_fact: | |
last: '{{ item }}' |
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
$ cat base.py | |
class MyMeta(type): | |
def __new__(mcs, name, bases, attrs): | |
return super().__new__(mcs, name, bases, attrs) | |
class MyBase(metaclass=MyMeta): | |
pass | |
$ python -c 'from base import MyBase |
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
# Example of using raylib using only Python standard library | |
# whilst raylib-py looks useful, it seems quite out of date | |
from pathlib import Path | |
from ctypes import CDLL, c_int, c_char_p, c_ubyte, c_bool, Structure | |
raylib = CDLL(Path(__file__).parent / "lib" / "libraylib.3.7.0.dylib") | |
raylib.InitWindow.argtypes = [c_int, c_int, c_char_p] | |
raylib.InitWindow.restype = None |