find:
(^[ \t]*def[ \t]*([a-zA-Z_]+).*?)\n+([ \t]*)
replace:
$1
$3print("function $2")
$3
import sys | |
import json | |
import yaml | |
import shutil | |
import subprocess | |
from ansible.plugins.action import ActionBase | |
""" | |
fails if bitwarden is not unlocked |
{ | |
"description": "ctrl+v -> ctrl+shift+option+v (only Stickies)", | |
"manipulators": [ | |
{ | |
"conditions": [ | |
{ | |
"bundle_identifiers": [ | |
"^com\\.apple\\.Stickies$" | |
], | |
"type": "frontmost_application_if" |
def _format_diff_strings(before: str, after: str) -> str: | |
before_lines = before.splitlines() | |
after_lines = after.splitlines() | |
diff = difflib.unified_diff(before_lines, after_lines, lineterm="") | |
output = "" | |
removed_lines = [] | |
added_lines = [] | |
def _format_added_removed(): | |
# given the current state of the `added` and `removed` variables, add text to the `output` |
import os | |
import threading | |
import subprocess | |
before = "" | |
after = "" | |
before_read_fd, before_write_fd = os.pipe() | |
after_read_fd, after_write_fd = os.pipe() | |
diff_proc = subprocess.Popen( |
# ansible module | |
import os | |
from ansible.module_utils.basic import AnsibleModule | |
def main(): | |
module = AnsibleModule( | |
argument_spec=dict( | |
paths=dict(type="list", required=True), | |
follow=dict(type="bool", default=True), | |
), |
def dict2xml(x: dict, indent=0) -> str: | |
assert isinstance(x, dict) | |
assert len(x) == 1 | |
datatype = list(x.keys())[0] | |
assert re.fullmatch(r"[a-zA-Z0-9_]+", datatype) | |
data = x[datatype] | |
body = "" | |
if "__content__" in data: | |
assert isinstance(data["__content__"], str) | |
body += f"{' '*(indent+2)}{data['__content__']}" |
find:
(^[ \t]*def[ \t]*([a-zA-Z_]+).*?)\n+([ \t]*)
replace:
$1
$3print("function $2")
$3
function nodes_with_state(){ | |
sinfo -N --json | jq -r '.sinfo | .[] | select(any(.node.state[]; .=="$1")) | .nodes.nodes[0]' | |
} |
def make_string_sortable_numerically(string:str) -> List[int]: | |
""" | |
convert string to list of int unicode values | |
but, any groups of 2 or more digits are converted to an int | |
the output value for both those indexes = some big number + int | |
"abc100" -> [97, 98, 99, 10100, 10100, 10100] | |
""" | |
output = [ord(c) for c in string] | |
skip_these_indexes = [False]*len(string) | |
big_number = 10000 |
def string_matches_any_globs(x:str, globs:List[str]): | |
return any(fnmatch.fnmatch(x, y) for y in globs) | |
def find_files(walk_root_path:str, include_globs:List[str], exclude_globs:List[str]=None) -> list: | |
""" | |
excluding takes precidence over including | |
""" | |
output = [] | |
for dirname, _, basenames in os.walk(walk_root_path): | |
for basename in basenames: |