This file contains 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 | |
""" | |
Trying regular epxressions purported to match double quoted strings with backslash escapes | |
Syntax changes made vs sources | |
- Changed capture groups to non-capture groups () -> (?:) | |
- Removed escaping of double quotes \" -> " | |
""" | |
import re |
This file contains 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
start : brace+ | |
brace : [preamble] expandable [postscript] | |
preamble : /[^{}]+/ | |
postscript : /[^{}]+/ | |
expandable : "{" (range | list) "}" | |
range : begin ".." end [".." step] | |
begin : BOUND |
This file contains 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 | |
import regex | |
PATTERN = regex.compile(r''' | |
# Declare reusable sub-patterns | |
(?(DEFINE) | |
(?<COUNT>[0-9]+) | |
(?<CURRENCY>EUR|GBP|USD) | |
(?<QUANTITY>[0-9]+[.][0-9]+) |
This file contains 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 collections | |
from typing import Generator, Iterable, TypeVar | |
T = TypeVar('T') | |
def flag_last(iterable:Iterable[T]) -> Generator[None, tuple[T, bool], None]: | |
""" | |
Yield (item, is_last) for each item in iterable, is_last is True on the | |
last item, False otherwise. |
This file contains 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 os | |
import shutil | |
import string | |
import timeit | |
class FakeDirEntry: | |
def __init__(self, path): | |
self.path = path | |
self.name = path |
This file contains 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 copy_atomic(src, dst, follow_symlinks=True): | |
""" | |
Copy src file to dst atomically, via a temporary file that is renamed. | |
It is intended to be a drop in replacement for `shutil.copy2()`. | |
""" | |
if os.path.isdir(dst): | |
dst_dir = dst | |
dst_name = os.path.basename(src) | |
dst = os.path.join(dst, dst_name) |
This file contains 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 fastapi import FastAPI | |
app = FastAPI() | |
@app.get("/") | |
def root(): | |
return {"greeting": "Hello"} |
This file contains 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 | |
import logging | |
log = logging.getLogger('systemd_demo') | |
log.setLevel(logging.DEBUG) | |
# Official bindings | |
import systemd.journal |
This file contains 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 | |
""" | |
Determine whether stderr is connected to systemd journal, and hence whether | |
structured events can be written to the journal. | |
Based on https://systemd.io/JOURNAL_NATIVE_PROTOCOL/#automatic-protocol-upgrading | |
""" | |
import os | |
import sys |
This file contains 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 ansible-playbook | |
--- | |
- name: Test behaviour of version test | |
hosts: localhost | |
gather_facts: false | |
tasks: | |
- name: Expected results, comparing a.b.c <-> x.y.z, or a.b <-> x.y | |
debug: | |
msg: | |
- '"1.0" is version("1.0", "==") -> {{ "1.0" is version("1.0", "==") }}' |