Skip to content

Instantly share code, notes, and snippets.

View PeterJCLaw's full-sized avatar

Peter Law PeterJCLaw

  • Marks & Spencer
  • United Kingdom
View GitHub Profile
@PeterJCLaw
PeterJCLaw / export-points-csv.py
Created May 5, 2025 14:51
Script to export SRComp league & game points to a CSV
import csv
from sr.comp.comp import SRComp
from sr.comp.matches import Match
from sr.comp.scores import (
load_external_scores,
load_external_scores_data,
MatchScore,
)
@PeterJCLaw
PeterJCLaw / knockout-progressors.py
Created April 8, 2025 21:35
Static knockout analysis
#!/usr/bin/env python3
import argparse
import collections
import itertools
from pathlib import Path
from typing import IO, Text
import yaml
from sr.comp.knockout_scheduler.static_scheduler import (
@PeterJCLaw
PeterJCLaw / visualise-knockouts.py
Created April 7, 2025 22:37
Script to visualise SRComp static knockout schedules
#!/usr/bin/env python3
# See https://stackoverflow.com/a/10802842
import subprocess
import textwrap
from pathlib import Path
import yaml
from sr.comp.knockout_scheduler.static_scheduler import StaticMatchInfo
@PeterJCLaw
PeterJCLaw / parse-knockout.py
Last active April 8, 2025 20:58
Parse an SR2025 knockout Google Sheet into SRComp's static knockout scheduler format
#!/usr/bin/env python3
import argparse
import collections
import csv
import datetime
import re
import dateutil.tz
import yaml
@PeterJCLaw
PeterJCLaw / camera-see-through-more-things.wbt
Last active October 31, 2023 23:04
Demo of Webots camera seeing through things it shouldn't
#VRML_SIM R2023b utf8
WorldInfo {
basicTimeStep 8
}
Viewpoint {
orientation -0.2641270273446244 0.34818045239496637 0.899448323138205 1.401293242155436
position 1.0361061693335043 -1.5840493074793125 1.7899999051922475
near 0.1
ambientOcclusionRadius 0.3
@PeterJCLaw
PeterJCLaw / protocol-inheritance.py
Created July 26, 2023 15:55
Python protocol inheritance
from typing import Protocol
class IFoo(Protocol):
def bar(self) -> None:
...
class BaseFoo:
def bar(self) -> None:
@PeterJCLaw
PeterJCLaw / enums-value-demo.py
Created July 18, 2023 22:03
Python enum value annotation
import enum
class PlainEnum(enum.Enum):
FIRST = 'first'
SECOND = 'second'
FAIL = 5
reveal_type(PlainEnum.FIRST) # Revealed type is 'Literal[demo.PlainEnum.FIRST]?'
reveal_type(PlainEnum.FIRST.value) # Revealed type is 'builtins.str' # newer: Revealed type is "Literal['first']?"
@PeterJCLaw
PeterJCLaw / README.md
Last active May 13, 2023 14:12
Toy WSGI app for testing Open Telemetry `BatchSpanProcessor`

Demo wsgi app

This is a toy WSGI app under Gunicorn and uWSGI, used to explore forking behaviours interacting with Open Telemetry (and BatchSpanProcessor in particular).

gunicorn wsgi:app --workers 3

Optionally plus --preload, so that gunicorn will import Python into the main process before forking the workers.

@PeterJCLaw
PeterJCLaw / send.py
Last active February 27, 2023 21:10
Scripted email sending with attachments
#!/usr/bin/env python3
"""
Script to send emails with attachments, via gmail.
"""
# Based on a combination of:
# - https://stackoverflow.com/a/3363254/67873
# - https://github.com/PeterJCLaw/libfritter/blob/master/libfritter/mailer.py
@PeterJCLaw
PeterJCLaw / gather-images.sh
Created February 24, 2023 23:11
Generate white-balanced & cropped final images from SR2023 Virtual Competition recordings
#!/bin/sh
set -euo pipefail
# Requirements:
# - ImageMagick and FFMPEG (cli tools on PATH)
# - The script from http://www.fmwconcepts.com/imagemagick/whitebalance/index.php, +x and on PATH
#
# Usage:
# - cd into the directory containing the recordings