Skip to content

Instantly share code, notes, and snippets.

@mofosyne
mofosyne / KiCad_Project_Checklist
Created August 20, 2025 11:47 — forked from MarcoCiau/KiCad_Project_Checklist
KiCad Project Checklist Template
# KiCad Project README
Welcome to the KiCad project! This repository contains all the files and documentation related to our project. Please refer to this README for important information and guidelines.
## Project Overview
- **Project Name:** [Your Project Name]
- **Project Description:** [Brief description of the project goals and objectives]
## Project Checklist
@mofosyne
mofosyne / item_basic_product_search.py
Last active June 11, 2025 01:26
item part basic product search
#!/usr/bin/env python3
# Item API Basic Product Search
import urllib.request # Query API
import json # Parsing API response
import os # For cache support
def get_url_content(url: str) -> str:
"""
Retrieves the content of a given URL as a string.
@mofosyne
mofosyne / get_url_json_api.py
Created June 10, 2025 14:33
Builtin Only Python URL getter for plain and json apis (Intended for use with simple script for accessing simple APIs)
import urllib.request
import json
def get_url_content(url: str) -> str:
"""
Retrieves the content of a given URL as a string.
Args:
url (str): The URL to retrieve content from.
@mofosyne
mofosyne / creative-archival-iso.sh
Last active March 10, 2025 20:39
hybrid ISO image with dvdisaster enhancement script (WIP Untested) (Suggestion Welcomed)
#!/bin/bash
#
# This script creates a hybrid ISO image (UDF + ISO9660/Rock Ridge/Joliet)
# using genisoimage. Although the UDF part is included, the volume label is
# subject to the ISO9660 limit (32 characters).
#
# Usage: ./create_iso.sh <source_folder> [<destination_iso_image>]
# Check for required dependencies
for cmd in genisoimage dvdisaster; do
@mofosyne
mofosyne / adc_to_mv.c
Last active February 27, 2025 15:23
These are C macro for converting between ADC to millivolt and back. Might be useful for embedded projects.
/* ADC Linear Conversion Macros
Brian Khuu 2025
ADC_MILLIVOLT_FROM_ADC_VAL(ADC_BIT_COUNT, MILLI_VOLT_REFL, MILLI_VOLT_REFH, ADC_VAL) = ( (MILLI_VOLT_REFL) + ((ADC_VAL) * (((MILLI_VOLT_REFH) - (MILLI_VOLT_REFL)) / (1 << (ADC_BIT_COUNT)))) )
ADC_VAL_FROM_MILLIVOLT(ADC_BIT_COUNT, MILLI_VOLT_REFL, MILLI_VOLT_REFH, MILLIVOLT) = ( (((MILLIVOLT) - (MILLI_VOLT_REFL)) * (1 << (ADC_BIT_COUNT))) / ((MILLI_VOLT_REFH) - (MILLI_VOLT_REFL)) )
*/
// This is the linear conversion macros
#define ADC_MILLIVOLT_FROM_ADC_VAL(ADC_BIT_COUNT, MILLI_VOLT_REFL, MILLI_VOLT_REFH, ADC_VAL) ( (MILLI_VOLT_REFL) + ((ADC_VAL) * (((MILLI_VOLT_REFH) - (MILLI_VOLT_REFL)) / (1 << (ADC_BIT_COUNT)))) )
@mofosyne
mofosyne / augmented_enum_macro_error_code.c
Last active November 16, 2024 14:25
Self Describing Error Code Enum Macro (Or other status tracking variables) V2
///usr/bin/env ccache gcc -Wall -Wextra -Werror -O3 -std=gnu17 "$0" -o /tmp/a -lm && /tmp/a "$@"; exit
#include <stdint.h>
#include <stdio.h>
/*
Self Describing Error Code Enum Macro (Or other status tracking variables) V2
Author: Brian Khuu (2024)
This is an idea I got for easier management of error codes and other enums.
The benefit of this approach is that it provides a way of having self
@mofosyne
mofosyne / self_describing_error_code_macros.c
Created November 13, 2024 13:55
Self Describing Error Code Enum Macro (Or other status tracking variables) In C
/*
Self Describing Error Code Enum Macro (Or other status tracking variables) In C
Author: Brian Khuu (2024)
This is an idea I got for easier management of error codes and other enums.
The benefit of this approach is that it provides a way of having self
documenting enumerated values which would be useful for debug loggers.
Ergo, your debug log could print the meaning of an error or status message.
*/
@mofosyne
mofosyne / bounded_and_clamped_value_macro.c
Last active November 12, 2024 11:17
Bounded And Clamped Value Macros (Useful for guarding against invalid integer ranges)
#!/usr/bin/tcc -run
// Bounded Value Macros (Useful for guarding against invalid integer ranges)
#define clamp_upper(value, max) ((value) < (max) ? (value) : (max))
#define clamp_lower(value, min) ((value) > (min) ? (value) : (min))
#define clamp_range(value, min, max) clamp_lower(min, clamp_upper(value, max))
#define is_above_bound(value, max) ((value) > (max))
#define is_below_bound(value, min) ((value) < (min))
#define is_within_bound(value, min, max) ((value) >= (min) && (value) <= (max))
@mofosyne
mofosyne / gnu_make_4.3_Implicit_Rules_And_Variables.make
Last active October 27, 2024 11:42
GNU Make 4.3 Implicit Variables And Rules `make -p 2>/dev/null | sed '/^# environment$/,/^[^#]/d'` (`2>/dev/null` to suppress error message) (sed is to remove sensitive enviromental variables)
# GNU Make 4.3
# Built for x86_64-pc-linux-gnu
# Copyright (C) 1988-2020 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
# Make data base, printed on Sun Oct 27 22:42:28 2024
# Variables
@mofosyne
mofosyne / sexp_formatter.py
Last active September 22, 2024 15:49
KiCADv8 Style Prettyfy S-Expression Formatter (sexp formatter)
#!/usr/bin/env python3
# KiCADv8 Style Prettify S-Expression Formatter (sexp formatter)
# By Brian Khuu, 2024
# This script reformats KiCad-like S-expressions to match a specific formatting style.
# Note: This script modifies formatting only; it does not perform linting or validation.
# Context: Compact element settings are added to support KiCAD-specific handling for readability, e.g., PCB_PLUGIN::formatPolyPts.
import os
import argparse
from pathlib import Path