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
"""Ted Moskovitz, 2025 | |
A toy implementation of dictionaries/hash tables using | |
1) compact dict structure | |
2) linear probing with perturb | |
More info: https://tedmoskovitz.github.io/posts/compact_dicts/post | |
""" | |
from typing import Any | |
import math | |
from sys import getsizeof |
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 collections import OrderedDict | |
def lru_cache(maxsize=128): | |
if maxsize is None: | |
maxsize = float('inf') | |
if maxsize <= 0: | |
raise ValueError("negative size") | |
def decorator(func): |
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 | |
def xentropy_loss(target_BO, pred_BO): | |
return -np.mean(target_BO * np.log(pred_BO + 1e-15)) | |
def batch_softmax(x_BO): | |
# subtract the max to avoid overflow | |
max_x_B1 = np.max(x_BO, axis=-1)[:, None] | |
exp_x_BO = np.exp(x_BO - max_x_B1) | |
return exp_x_BO / np.sum(exp_x_BO, axis=-1)[:, None] |
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
""" | |
A python script that merges two .bib files. | |
The merging is done according to entry title. If the same title appears more than | |
once, the first instance of the title will be preserved, and the second and | |
subsequent instances will not be included. | |
Usage: python merge_bib.py <bib1> <bib2> <output> | |
""" | |
import sys |
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
"""A minimal asychronous/concurrent web crawler. Author: Ted Moskovitz, 2024""" | |
from aiohttp import ClientSession | |
import asyncio | |
from bs4 import BeautifulSoup | |
import concurrent.futures as cf | |
import logging | |
from posixpath import normpath | |
from typing import Tuple, List, Optional, Callable | |
from urllib.parse import urlparse, urlsplit, urlunsplit, parse_qsl, urlencode | |
from urllib.robotparser import RobotFileParser |