Skip to content

Instantly share code, notes, and snippets.

View bradmartin333's full-sized avatar

Brad Martin bradmartin333

View GitHub Profile
@bradmartin333
bradmartin333 / kb.cpp
Created October 19, 2024 02:46
stream keyboard input on a thread
#include <iostream>
#include <thread>
#include <termios.h>
#include <unistd.h>
void processKeyboardInput() {
termios original_settings, new_settings;
tcgetattr(STDIN_FILENO, &original_settings);
new_settings = original_settings;
new_settings.c_lflag &= ~ICANON;
@bradmartin333
bradmartin333 / pdf_renamer.py
Created January 15, 2024 16:38
rename PDFs easily
import os
import subprocess
def rename_pdfs(directory):
"""Iterates through PDFs in a directory, opens them, and renames them with user input."""
pdf_files = [f for f in os.listdir(directory) if f.endswith(".pdf")]
for filename in pdf_files:
pdf_path = os.path.join(directory, filename)
@bradmartin333
bradmartin333 / gen.py
Created January 4, 2024 23:24
scaled plotting in raylib
import random
import csv
def rim():
return random.randint(0, 2**32 - 1)
def write_to_csv(data, filename):
with open(filename, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerows(data)
@bradmartin333
bradmartin333 / HEIC_to_PNG.sh
Last active October 31, 2023 14:58
batch convert HEIC images to PNG with WSL2 and ImageMagick
#!/bin/bash
: ' Setup
Put script in dir with HEIC images
Install imagemagick: sudo apt install imagemagick
Allow larger cache
- sudo nano /etc/ImageMagick-6/policy.xml
- change <policy domain="resource" name="disk" value="1GiB"/>
@bradmartin333
bradmartin333 / negative_yaw_sim.py
Created October 19, 2023 12:21
visual way to debug an acceptable range of degrees
from pyray import *
import math
show_instruction = True
cone_deg_half = 25
heading = 340
window_size = Vector2(800, 500)
text_size = int(window_size.y / 20)
center = Vector2(window_size.x / 2, window_size.y / 2)
@bradmartin333
bradmartin333 / DirList.ino
Created August 3, 2023 13:16
List directory of Mbed OS filesystem on APMC
/*
Portenta - DirList
The sketch shows how to mount an usb storage device and how to
get a list of the existing folders and files.
The circuit:
- Portenta H7
This example code is in the public domain.
@bradmartin333
bradmartin333 / markImages.py
Created June 1, 2023 01:29
Mark images with proportional text
from PIL import Image, ImageDraw, ImageFont
import os
filelist = os.listdir(".")
filelist.sort()
jpglist = []
for filename in filelist:
if filename[0] == "g":
jpglist.append(filename)
@bradmartin333
bradmartin333 / raylib_keystone.py
Last active May 12, 2023 18:39
Keystone correction using y = mx + b
from pyray import *
import csv
# Constants
start_wid = 800
start_hgt = 600
debug = True
def lerp(v1: Vector2, v2: Vector2, ratio: float):
@bradmartin333
bradmartin333 / FlashManagement.ino
Created April 18, 2023 12:58
Read and write to mbed filesystem on Arduino Portenta Machine Control
#include "PluggableUSBMSD.h"
#include "QSPIFBlockDevice.h"
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"
REDIRECT_STDOUT_TO(Serial)
static QSPIFBlockDevice root;
mbed::MBRBlockDevice fs_data(&root, 1);
static mbed::FATFileSystem fs("fs");
void USBMSD::begin() {
@bradmartin333
bradmartin333 / focus.cs
Created February 23, 2023 03:19
Calculate entropy-based image focus score
internal class Focus
{
public string ElapsedTime;
public Bitmap ScaledImage;
private int ScanSize, Width, Height;
private const double ImageScaling = 0.2;
private const int GridSize = 20; // N x N grid
private const double DataPercentage = 0.2; // Highest % of available data from training grid
private int[] Tiles;
private double[] Scores;