Wednesday, December 4, 2019

QGIS freezes while editing features

There are many possibilities for QGIS to hang / freezes while editing features. But for my experience, I found it often hangs when using a Shapefile layer.

To minimize this kind of problem, I tried to use other feature format (e.g. SpatialLite). And the problem is relieved to some extent.



Have a try and let me know if it helps or not.

Tuesday, December 3, 2019

Windows equivalent of "wc -l" command in Linux

To count the number lines of files / stdout in Linux, we uses "wc -l" to achieve. In Windows, we use the following instead:
  • find /c /v ""

For example, suppose we have a file "sample_file.txt" and we want to know the number of lines of that file, we can perform the following:
  • type sample_file.txt | find /c /v ""



Monday, December 2, 2019

Handling table names with underscore ("_") in flask_sqlalchemy / Python

When you create table class using flask_sqlalchemy (the Flask extension for SQLAlchemy), it can maps the modal class to a proper table automatically. This is cool but if you have a table name with underscore (e.g. MY_SAMPLE_TABLE) and you name your model class with the underscore ('_') as usual, you will find SQLAlchemy will map your table name as something the following:

"MY__SAMPLE__TABLE"

Each single underscore (_) with becomes a double underscores (__). This is annoying and you might believe this is a bug, but in fact you can resolve this issues by naming your table class using the PEP8 naming convention, and named your class as:

class MySampleTable(db.Model):
     field_id = db.Column(db.Integer, primary_key = True)
     field_data = db.Column(db.String(200))

The the SQLAlchemy will map the MySampleTable class to table name as "MY_SAMPLE_TABLE" correctly.

For more information about PEP8, click here for details.

A job with mixture of joy and technology

Job with LEGO + IT, what else I can asked for ?


Thursday, November 28, 2019

Connecting Oracle with Python via cx_Oracle extension


Installation Prerequisites

  • Python 2.7, 3.5 or above
  • Oracle Client / Oracle Instant Client "Basic" or "Basic Light"
  • libaio / libaio1 package


Installation Reference



Sample Python Code

import cx_Oracle

# Make DSN address. Real values for host address, port and service name were replaced by '<>'.

dsn = cx_Oracle.makedsn('<host_address>', '<port>', service_name='<service_name>')

# Connect to DSN

orcl = cx_Oracle.connect(user='<username>', password='<password>', dsn=dsn)

# Get cursor

cursor = orcl.cursor()

# Execute SQL statement

cursor.execute('<SQL SELECT STATEMENT>')

# Fetch result

data = cursor.fetchone()

Friday, November 22, 2019

Sending F10 in Ubuntu Terminal

By default, you just can't send F10 to Ubuntu Terminal's curses program. This is because F10 is being captured by Terminal.app already.

A quick workaround is to use "ESC 0" to simulate sending F10 inside Terminal.app.

Reference

Tuesday, November 19, 2019

Customized Dash (Launcher / Taskbar) Icon in Ubuntu

To customize application icon in Ubuntu:

  1. Create a .desktop file in ~/.local/share/applications/
    e.g. /home/user/share/applications/<application name>.desktop
  2. Add the following content to the desktop file
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Name=ApplicationName
GenericName=ApplicationName
Icon=/home/user/application-icon.png
Exec=/home/user/application/application-executable
Categories=Category;Subcategory
Done!

Thursday, October 31, 2019

Wednesday, October 30, 2019

Deleting files specified in a text based file list

To delete a list of files specified in a text based file list, do the following:

> for /f %i in (files_to_delete.txt) do del %i

Reference:
https://superuser.com/questions/355584/how-to-delete-files-from-a-folder-using-a-list-of-file-names-in-windows

Export text based file list for the difference between 2 directories (Windows version)

The following is a tutorial for exporting a text-based file list showing the difference between 2 directories (e.g. D:\DirA, D:\DirB):

Step 1: Create a text-based file list for both directories

> cd D:\DirA
> dir /s /b /a:-d > file-list-dir-a.txt
> cd D:\DirB
> dir /s /b /a:-d > file-list-dir-b.txt

Step 2: Use WinMerge to get the difference between the 2 file lists:


Note: To display difference only, you need to set "View > Diff Context > 0 Lines".

Step 3: Copy the difference from WinMerge and create a text file to store it.



Upgrade nodejs in conda (from v18 to v26)

If your conda env is nodejs v18, doing a conda install nodejs=26 is likely to create a lot of conflict. Consider remove those conflicting p...