Skip to content

Instantly share code, notes, and snippets.

View maxfischer2781's full-sized avatar

Max Kühn maxfischer2781

  • Karlsruhe, Germany
View GitHub Profile
@maxfischer2781
maxfischer2781 / pyparsing_lr.py
Created June 27, 2021 17:33
Railroad for a left-recursive PyParsing grammar
import pyparsing as pp
from pyparsing.diagram import to_railroad, railroad_to_html
import tempfile
import webbrowser
pp.ParserElement.enable_left_recursion()
# named references
expr = pp.Forward().setName("expr")
add_sub = pp.Forward().setName("add_sub")
@maxfischer2781
maxfischer2781 / udp_deck.py
Last active June 22, 2021 16:37
Utility to record/replay UDP datagrams
#!/usr/bin/env python3
from typing import BinaryIO
import socket
import argparse
import pathlib
import struct
import time
CLI = argparse.ArgumentParser(
@maxfischer2781
maxfischer2781 / new_factory.py
Created February 23, 2021 10:28
Example of using `__new__` as a subclass factory
class Number:
def __new__(cls, literal):
for scls in cls.__subclasses__():
try:
return scls(literal)
except (TypeError, ValueError):
pass
raise TypeError("The path to hell is paved with incomplete examples")
# here be numerical operations!
@maxfischer2781
maxfischer2781 / apel_fixup.py
Created February 16, 2021 17:08
Script to recreate missing HTCondor-CE APEL blah/batch records from a condor history.d directory
"""
Script to recreate missing APEL blah/batch records from a condor history.d directory
"""
from typing import TextIO, TypeVar, List
import argparse
import pathlib
import subprocess
import os
import threading
import tempfile
@maxfischer2781
maxfischer2781 / so64893801.py
Created November 19, 2020 13:11
Example code for SO "Type annotations for abstract classes that are coupled by a shared, arbitrary type"
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Generic, TypeVar
R = TypeVar('R', bound='Runner')
T = TypeVar('T') # result type
class Command(ABC, Generic[T, R]):
@maxfischer2781
maxfischer2781 / htcce-apel.md
Last active April 13, 2024 17:35
HTCondor-CE APEL Notes

Notes on using HTCondor-CE with APEL accounting for WLCG

These are tales of An Admin getting APEL+HTCondor-CE to work at GridKa/FZK Tier 1.

As background information, see

Setting up HTCondor-CE for APEL

@maxfischer2781
maxfischer2781 / jobwrapper.sh
Created July 16, 2020 08:53
Configure HTCondor Startd to run jobs with login-environment
#!/bin/bash -l
#
# Wrapper when executing condor jobs
# Run jobs via `bash -l` to force sourcing a login shell including all /etc/profile.d/*.sh scripts
#
exec "$@"
@maxfischer2781
maxfischer2781 / make_gridmapdir.py
Last active June 23, 2020 11:56
Create a gridmapdir from a groupmap file and accounts
#!/usr/bin/env python3
from typing import NamedTuple, Iterable, Dict, List
import argparse
import pathlib
import re
CLI = argparse.ArgumentParser()
CLI.add_argument(
@maxfischer2781
maxfischer2781 / condor_switch.py
Created April 23, 2020 11:37
Compile HTCondor if-then cases to a single if-then-else tree
#!/usr/bin/env python3
from typing import Dict
def switch(cases: Dict[str, str], default='UNDEFINED', separator='\n'):
# ["IfThenElse(ac, am", "IfThenElse(bc, bm", "IfThenElse(cc, cm", ...]
switch_expression = separator.join(
f"IfThenElse({condition}, {on_match},"
for condition, on_match in cases.items()
)
@maxfischer2781
maxfischer2781 / detailed_monitored_pipe.py
Created February 20, 2020 14:56
Variant of usim.Pipe that allows detailed load monitoring
from typing import NamedTuple, Optional, Deque, Any, Dict, AsyncIterable
from usim import Pipe, instant
from collections import deque
from usim._primitives.notification import Notification
class MonitoredPipeInfo(NamedTuple):
requested_throughput: float
available_throughput: float