Tricks and tips

How to use PyQt5 with QML and Python 3?

pip3 install PyQt5
from PyQt5.QtCore import QUrl, QObject, QMetaObject,Qt,pyqtSlot, QThread,pyqtSignal
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView
appObject = QApplication(sys.argv)
appView = QQuickView()
appView.setSource(QUrl("main.qml"))
appView.show()
root = appView.rootObject().findChild(object, "root") #supply the name of the root element. Literally `name` attribute. IDs do not work with python 
root.anySignalName.connect(lambda: print("Signal was triggered"))
            

How to style Angular Material?

You cannot override styles that are written in a web component. To hack it, use `/deep/` (deprecated!) or `>>>` (also deprecated)
    body /deep/ mat-card{
        background-color:pink;
        border-radius:0px;
    }
Check in dev tools for individual selectors of different components. Works in webkit as of september 2018.

What to do, when pickle.dumps gives a recursion error?

Serialize a dictionary instead: pickle.dumps(vars(object))

How to generate random ID in python

        def random_hash():
            return binascii.hexlify(os.urandom(32)).decode('utf-8')
    

How to find element by its CSS selectors in beautifulsoup?

elem = soup.select("#example")[0]

How to disable WiFi on ESP8266?

#include WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); delay(1000);

Awful oneliners

[()=>{}, ()=>{}][Number(boolean_value)]()
       
instead of
if (boolean_value){
    
}else{
}
       
or
{true:()=>{}, false:()=>{}}[boolean_value]()
       

How to use OpenCl ran on GPU with CUDA toolkit on windows with visual studio?