Skip to content

Instantly share code, notes, and snippets.

@asdf8601
asdf8601 / py2mermaid.py
Last active July 2, 2024 14:59
[mermaid] classDiagram builder from python code
r"""
This requires to have the library (pkg) pre-installed.
Usage:
$ python ./py2mermaid.py --pkg pandas
$ python ./py2mermaid.py --pkg pandas --base-module pandas.core
$ python ./docs/diagrams/py2mermaid.py --pkg pandas --base-module pandas.core
$ python ./docs/diagrams/py2mermaid.py --pkg pandas --base-module pandas.core --raw | sed "s/\w\.\(\w\)/\U\1/g"
Note: based on https://gist.github.com/Zulko/e0910cac1b27bcc3a1e6585eaee60121
@m3nu
m3nu / simpletreemodel.py
Last active October 10, 2024 01:23
QTreeView with Custom QAbstractItemModel and Lazy Loading
"""
This is an adjusted version of the official simpletreemodel[1] that adds lazy loading and uses a dict as backend.
Instead of the dict it could also use a database or similar. Items are only loaded when expanded, which allows
for speedy startup-time, even with 2.5m items.
1: https://github.com/baoboa/pyqt5/tree/master/examples/itemviews/simpletreemodel
"""
import sys
@chipolux
chipolux / embedded_window.py
Created August 22, 2017 23:27
Embedding A Window In A Widget (PyQt5 and python-xlib)
def get_window_id(name):
import Xlib.display
d = Xlib.display.Display()
r = d.screen().root
window_ids = r.get_full_property(
d.intern_atom('_NET_CLIENT_LIST'), Xlib.X.AnyPropertyType
).value
@jackdoerner
jackdoerner / dpx.py
Last active April 16, 2025 08:36
Read Metadata and Image data from 10-bit DPX files in Python 3
"""
dpx.py
Read Metadata and Image data from 10-bit DPX files in Python 3
Copyright (c) 2016 Jack Doerner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@wmayner
wmayner / lru_cache.py
Created May 5, 2014 20:58
[Python] Memory-aware LRU cache decorator
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Memory-aware LRU Cache function decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A modification of the builtin ``functools.lru_cache`` decorator that takes an
additional keyword argument, ``use_memory_up_to``. The cache is considered full
if there are fewer than ``use_memory_up_to`` bytes of memory available.
@maty974
maty974 / setNukeZeroMarginsWidget.py
Last active March 14, 2024 09:09
The Foundry Nuke hack works with "nukescripts.panels.registerWidgetAsPanel", to remove the disturbing widget contents margins set by Nuke.
'''
Created on Feb 8, 2013
@author: matthieuc
@contact: [email protected]
'''
import PySide.QtGui as QtGui
def setNukeZeroMarginsWidget(widget_object):