Skip to content

Instantly share code, notes, and snippets.

#include "mbed.h"
Serial serial(USBTX, USBRX);
DigitalOut led(LED1);
//void onReceive() {
// char c = serial.getc();
// led = !led;
// serial.putc(c+1);
//}
@michalmonday
michalmonday / python_speed_check.md
Last active January 24, 2023 11:08
A command to profile a python script
# py -3 -m pip install snakeviz

# on Windows:
py -3 -m cProfile -o my_script.profile my_script.py && snakeviz.exe my_script.profile
@michalmonday
michalmonday / pyqt6_workflow.md
Created January 24, 2023 11:06
How to create and use Qt Designer or Qt Creator to create a GUI for python.
  • Create "ui" file in Qt Designer or Qt Creator.
  • Run update_MainWindow.py which runs pyuic6 -o my_file.py <file>.ui and moves imports from the bottom to the top of the file, because promoted classes happen to be imported at the bottom for some reason which was causing an error.
  • See files in this folder (e.g. file_loader.py) to see how to create/connect signals and slots.
@michalmonday
michalmonday / float_to_concise_str.py
Created February 6, 2023 14:16
Neat rounding function.
import numpy as np
def float_to_concise_str(f):
''' turns 0.0012345678 into 0.0012 '''
f = float(f)
if len(str(f).split('.')[1]) < 2 or f >= 1.0:
return str(round(f, 2))
return np.format_float_positional( float(f'{f:.2}'), trim='-')
@michalmonday
michalmonday / copy_bsp.py
Last active October 28, 2024 15:13
Script that copies BSP and Utilities from ST repository to STM32F412G-Disovery project
'''
Usage: py -3 copy_bsp.py project_name
This script copies BSP files and Utilities to specified project.
This script should be placed in the workspace folder of STM32CubeIDE.
In the same directory where project folders are created.
REPOSITORY_PATH must be manually modified in this script in order to work.
Whenever "Project -> Generate Code" option is used, the Utilities folder