Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
simonLeary42 / ldap_user_editor.py
Last active October 4, 2023 16:09
python LDAP user editor
#!/usr/bin/env python3
import sys
import atexit
import ldap3
__LDAP_USER = ""
__LDAP_PASSWORD = ""
__LOCKED_STR = b"LOCKED"
__USERS = "ou=users,dc=unity,dc=rc,dc=umass,dc=edu"
#!/bin/sh
prepend_path() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: prepend_path <directory> <env.var>"
echo "e.g. prepend_path ~/.local/bin PATH"
echo "received: prepend_path $@"
return 1
fi
local dir="$1"
local env_var="$2"
#!/bin/bash
# assuming that username is LDAP `cn` and email is LDAP `mail`
USERS="ou=users,dc=unity,dc=rc,dc=umass,dc=edu"
ldapsearch -LLL -x -o ldif-wrap=no -b $USERS mail cn |
grep -v dn: | # delete lines that have `dn:`
tr '\n' ',' | # replace newlines with command
sed -r 's/\,{2,}/\n/g' | # replace multiple commans with a newline
sed -r 's/mail: (.*),cn: (.*)/cn: \2,mail: \1/g' | # if string is `mail,cn` rearrange it to be `cn,mail`
sed 's/mail: //g' | # remove `mail: `
sed 's/cn: //g' # remove `cn: `
# print to stderr. If stderr is a TTY, print in red
def print_err(*args, **kwargs):
if sys.stderr.isatty():
print('\033[1;31m', end='', file=sys.stderr)
print(*args, **kwargs, file=sys.stderr)
if sys.stderr.isatty():
print('\033[0m', end='', file=sys.stderr)
@simonLeary42
simonLeary42 / rm_edf_scheduling.py
Last active May 6, 2023 17:15
A simulation of Rate Monotonic and Earliest Deadline First scheduling algorithms
import random
import bisect
import math
N = 4 # number of different tasks
T_MAX = 25 # how many time steps to simulate
MIN_PERIOD = 2 #integer!
MAX_PERIOD = 9 #integer!
class Task:
import re
def indent(string: str, indenter=" ", num_indents=1) -> str:
for i in range(num_indents):
string = indenter + string # first line
string = string.replace('\n', '\n'+indenter) # all other lines
return string
def remove_empty_lines(string: str) -> str:
return re.sub(r"\n{2,}", '\n', string)
alias ls="ls --color=auto -F --quoting-style=shell"
alias la="ls -a"
alias ll="ls -la"
alias cp="cp -v"
alias rm="rm -v"
alias mv="mv -v"
alias chmod="chmod -v"
alias chown="chown -v"
alias df="/bin/df -h --output=source,size,used,avail,pcent,file"
alias cdp="cd $OLDPWD"
@simonLeary42
simonLeary42 / gist:00a490b50310a52a65e76503c69a4070
Created April 11, 2023 20:33
powershell equivalent to `chmod -w`
function Remove-Write-Privs{
param([string]$filename)
$acl = Get-Acl $filename
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users", "Write", "Deny")
$acl.AddAccessRule($rule)
Set-Acl $filename $acl
}