Skip to content

Instantly share code, notes, and snippets.

View timmc-edx's full-sized avatar

Tim McCormack timmc-edx

View GitHub Profile
@timmc-edx
timmc-edx / first.py
Last active June 2, 2020 13:50
terrible scope example in python
# python3 ./first.py
import second
import builtins
builtins.magic = "wow"
second.some_func()
@timmc-edx
timmc-edx / pr-checklist.md
Last active January 27, 2021 14:14
Code review checklist, edX version

Have the following been addressed in the branch, if appropriate?

  • Tests (unit, API, integration)
  • Docs (source comments, doc directory, elsewhere)
  • Changelog
  • Compatibility with previous versions (calls, shared files or DBs, data formats -- backward and forward compatibility)
  • Rollback friendly?
  • Feature switches?

edX-specific considerations:

  • Why did [mistaken action] seem like the correct action at the time?
  • Why was the problem not detected automatically?
    • Why was the mistake caught late, not early?
  • Why was the problem not fixed automatically?
    • Why did this require manual intervention?
    • Why did this require human detection?
  • Were any of the contributing factors already known problems?
    • Why were they not addressed earlier?
    • Have we seen these in previous RCAs?
# Place in a Python package with this in the setup.py:
#
# entry_points={
# 'console_scripts': [
# 'make = SOME_MODULE.instrument_make:wrapper',
# ],
# },
import re
#!/usr/bin/python3
import collections
import datetime
import os
import sys
tz = datetime.timezone(offset=datetime.timedelta(hours=-5))
logfile = os.path.expanduser("~/context-switches.log")
@timmc-edx
timmc-edx / gpm.sh
Created February 11, 2022 22:52
Aliases for fetch or pulling the git default branch
function git_default_branch {
# Guess the name of the remote -- either origin or the first other remote
guessed_remote="$(
(
git remote | grep -P '^origin$'
git remote | grep -P '^origin$' -v
) | head -n1 | tr -d '\n'
)"
git symbolic-ref "refs/remotes/$guessed_remote/HEAD" \
| sed 's|^refs/remotes/[^/]\+/||'
@timmc-edx
timmc-edx / class_graph.py
Last active August 12, 2022 18:36
Load and display Python class hierarchy
"""
Build and display a graph of classes in a module.
Call from virtualenv of repo you're inspecting.
Example call, from inside edx-platform:
DJANGO_SETTINGS_MODULE=lms.envs.test python3 ./class_graph.py xmodule.modulestore BulkOperationsMixin | dot -Tsvg > BulkOperationsMixin.svg
"""
@timmc-edx
timmc-edx / notify_rebase.py
Created June 25, 2021 14:45
ARCHBOM-1819
#!/usr/bin/env python3
# This script records an action we took to leave a comment on (almost)
# every open edx-platform PR to let people know that they needed to
# rebase onto master (or merge it into their branch) to avoid breaking
# the build.
#
# The script requires a Github access token and finds all open PRs
# against master on edx-platform which do not have a specific commit
# in their ancestors, then leaves a comment on each one. This should
# be done from a bot account; the bot will then be subscribed to all
@timmc-edx
timmc-edx / check-jwt-keys.sh
Last active May 18, 2023 16:49
Check that the JWT public keys are readable and identical across all of the configs, per environment.
grep -Prl 'JWT_PUBLIC_SIGNING_JWK_SET(?!.*\}\})' ~/edx-repos/*-internal | while IFS= read -r fp; do
cat -- "$fp" | yq '.. | .JWT_PUBLIC_SIGNING_JWK_SET? | select(. != null)' -r | jq . -c --sort-keys || echo "Error in file $fp"
done | sort | uniq -c | sort -rn | less -Sn