Skip to content

Instantly share code, notes, and snippets.

@dat-boris
dat-boris / opencv_pnp_roundtrip.py
Created November 10, 2024 20:47
OpenCV solvePnP and projectPoints roundtrip test
import cv2
import numpy as np
# Define 3D object points
object_points = np.array([
[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0]
], dtype=np.float32)
@dat-boris
dat-boris / extract_keyframe.py
Created October 4, 2024 15:02
Example code for creating keyframe from screen capture
#!/usr/bin/env python3
"""A simple script to capture screen, that then post to the server as websocket
for setting up the messages.
We log these folders to allow for the case for following through the data. The
folder structure works with:
- logs/video/<yyyymmdd-hhmmss>.avi
- logs/keyframes/<yyyymmdd-hhmmss>_<frame>.png
@dat-boris
dat-boris / download_video.py
Created September 7, 2024 16:17
A script for downloading video from https://publicorderemergencycommission.ca
#!/usr/bin/env python
"""A script for downloading video from https://publicorderemergencycommission.ca
Oh my, the site is awful! It streams the mp4 in .ts format that is much slower
than the stream reate. So this script downloads the stream and compress it using
ffmpeg h264 codec.
You will need to find the video link - you can do that by using the developer tool
when playing the video on page
@dat-boris
dat-boris / out_loud.py
Created April 18, 2022 22:19
Script for making sure I read out loud while I am typing text.
#!/usr/bin/env python
"""Ensure that you write out loud when you write your text.
brew install portaudio
pip installl pynput speechrecognition pyaudio pyttsx3
./out_loud.py
WARNING: you might need to hack your security setting following:
https://stackoverflow.com/questions/53088995/pynput-keyboard-listener-does-not-detect-keys-on-mac-os-x
"""
@dat-boris
dat-boris / petting_zoo_tutorial.py
Created October 10, 2021 03:59
Petting Zoo tutorial
"""PettingZoo
Tutorial from: https://nbviewer.org/github/gsverhoeven/gt_rl_course/blob/master/week_8/marl_tictactoe.ipynb
Setup:
pipenv install pettingzoo[classic]
"""
import random
@dat-boris
dat-boris / test_port_listen.go
Last active April 21, 2021 17:17
Looking at difference between port listening with/ without loopback address
package main
import (
"fmt"
"os"
"net"
"log"
"time"
)
func main() {
port := os.Args[1]
@dat-boris
dat-boris / read_gcs.py
Created January 18, 2021 20:06
Quick snippet for reading GCS file
import re
import tempfile
import google.cloud.storage as storage
def analyse_one_logfile(gcs_full_path):
client = storage.Client()
bucket = client.get_bucket(DEV_LOGFILE_BUCKET_NAME)
m = re.match('gs://{}/(.*)'.format(DEV_LOGFILE_BUCKET_NAME), gcs_full_path)
@dat-boris
dat-boris / pnp2tts.py
Last active January 3, 2021 21:14
A script I use to export PnP file into JPG for Tabletop Simulator import
#!/usr/bin/env python
"""Script for joining PDF into image output.
Prerequisite:
# This takes a bit of time!
brew install poppler
pipenv install pillow pdf2image
I use this for converting PnP pdf into image to be uploaded to TTS.
@dat-boris
dat-boris / export_instance_count.py
Last active October 27, 2021 12:37
Exporting instance count from stackdriver metrics
"""
Code for exporting instance count for last month
Setup:
pip install --upgrade google-cloud-monitoring
DOC:
https://cloud.google.com/monitoring/docs/reference/libraries#client-libraries-usage-python
Code snippet:
https://cloud.google.com/monitoring/custom-metrics/reading-metrics
@dat-boris
dat-boris / fix_broken_key_mapping.sh
Created September 17, 2020 03:58
For mac. use this to remap keys
# Remap F1 to backtick (my backtick is broken, use F1 instead)
# https://apple.stackexchange.com/questions/283252/how-do-i-remap-a-key-in-macos-sierra-e-g-right-alt-to-right-control
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html
hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x70000003a,
"HIDKeyboardModifierMappingDst":0x700000035}]
}'