Skip to content

Instantly share code, notes, and snippets.

View bradmartin333's full-sized avatar

Brad Martin bradmartin333

View GitHub Profile
@bradmartin333
bradmartin333 / bluetooth_printer.py
Created June 6, 2025 20:38
discover a bluetooth printer and send it a CLI argument message to print
import bluetooth
import sys
if len(sys.argv) != 2:
print(f"usage: {sys.argv[0]} <message>")
sys.exit(1)
message = sys.argv[1]
nearby_devices = bluetooth.discover_devices(
@bradmartin333
bradmartin333 / print_quote.py
Created June 6, 2025 19:26
print zen quote to USB thermal printer
import requests
PRINTER_DEVICE = "/dev/usb/lp0"
with open(PRINTER_DEVICE, "wb") as printer:
response = requests.get("https://zenquotes.io/api/random")
response.raise_for_status()
data = response.json()
if data and isinstance(data, list) and len(data) > 0:
quote_data = data[0]
quote = quote_data.get("q")
@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):