This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Tail call 'optimization' | |
------------------------ | |
A simple tail call 'optimization' implemented by a trampoline. | |
Usage | |
----- | |
Use the `tailrec` decorator on the function, and change the tail recursive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
FreeViz | |
------- | |
Compute a lower dimensional linear projection to optimize separation | |
between classes. | |
""" | |
import numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Thread safer backcompatibility layer for `subprocess` | |
""" | |
from __future__ import absolute_import, print_function | |
import os | |
import sys | |
import threading | |
import atexit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
function print_usage { | |
echo 'pyqt-convert.sh INSTALLER | |
Convert a PyQt4/PyQt5 windows installer into a wheel package. | |
note: 7z executable must be on PATH. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A QSignalSpy like object, which is sadly missing from PyQt4 (but is exposed in PyQt5) | |
No guaranties it behaves as the real thing under all circumstances. | |
""" | |
from PyQt4.QtCore import QObject, QEventLoop, QTimer | |
class QSignalSpy(QObject): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import weakref | |
from types import SimpleNamespace as namespace | |
from PyQt4.QtCore import QObject | |
class qobjref(object): | |
""" | |
A 'guarded reference' to a QObject. | |
An instance of a `qobjref` holds a reference to a `QObject` for as long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
OlderNewer