Skip to content

Instantly share code, notes, and snippets.

@ales-erjavec
ales-erjavec / numpy_openblas_config.py
Last active December 31, 2021 08:46
Inspect/config numpy-linked OpenBLAS
"""
Inspect/config numpy-linked OpenBLAS
"""
import re
import ctypes
import numpy.core
@ales-erjavec
ales-erjavec / pthread_attr_getstacksize.py
Created July 18, 2018 11:43
Get the default stack size of new pthread threads.
"""
Get the default stack size of new pthread threads
"""
import ctypes, ctypes.util
libc = ctypes.CDLL(ctypes.util.find_library("c"))
pthread_attr_getstacksize = libc.pthread_attr_getstacksize
pthread_attr_getstacksize.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_size_t)]
pthread_attr_getstacksize.restype = ctypes.c_int
@ales-erjavec
ales-erjavec / pyqt-delete-later-test.py
Created October 26, 2018 08:57
PyQt5 segfault test
from concurrent.futures import ThreadPoolExecutor
from PyQt5.QtCore import Qt, QObject, QCoreApplication
from PyQt5.QtCore import QMetaObject
class TestObject(QObject):
def event(self, event):
return super().event(event)
@ales-erjavec
ales-erjavec / mod.c
Created January 31, 2019 21:55
A modulo operator in c
#include <stdio.h>
#include <limits.h>
#include <assert.h>
int mod(int a, int b) {
int res;
if (b < 0) {
// because -INT_MIN == INT_MIN
if (b > INT_MIN) {
return -mod(-a, -b);
@ales-erjavec
ales-erjavec / graphicsstatictextitem.py
Created February 12, 2019 22:39
A QGraphicsItem displaying a QStaticText item
from typing import Optional
from PyQt5.QtCore import Qt, QPointF, QRectF
from PyQt5.QtGui import QStaticText, QFont, QPalette, QPainter, QTransform
from PyQt5.QtWidgets import QGraphicsObject, QWidget, QStyleOptionGraphicsItem
class StaticTextItem(QGraphicsObject):
"""
A text graphics object for displaying text in a QGraphicsScene.
import time
from types import SimpleNamespace
from threading import Event
from concurrent.futures.thread import ThreadPoolExecutor
from PyQt5.QtCore import (
Qt, QObject, QCoreApplication, QTimer, QEventLoop, pyqtSignal
)
from typing import Iterable
from PyQt5.QtWidgets import QListView, QLineEdit
from PyQt5.QtGui import QResizeEvent
from PyQt5.QtCore import (
Qt, QAbstractItemModel, QModelIndex, QSortFilterProxyModel, QItemSelection
)
class FilterListView(QListView):
"""
DataType
--------
A NamedTuple like class except it also defines strict type dependent
__eq__, __ne__ and __hash__. This ensures that instances can be compared,
hashed in dict, sets, ... I.e.
Example
-------
from PyQt5.QtCore import QObject, pyqtProperty
class Q_Property(pyqtProperty):
"""
A descriptor that more closely resembles the Q_PROPERTY macro.
Encourage a coding style which is consistent with Qt.
Example:
@ales-erjavec
ales-erjavec / qvariant_cast.py
Last active March 10, 2021 13:52
qvariant_cast "like" in PyQt5/PySide2
from typing import overload, Union, Type, TypeVar, Any
from functools import lru_cache
from PyQt5.QtCore import QObject, pyqtProperty as Property
@lru_cache(maxsize=200)
def _converter(type_: Union[type, str]):
class Obj(QObject):
__slots__ = ("field",)