Skip to content

Instantly share code, notes, and snippets.

View michalmonday's full-sized avatar

Michal Borowski michalmonday

  • Colchester, UK
View GitHub Profile
@michalmonday
michalmonday / union_find.py
Last active March 18, 2022 12:39
Detect cycle in an undirected graph (python)
#python3
# It's simpler version of the example posted at:
# https://www.geeksforgeeks.org/union-find/
class Graph:
edges = set()
def add_edge(self, src, dst):
'''Each edge has 2 vertices: source and destination.'''
@michalmonday
michalmonday / marks.py
Last active May 30, 2021 16:28
Python3 program which calculates final mark based on previous and potential future marks.
# Python3 program which calculates final mark based on previous and potential future marks.
# How to use this program:
# - modify "previous_marks" list (line 18)
# - run the program
# If the program fails to run because of missing libraries, you can run the following command:
# python3 -m pip install matplotlib tk numpy
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
@michalmonday
michalmonday / hmm.py
Last active February 9, 2022 19:02
Hidden Markov model simple example
##from nltk.corpus import brown
##
###tw = brown.tagged_words(tagset='universal')
##tw = brown.tagged_words()
##
##vbz = [t for t in tw if t[1] == "VBZ"]
##print('Total number of VBZ tokens:', len(vbz))
##
##is_ = [t for t in tw if t[0] == "is"]
##print('Total number of "is" words:', len(is_))
@michalmonday
michalmonday / list_largest_files.sh
Created July 1, 2022 14:14
Simple but super useful for cleaning space bash script to list largest files.
if [ $# -eq 0 ]; then
PATH_DU="."
else
PATH_DU="$1"
fi
sudo du -ah --max-depth=1 $PATH_DU | sort -rh | head -n 30
@michalmonday
michalmonday / new_instruction.py
Created July 12, 2022 13:00
Build 32-bit hex value of a custom RISC-V R-type instruction.
import re
def reg_index(reg_name):
return [
'zero', # always zero (x0)
'ra', # return address
'sp', # stack pointer
'gp', # global pointer
'tp', # thread pointer
't0',
@michalmonday
michalmonday / copy_to_pynq.py
Created July 30, 2022 22:21
Copies .bit and .hwh files from Vivado output directories to pynq.
#!py -3
'''
After using Vivado block design, creating a HDL wrapper for it,
and generating bitstream, this script can be used to move the
"_wrapper.bit" and ".hwh" files to pynq.
Tested on Windows only.
'''
import shutil
@michalmonday
michalmonday / dma_receiver.py
Last active August 6, 2022 11:11
Efficient (hopefully) pynq dma receiver with multiple buffers that allows to get the data as a list.
''' Example usage with dma.sendchannel supplying the data:
import os, subprocess, sys, re, time
from pathlib import Path
from pynq import Overlay
from pynq import allocate
from threading import Thread
from dma_receiver import DmaReceiver
#!/usr/bin/python3
'''
This script can be replaced by simply using:
python3 -m serial.tools.list_ports -v
'''
import serial # pip install pyserial
import serial.tools.list_ports as list_ports
@michalmonday
michalmonday / fix.cpp
Last active November 25, 2022 17:13
Extension board LEDs wiring fix
#include "mbed.h"
// mosi, miso (unused really), sclk
SPI sw(p5, p6, p7);
// lat (latch) pin of TLC59281 as shown in extension board schematic
DigitalOut lat(p8);
/* The extension board wiring from TLC59281 to 3 LEDs pairs are not consistent with
remaining 5 LEDs pairs (green is wired as red, red is wired as green).
@michalmonday
michalmonday / keys.cpp
Created November 25, 2022 17:54
Mbed extension board alternative keypad reading.
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
BusOut cols_out(p26, p25, p24);
// Checking extension board with multimeter shows that p14,p13,p12,p11 are connected
// to row indicating pins of the keypad. The extension board schematic is incorrect.
BusIn rows_in(p14, p13, p12, p11);