Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
simonLeary42 / firefox-toggle-config-option.sh
Last active September 28, 2023 16:59
Script to toggle the firefox `mousewheel.default.delta_multiplier_y` setting between two values. This is useful when I want one scroll sensitivity for my touchpad and another sensitivity for my mouse.
#!/bin/bash
set -eo pipefail
SETTING="mousewheel.default.delta_multiplier_y"
CONFIG_FILE_PATH="/home/simon/.mozilla/firefox/shlbuz9i.default-esr/prefs.js"
LOW="30" # comfortable with my macbook 2015 touchpad
HIGH="101" # 100 is default, firefox deletes default values from the file
firefox_found=$(pgrep -U "$(whoami)" -fx '(.*/)?firefox(-esr)?$' | uniq || true)
@simonLeary42
simonLeary42 / .gitlab-ci.yml
Last active August 1, 2023 22:37
general purpose GitLab CI style check with prettier, plus local shell script to format with prettier. This ensures that the local formatting and the remote style check use the same version, and little effort is required on the local end
prettier_style_check:
image: node:latest
stage: test
script:
- npm install -g prettier
- prettier --version
- prettier . --check || { echo "did you run \`format.sh\`?"; exit 1; }
@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
}