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
# Python 3.12.8 | |
# fastapi==0.70.1 | |
# rich==14.2.0 | |
# starlette==0.16.0 | |
from rich import print | |
from fastapi import FastAPI | |
def inspect_middleware(app: FastAPI): | |
# The middleware is a combination of exception handlers and user-defined |
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 django.core.management.commands import showmigrations | |
from django.db import DEFAULT_DB_ALIAS | |
from django.db.migrations.loader import MigrationLoader | |
from django.db.migrations.recorder import MigrationRecorder | |
class Command(showmigrations.Command): | |
help = "Shows the most recently applied migration for each app." | |
def add_arguments(self, parser): |
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
def _pretty_bytes(n_bytes, threshold=10000, include_bytes=True): | |
n = n_bytes | |
suffix = f" ({n_bytes} B)" if include_bytes else "" | |
if n < threshold: | |
return f"{n} B" | |
n /= 1024 | |
if n < threshold: | |
return f"{n:.3f} KiB{suffix}" |
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
""" | |
For unpickling joblib files with renamed imports | |
Sample usage: | |
import_mapping={"bar": "baz.bar"} | |
name_mapping={("old.module", "OldClass"): ("new.module", "NewClass")} | |
with open("foo.joblib", "rb") as f: | |
foo = RemappingNumpyUnpickler( |
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
$('.mord').each(function(i, ele){ | |
if ($(ele).text() == '.') { | |
console.log('Replacing . at ' + i); | |
$(ele).text(',') | |
} | |
return true; | |
}); | |
$('.mord .mpunct').each(function(i, ele){ | |
if ($(ele).text() == ',') { |
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 numpy as np | |
import matplotlib.pyplot as plt | |
# see http://yann.lecun.com/exdb/mnist/ for data format | |
def load_mnist_params(fname): | |
with open(fname, 'rb') as f: | |
magic_number = f.read(4) # 0x00000803 | |
number_of_images = int.from_bytes(f.read(4), byteorder='big') | |
rows = int.from_bytes(f.read(4), byteorder='big') |
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
*.swp | |
libs/ | |
other/ |