find:
(^[ \t]*def[ \t]*([a-zA-Z_]+).*?)\n+([ \t]*)
replace:
$1
$3print("function $2")
$3
| 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[Tuple[int, int]]: | |
| """ | |
| each character becomes a tuple of two ints. The first int is either 0,1, or 2 | |
| 0 for characters that come before numbers, 1 for numbers, 2 for after numbers | |
| the second int is the unicode value of the character, or the integer value of the number | |
| that this character is a part of. | |
| $ 7 8 9 a ~ | |
| "$789a~" -> [[0, 36], [1, 789], [1, 789], [1, 789], [2, 97], [2, 126]] | |
| """ | |
| output = [[None, None] for _ in range(len(string))] |
| 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: |
| #!/usr/bin/env python3 | |
| # let's say you have a cron job that updates some cache and you'd like it to | |
| # be updated often. You can measure the time it takes and set the cron frequency | |
| # similar to that amount of time, but what if this machine is running slower one day? | |
| # then, the last iteration of your job will still be running when the next | |
| # iteration begins. What happens if they're both overwriting a file? | |
| # What if the combined load of those two jobs slows down the computer even more, | |
| # and then there are 3 jobs, and so on? |
| #!/bin/bash | |
| for file in $(find /var/spool/postfix/deferred -type f); do postcat -qb $(basename $file); done |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <channel name="xfce4-panel" version="1.0"> | |
| <property name="configver" type="int" value="2"/> | |
| <property name="panels" type="array"> | |
| <value type="int" value="1"/> | |
| <property name="panel-1" type="empty"> | |
| <property name="autohide-behavior" type="uint" value="0"/> | |
| <property name="position" type="string" value="p=10;x=0;y=0"/> | |
| <property name="position-locked" type="bool" value="true"/> |
| import re | |
| import os | |
| import platform | |
| import tempfile | |
| import subprocess | |
| import urllib.request | |
| # https://stackoverflow.com/a/1732454/6307935 | |
| def get_links(url:str) -> list[str]: | |
| response = urllib.request.urlopen(url) |
| from control.matlab import tf, bode, rlocus, nyquist | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from scipy.interpolate import interp1d | |
| def indices_before_sign_flip(x: np.array): | |
| return np.where(np.diff(np.sign(x)))[0] | |
| def find_180deg_crossing_freq(phase, freq): | |
| target_phase = -1*np.pi # for some reason +pi doesn't work |