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 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! |
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
#!/usr/bin/env python3 | |
from typing import BinaryIO | |
import socket | |
import argparse | |
import pathlib | |
import struct | |
import time | |
CLI = argparse.ArgumentParser( |
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 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") |
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 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) |
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
""" | |
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) |
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
# 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> |
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 asyncio | |
import time | |
async def no_op(): | |
return | |
async def main_gather(count): | |
await asyncio.gather(*(asyncio.gather(no_op()) for _ in range(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
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: |
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
v = "Hello World" | |
def scope(): | |
global v | |
try: | |
1/0 | |
except ZeroDivisionError as v: | |
pass | |
print(v) |
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
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" |