Skip to content

Instantly share code, notes, and snippets.

View simonLeary42's full-sized avatar

simonLeary42

  • UMass Amherst
  • 20:42 (UTC -05:00)
View GitHub Profile
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
@simonLeary42
simonLeary42 / xfce-panel-win10.xml
Last active December 19, 2023 17:43
windows 10 style XFCE panel. Meant for unprivileged users, no sleep/hibernate/power off buttons. Install to `/etc/xdg/xfce4/panel/default.xml` globally or `~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml` per user.
<?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
def bool_array_find_clusters_and_islands(bool_array):
clusters = []
islands = []
cluster_start_index = None
currently_iterating_through_cluster = False
for i,value in enumerate(bool_array):
value = bool(value)
if currently_iterating_through_cluster and (value is True):
if i == len(bool_array)-1: # if last element
cluster_end_index = i
@simonLeary42
simonLeary42 / simplify.py
Last active November 3, 2023 06:29
simplify math expressions with sympy
import sympy
import readline # allow arrow keys while typing inputs
while True:
expression = input("expression: ")
unknowns = input("unknowns comma delimited: ")
exec_str = f"{unknowns} = sympy.symbols(\"{unknowns}\")"
print(f"> {exec_str}")
exec(exec_str)