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 / 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 / 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 / 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 / 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 / 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.'''