Posts

Setup autostart services in Linux with SELinux

1) Create your start / stop script in a predefined directory (e.g. /development/service-script/ ) /development/service-script/start-cmd /development/service-script/stop-cmd 2) Allow SELinux to execute binaries in the predefined directory /development/service-script/  (!! important for SELinux)      chcon -R -t bin_t /development/service-script/ 3) Create abc.service in /etc/systemd/system/      # Systemd unit file for ABC service      [Unit]        Description=ABC service      After=syslog.target network.target      [Service]      Type=forking      ExecStart=/development/service-script/start-cmd      ExecStop=/development/service-script/stop-cmd      User=service_owner      Group= service_owner      UMask=0007      RestartSec=10      Restart=always      [...

NO_PUBKEY when updating QGIS in Linux / Ubuntu (2022)

Update the key file (qgis-archive.gpg) by: wget  -qO  -  https://qgis.org/downloads/qgis-2022.gpg.key  |  gpg  --no-default-keyring  --keyring  gnupg-ring:/etc/apt/trusted.gpg.d/qgis-archive.gpg  --import The NO_PUBKEY error message will be gone for 'apt update'

Separated dock for multiple workspace in Ubuntu

Separated dock for multiple workspace in Ubuntu, set the following to be true: gsettings set org.gnome.shell.extensions.dash-to-dock isolate-workspaces true

Skip basic authentication headers before passing a request to proxypass target host

This can be done via "RequestHeader unset Authorization"  <Location "/some_path">     Require all granted     ProxyPass https://target-host     RequestHeader unset Authorization </Location> Reference: 1 , 2

Ubuntu deactivate shift+numpad = number

 setxkbmap -option 'numpad:microsoft' Reference: codegrepper.com  

Extract PDF content (from CHP) with Python

import re import sys import urllib.request import pdfplumber import pandas as pd if (len(sys.argv) < 2):     print("\n\nSyntax: python extract_pdf.py date_string (e.g. 20220124) \n\n")     exit() def main():         date_string  = sys.argv[1] # e.g. 20220124     pdf_file_name = f"ctn_{date_string}.pdf" # PDF from CHP: https://www.chp.gov.hk/files/pdf/ctn_20220124.pdf     #download_pdf( pdf_file_name )     extract_pdf( pdf_file_name ) def extract_pdf( pdf_file_name ):     with pdfplumber.open( f"./pdf/{pdf_file_name}" ) as pdf:         for page in pdf.pages:             #print(page)             for table in page.extract_tables():                 df = pd.DataFrame(table[1:], columns=table[0])                 for index, row in df.iterrows():...

Display cx_oracle error indicating which rows are affected

cursor.executemany("SQL EXEC STATEMENT", data, batcherrors=True ) for error in cursor.getbatcherrors() :     print("Error", error.message, "at row offset", error.offset)