Skip to content

Instantly share code, notes, and snippets.

View PeterJCLaw's full-sized avatar

Peter Law PeterJCLaw

View GitHub Profile
@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
@PeterJCLaw
PeterJCLaw / remote-setup.sh
Created December 20, 2020 14:24
Running webots on Digial Ocean
#!/bin/sh -ex
### As root
apt update
apt upgrade --yes
wget https://github.com/cyberbotics/webots/releases/download/R2020b-rev1/webots_2020b-rev1_amd64.deb -O /webots_2020b-rev1_amd64.deb
apt install --yes python3-venv xvfb /webots_2020b-rev1_amd64.deb
@PeterJCLaw
PeterJCLaw / crons.py
Created October 9, 2020 12:10
Helper for finding DLQ crons which run at a given time
from django_lightweight_queue.cron_scheduler import get_cron_config
cc = get_cron_config()
crons_then = set()
for x in cc:
for hour in (22, 23, 0):
for minute in range(3):
if (
@PeterJCLaw
PeterJCLaw / aliases.sh
Created July 23, 2020 18:32
Aliases useful for linting changes in a Python project in a git repo
# Python Project things
run-py-branch() { git diff origin/master... --name-only --diff-filter=d | grep '\.py$' | xargs --no-run-if-empty "$@"; }
run-py-local() { git diff --name-only --diff-filter=d | grep '\.py$' | xargs --no-run-if-empty "$@"; }
run-py-cache() { git diff --cached --name-only --diff-filter=d | grep '\.py$' | xargs --no-run-if-empty "$@"; }
isort-branch() { run-py-branch isort; }
isort-local() { run-py-local isort; }
isort-cache() { run-py-cache isort; }
flake8-branch() { run-py-branch flake8; }
@PeterJCLaw
PeterJCLaw / git-fixup
Last active May 21, 2020 22:29
Command to fixup a single historical git commit
#!/bin/sh
# I found this (or something like it) on a blog at one point and now can't find it.
# If you know where this came from feel free to comment and I'll happily add attribution.
# Installation: put this in your $PATH as an executable file.
#
# Usage:
# - stage the changes you want applied
# - run `git fixup $COMMIT`
@PeterJCLaw
PeterJCLaw / README.md
Last active March 6, 2020 23:59
Debug a robot.py using VSCode

Debug a robot.py using VSCode

These instructions will allow you to debug robot code running on a Student Robotics kit using [VSCode][vscode].

  1. Setup [VSCode][vscode] locally
  2. Add the following to the project to debug:
    # Near the top of `robot.py`
    import ptvsd

ptvsd.enable_attach()

@PeterJCLaw
PeterJCLaw / demo.py
Created February 23, 2020 23:36
jedi handling of annotated non-ClassVar class attributes
from typing import ClassVar
class A:
cls_attr = 1
cls_attr_comment = 2 # type: int
cls_attr_classvar_comment = 2 # type: ClassVar[int]
cls_attr_hint: int = 3
cls_attr_classvar_hint: ClassVar[int] = 3
@classmethod