Skip to content

Instantly share code, notes, and snippets.

View mdmitry1's full-sized avatar
:atom:
🦁

Dmitry Messerman mdmitry1

:atom:
🦁
View GitHub Profile
@mdmitry1
mdmitry1 / Makefile
Last active February 4, 2025 20:15
Disjoint set
MODULE=disjoint_set_c
VER=13
EXT=cpython-3$(VER)-$(HOSTTYPE)-gnu.so
SO=$(MODULE).$(EXT)
%.$(EXT): %_setup.py %.pyx
python3.$(VER) $< build_ext -i
strip $@
-rm -rf build
all: $(SO)
clean:
#!/usr/bin/python3.13
'''
https://www.pythonguis.com/tutorials/qtableview-modelviews-numpy-pandas/
'''
from sys import argv, exit
from rich import print as rprint
import warnings
warnings.filterwarnings("ignore",category=UserWarning)
from pandas import read_csv
from os import name as osname, popen
@mdmitry1
mdmitry1 / Makefile
Last active February 8, 2025 19:29
Prime numbers calculation in C++, Cython an Python
MODULE=primes_cython
VER=13
EXT=cpython-3$(VER)-$(HOSTTYPE)-gnu.so
SO=$(MODULE).$(EXT)
%: %.cpp
g++ -O2 -o $@ $<
strip $@
%.$(EXT): %_setup.py %.pyx
python3.$(VER) $< build_ext -i
strip $@
#!/usr/bin/python3.13
'''
https://octave.sourceforge.io/octave/function/sombrero.html
'''
import warnings
warnings.filterwarnings("ignore")
from numpy import sin, sqrt, linspace,finfo, transpose
from re import search
from sys import version as python_version
#Workaround for matplotlib bug
#!/usr/bin/python3.13
'''
https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
https://www.codequoi.com/en/coloring-terminal-text-tput-and-ansi-escape-sequences
https://web.archive.org/web/20210226122732/http://ascii-table.com/ansi-escape-sequences.php
'''
from sys import argv
from argparse import ArgumentParser
def print_color(fg_bg_code, color):
#!/usr/bin/python3.13
import sys
from os.path import realpath, basename
from rich import print as rprint
import warnings
warnings.filterwarnings("ignore",category=UserWarning)
import pandas as pd
import argparse
script_name = basename(realpath(sys.argv[0]))
parser = argparse.ArgumentParser()
@mdmitry1
mdmitry1 / EilatBay.jpg
Last active December 27, 2024 11:42
Platform Independent Qt GUI example
EilatBay.jpg
@mdmitry1
mdmitry1 / match_ex.py
Last active December 27, 2024 11:54
Structural Pattern Matching example
#!/usr/bin/tcsh -f
"/usr/bin/true" '''\'
if(1 == `uname | grep ^MINGW | wc -l`) then
exec python3.10 $0
else
exec python3.13 $0
endif
'''
# https://realpython.com/python310-new-features/
from datetime import datetime
@mdmitry1
mdmitry1 / decorator_callback_ex.py
Last active December 27, 2024 11:45
Decorator with parameters and color output
#!/usr/bin/python3.13
from os import environ
from sys import argv
def sortDecorator(x):
def decorator(func):
def wrapper(*args, **kwargs): return func(*args, **kwargs)
return wrapper
return decorator
@mdmitry1
mdmitry1 / get_window_geometry
Last active January 3, 2025 14:29
Python Tkinter window running Tcl script
#!/usr/bin/tcsh -f
set w=`xdotool getwindowfocus`
set g=`xdotool getwindowgeometry $w | grep : \
| sort | awk '{print $2}' | tr '\012' ' ' | sed -e 's/ /+/' -e 's/,/+/' -e 's/$//'`
echo $g