Query documents in Mongoose

// find each person with a last name matching 'Ghost'
var query = Person.findOne({ 'name.last': 'Ghost' });

// selecting the `name` and `occupation` fields
query.select('name occupation');

// execute the query at a later time
query.exec(function (err, person) {
  if (err) return handleError(err);
  // Prints "Space Ghost is a talk show host."
  console.log('%s %s is a %s.', person.name.first, person.name.last,
    person.occupation);
});

References
https://mongoosejs.com/docs/queries.html

Remove special characters from excel cell using macro

Press Alt+F11 then Insert>Module :

Function removeSpecialCharacters(sInput As String) As String

    Dim s As String, temp As String, i As Long
    Dim C As String

    s = sInput
    If s = "" Then Exit Function
    temp = ""

    For i = 1 To Len(s)
        C = Mid(s, i, 1)
        If AscW(C) > 31 And AscW(C) < 127 Then
            temp = temp & C
        End If
    Next i

    removeSpecialCharacters = temp
End Function

 

Multiprocessing in Python

# importing the multiprocessing module 
import multiprocessing 

def print_cube(num): 
  """ 
  function to print cube of given num 
  """
  print("Cube: {}".format(num * num * num)) 

def print_square(num): 
  """ 
  function to print square of given num 
  """
  print("Square: {}".format(num * num)) 

if __name__ == "__main__": 
  # creating processes 
  p1 = multiprocessing.Process(target=print_square, args=(10, )) 
  p2 = multiprocessing.Process(target=print_cube, args=(10, )) 

  # starting process 1 
  p1.start() 
  # starting process 2 
  p2.start() 

  # wait until process 1 is finished 
  p1.join() 
  # wait until process 2 is finished 
  p2.join() 

  # both processes finished 
  print("Done!") 

References
https://www.geeksforgeeks.org/multiprocessing-python-set-1/

Connect clicked event of Button in PySide

import sys
import os

from PySide2.QtWidgets import QApplication, QWidget, QPushButton
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader


class main(QWidget):
    def __init__(self):
        super(main, self).__init__()
        self.load_ui()

    def load_ui(self):
        loader = QUiLoader()
        path = os.path.join(os.path.dirname(__file__), "form.ui")
        ui_file = QFile(path)
        ui_file.open(QFile.ReadOnly)
        self.window:QWidget = loader.load(ui_file, self)
        ui_file.close()

        # pushButton is the name of button control
        self.pushButton:QPushButton = self.window.findChild(QPushButton,"pushButton")
        self.pushButton.clicked.connect(self.clicked)

    def clicked(self):
        print("Hello")


if __name__ == "__main__":
    app = QApplication([])
    widget = main()
    widget.show()
    sys.exit(app.exec_())

References
https://www.blog.pythonlibrary.org/2018/05/30/loading-ui-files-in-qt-for-python/

Load ui file in PySide2

import sys
import os


from PySide2.QtWidgets import QApplication, QWidget
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader


class main(QWidget):
    def __init__(self):
        super(main, self).__init__()
        self.load_ui()

    def load_ui(self):
        loader = QUiLoader()
        path = os.path.join(os.path.dirname(__file__), "form.ui")
        ui_file = QFile(path)
        ui_file.open(QFile.ReadOnly)
        loader.load(ui_file, self)
        ui_file.close()

if __name__ == "__main__":
    app = QApplication([])
    widget = main()
    widget.show()
    sys.exit(app.exec_())