Skip to content

Instantly share code, notes, and snippets.

View maxfischer2781's full-sized avatar

Max Fischer maxfischer2781

View GitHub Profile
@maxfischer2781
maxfischer2781 / apel-gap-publish.py
Created July 13, 2023 16:15
APEL gap publish CLI
#!/usr/bin/python3
from typing import Generator
import argparse
import configparser
import contextlib
import datetime
import pathlib
import tempfile
import subprocess
@maxfischer2781
maxfischer2781 / apel.diff
Created May 11, 2023 13:46
APEL HEPScore23 Patch
diff -cB --recursive production/usr/lib/python2.7/site-packages/apel/db/__init__.py patched/usr/lib/python2.7/site-packages/apel/db/__init__.py
*** production/usr/lib/python2.7/site-packages/apel/db/__init__.py 2021-03-22 17:42:15.000000000 +0100
--- patched/usr/lib/python2.7/site-packages/apel/db/__init__.py 2023-04-05 10:39:54.000000000 +0200
***************
*** 15,21 ****
'''
LOGGER_ID = "apeldb"
! JOB_MSG_HEADER = "APEL-individual-job-message: v0.3"
SUMMARY_MSG_HEADER = "APEL-summary-job-message: v0.2"
@maxfischer2781
maxfischer2781 / except_delete.py
Created February 28, 2022 16:48
Demonstrator for except clause deleting its target
v = "Hello World"
def scope():
global v
try:
1/0
except ZeroDivisionError as v:
pass
print(v)
@maxfischer2781
maxfischer2781 / slot_lookup.py
Created January 11, 2022 09:25
Draft for special method lookup
def slot_get(ob: object, field: str):
tp = type(ob)
try:
field = tp.__dict__[field]
except KeyError:
return getattr(super(tp, ob), field)
else:
try:
descriptor_get = field.__get__
except AttributeError:
@maxfischer2781
maxfischer2781 / gather_overhead.py
Created October 27, 2021 11:31
Script for measuring the overhead of asyncio.gather
import asyncio
import time
async def no_op():
return
async def main_gather(count):
await asyncio.gather(*(asyncio.gather(no_op()) for _ in range(count)))
@maxfischer2781
maxfischer2781 / base_playground.py
Last active October 14, 2021 07:43
Simple Physics Notation to Quantum Circuit example
# Measuring < 00 | X | 00 >, < 01 | X | 00 >, < 10 | X | 00 >, < 11 | X_0 | 00 >
from qiskit import QuantumCircuit
from qiskit.providers.aer import QasmSimulator
import time
# Use Aer's qasm_simulator
simulator = QasmSimulator()
# Circuit setup
circuit = QuantumCircuit(2) # |00>
@maxfischer2781
maxfischer2781 / decosample.py
Last active August 30, 2021 11:52
Helper that allows using the same decorator for both functions and methods
"""
Basic "Decoscriptor" example
"""
from decoscriptor import anydeco
@anydeco
def art(fun, *args, **kwargs):
print("Big Whoop and a bottle of", args, kwargs)
print("Fun is set to", getattr(fun, "__self__", "<unbound>"))
return fun(*args, **kwargs)
@maxfischer2781
maxfischer2781 / context_average.py
Created July 7, 2021 17:36
Use a context manager to average over several method calls
from contextlib import contextmanager
class Optimizer:
def __init__(self, weight: int):
self.weight = weight
def step(self, num):
num = self.calculate(num)
return self.apply(num)
@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(