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 / 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
@PeterJCLaw
PeterJCLaw / demo_controller.py
Created February 3, 2023 21:47
Webots recognition object orientation quandary
from controller import Robot, Camera
robot = Robot()
camera: Camera = robot.getDevice('camera') # type: ignore
camera.enable(1000 // 30)
camera.recognitionEnable(1000 // 30)
while True:
for obj in camera.getRecognitionObjects():
@PeterJCLaw
PeterJCLaw / generate-code-examples.sh
Created October 16, 2022 22:34
Extract code samples from SR docs
#!/bin/bash
git ls -r |\
grep '\.md$' |\
grep -vP '(troubleshooting/python.md|programming/sr/(compass|radio)/index.md)' |\
xargs ./get-code-chunks.py |\
grep -vP 'R\..+\.something(\.\.\.)?$' > code-examples.py
@PeterJCLaw
PeterJCLaw / .gitignore
Last active February 15, 2021 22:50
Minimal demo of Flask error from Werkzeug 2 change when Sphinx builds docs
/out
/.vscode
@PeterJCLaw
PeterJCLaw / __init__.py
Last active January 15, 2021 20:10
Cut-down reproduce for mypy NamedTuple & generic Callable crash
# empty