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 / make-requirements-if-needed.sh
Created October 19, 2023 20:55
Snapshot of make-requirements-if-needed.sh
#!/usr/bin/env bash
# Run `make requirements` if virtualenv or requirements dir has changed since
# last run.
set -eu -o pipefail
if [[ -z "${VIRTUAL_ENV:-}" ]]; then
echo >&2 "Not in a virtualenv"
exit 1
fi
@timmc-edx
timmc-edx / slack-users-har.sh
Created September 28, 2023 18:42
Extracting Slack user email addresses from a HAR file
# Load a channel's info pane, scroll to the bottom of the member list, export a HAR, then run it through this:
jq '.log.entries[]|select(.request.url|contains("users/list"))|.response.content.text' -r | jq '.results[]|.profile.email' -r
# Useful for workspace migration.
@timmc-edx
timmc-edx / git-collisions.sh
Created August 21, 2023 21:37
Find colliding hash prefixes in a repo
git log --branches --tags --format=format:%H | grep -Po '^.{7}' | sort | uniq -c | grep -v ' 1 '
@timmc-edx
timmc-edx / gist:bf1ef2ccc672df416735deeff449ce45
Last active May 19, 2023 16:46
Finding parent transactions in a New Relic NRQL query based on searching child transactions
select count(*) from Transaction facet name where guid in (
select parentId from (
select count(*) from Transaction facet parentId
where appName = '...' and request_user_id = ... and name = '...'
limit max
)
limit max
)
since 3 days ago limit max
@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
@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 / 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 / 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
#!/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")
# Place in a Python package with this in the setup.py:
#
# entry_points={
# 'console_scripts': [
# 'make = SOME_MODULE.instrument_make:wrapper',
# ],
# },
import re