This file contains hidden or 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 json | |
import pygments | |
from debug_toolbar.middleware import get_show_toolbar | |
from django.http import HttpResponse | |
from pygments.formatters import HtmlFormatter | |
from pygments.lexers import JsonLexer | |
TRUE_VALUES = ("t", "true", "1", 1, True) |
This file contains hidden or 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
# This script can be easily run with the following command: | |
# $ hatch run uuid7_generation_speed.py | |
# or you can manually install the dependencies and run the script as you like. | |
# | |
# https://github.com/pypa/hatch/blob/master/docs/how-to/run/python-scripts.md | |
# | |
# /// script | |
# title = "Performance test for UUID7 generators" | |
# requires-python = ">=3.12" | |
# dependencies = [ |
This file contains hidden or 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 pkgutil import iter_modules | |
from pprint import pprint | |
from importlib import import_module | |
from importlib.metadata import version as version_il | |
from importlib.metadata import PackageNotFoundError | |
modules = list(iter_modules()) | |
packages = filter(lambda x: x.ispkg, modules) | |
packages = list(packages) # The filter needs to be iterated more than once |
This file contains hidden or 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 time | |
from django.db import connections | |
def management_command_profiler(func): | |
""" | |
This decorator shows the execution time and query count of the function passed. | |
Output is designed to use with methods of management commands. | |
""" |
This file contains hidden or 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
# pip install "httpx>=0.16.1" | |
# Make a dismiss request from https://www.kadenze.com/notifications page manually. | |
# Get x-csrf-token and cookie from that request, fill HEADERS with them. | |
import httpx | |
from pprint import pprint | |
HEADERS = { | |
"accept": "application/json, text/javascript, */*; q=0.01", |
This file contains hidden or 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 django.apps | |
models = django.apps.apps.get_models() | |
for model in models: | |
print(model, model.objects.count()) |
This file contains hidden or 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 jwt | |
from channels.auth import AuthMiddlewareStack | |
from django.conf import settings | |
from django.contrib.auth.models import AnonymousUser | |
from django.db import close_old_connections | |
from rest_framework.authtoken.models import Token | |
from members.models import MemberProfile | |
This file contains hidden or 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 json | |
from debug_toolbar.middleware import DebugToolbarMiddleware as BaseMiddleware | |
from debug_toolbar.middleware import get_show_toolbar | |
from debug_toolbar.toolbar import DebugToolbar | |
from django.template.loader import render_to_string | |
from graphiql_debug_toolbar.middleware import get_payload, set_content_length | |
from graphiql_debug_toolbar.serializers import CallableJSONEncoder | |
__all__ = ['DebugToolbarMiddleware'] |
This file contains hidden or 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
# pip install wget | |
# Save purchase/download page to index.html first | |
from lxml import html | |
import wget | |
book_list_xpath = """//*[@id="papers-content"]/div[11]/div[4]/div/div/div/div""" | |
book_name_xpath = """//*[@id="papers-content"]/div[11]/div[4]/div/div/div/div[{index}]/div/div[2]/div[1]/a/text()""" | |
download_links_path = """//*[@id="papers-content"]/div[11]/div[4]/div/div/div/div[{index}]/div/div[3]/div/div/div/div[1]/a/@href""" |
This file contains hidden or 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 NonHtmlDebugToolbarMiddleware(MiddlewareMixin): | |
""" | |
Converts non-HTML responses to HTML, | |
for being able to profile them with django debug toolbar. | |
Usage: /<endpoint>/?format=json&profile=1 | |
""" | |
def process_response(self, request, response): | |
profile = request.GET.get('profile') |
NewerOlder