Ext JS form load custom object

I have a custom object currentUser, it contains bank account name, mobile number,  and I want fill the form with currentUser’s properties.

 

To load a custom object,  first define a Model, then instantiate the Model with custom object, next call loadRecord with the model object. Note that I tried Ext.form.Panel loadRecord(), it’s not working for me, Ext.form.Basic should be used here. So we need call getForm() to get Ext.form.Basic

 

Another example

http://jsfiddle.net/el_chief/HBah5/4/

 

 

 

DeferredResult not working in Tomcat

The DeferredResult works on my local machine, but not work on the server machine.

On my local machine when a DeferredResult called setResult, the response will return immediately. But on remote server machine, it only return the response to client after 30s (default timeout is 30s).

According to above posts, it may be caused by earlier version tomcat 8 issue.

Then I tried jetty on remote server machine, it works. Next I checked the version by running CATALINA_BASE/bin/version.sh, it’s displaying

Server version: Apache Tomcat/8.0.14 (Debian)

And my local tomcat version is 8.0.36

 

Then I upload my local tomcat to remote server and try DeferredResult again, it works!

 

http://stackoverflow.com/questions/24619445/spring-async-deferredresult-not-working-in-tomcat-8

ExtJS Convert Query Parameter Object to URL

Assume we have a parameter object

 

To convert it to URL query, we can use following code

it will output

name=POS&min_price=10&start_date=2016-01-01

 

And to concatenate two URL part, we can use following code

It will build URL like following

http://test.com/products/export?name=POS&min_price=10&start_date=2016-01-01

 

 

 

No module named pefile

Today I want to build a python script to EXE file using PyInstaller. But after running PyInstaller, I got following error

No module named pefile

The full stack trace is

 

Starting from PyInstaller 3.2, a new module named pefile is introduced. This module is used to work with Windows binary file (EXE file, also called PE file). Before PyInstaller 3.2, PE related operation is done using its own module, like setting PE header and DOS header)

 

Solution

Assume the Python installation direcotry is C:\Python27.

Open Command Prompt window, and navigate to C:\Python27\Scripts

cd C:\Python27\Scripts

Then install pefile module using following command

pip install pefile

 

(pip is built into latest Python distribution, 2.7.12 for now)

Multiprocessing for Frozen Python

Recently I built a GUI application using PySide, and do some background calculation using multiprocessing. Using Python interpreter to run this application works smoothly. But if I freeze it to Windows executable file (exe) and run it, guess what, I got two main windows showing up!

 

After searching a while, I found following code should be added

It should be placed right after:

 

The freeze_support() is mainly used to pass initialization data from parent process to newly created process using pipe, including modules, process name, current working directory, etc. In Unix-based system this function is not needed, because fork will do these things for us (multiprocessing.Process will call os.fork() in start method on Linux)

 

the low-level implementation is in Lib/multiprocessing/forking.py and a wrapper in Lib/multiprocessing/__init__.py.

By reading the source code, we can see Python will detect –multiprocessing-fork in command line arguments to determine whether current process is child process or not. And the last command line argument is the pipe file handle. The data in main process is serialized using pickle, then pass to child process using pipe.

Shiboken Multiple Include Path on Windows

In shiboken documentation, it’s saying the separator of include path should be : (colon)

But on Windows every full path is containing colon (e.g. C:\Windows\cmd), it will mess with the colon separator.

In its source code printUsage() function I found it’s actually using a PATH_SPLITTER macro to represent the separator. And under windows it’s semicolon..

 

At past I’m using colon as separator:

–include-paths=D:\Qt\4.8.7\include\:D:\Qt\4.8.7\include\QtCore\:D:\Python27\Lib\site-packages\PySide\include\PySide

And I got lots of error messages like following:

type is specified in typesystem, but not defined

After replacing colon with semicolon, these errors are gone.

Memory Forensic for DateTime Type

In C or C++, a DateTime value is often represented by time_t type, it’s a UNIX timestamp format, which is number of seconds elapsed since 1970-1-1.  This type is defined as long (4 bytes long) on 32 bit machine, and long long (8 bytes long) on 64 bit machine.

 
And Datetime value has one important trait:

In short time the high byte won’t change.

Suppose a DateTime value is DDCCBBAA, so in memory it will be AA BB CC DD (in little endian), the highest byte (DD) won’t change in short time, and the second highest byte (CC) don’t change much. This is because the low 2 bytes can represent 65536 seconds, which is about 18 hours, that means after every 18 hours the second highest byte will only increase by 1. And the highest byte only change after 18*256 hours (nearly 192 days) passed by.

 

Next we will see how to use Python to convert bytes array to timestamp value, and display it as readable format

The data variable contains bytes needed work on, after some observing and investigation,  we think byte 4 to byte 8 is the DateTime value. Then we use struct.unpack function to convert the bytes to timestamp value, ‘<L’ means little endian and long type. Next we will convert timestamp value to human-readable format.

 

Note that time_t doesn’t contain timezone information, you need discover timezone at other places.

NSIS File command not working after calling SetOutPath

I wrote a NSIS script which copies two MSI files to $INSTDIR\Installers directory and then execute them, it’s pretty easy and following is the code

Unfortunately above code will not work and it’s saying NSIS cannot find these two msi files, but I’m sure they existed!

 
Then I tried to put $INSTDIR at beginning of the path

Now a MSI Help Dialog pops up with information about how to use msiexec command.. Apparently it failed again.

 

To solve this issue, we need call SetOutPath before ExecWait, like following

The first three lines will copy SqlLocalDB.msi and OutsideX64.msi files to $INSTDIR\Installers, and the last three lines will install MSI files at $INSTDIR\Installers.

It’s because that ExecWait (Exec, ExecShell) command will use $OUTDIR as working directory, and this path can be set by SetOutPath command (By default $OUTDIR is set to $INSTDIR).

If we don’t call SetOutPath command explicitly before ExecWait, its working directory will be $INSTDIR\Installers, and it will try to install MSI files under $INSTDIR\Installers\Installers directory, which is apparently wrong.

 

(And this guy had same problem as well http://stackoverflow.com/questions/17105455/install-sql-server-2008-r2-express-sp2-with-nsis)

Outside In Viewer Quiet Install not working

I need to install Outside In Viewer component silently in my NSIS installer. The Outside In Viewer installer is a MSI file, to install it silently, we need run following command in command line.

msiexec /i OutsideX64.msi /q

Above command will finish immediately, but it’s finished so soon that I think the installation is likely failed.

Since the command line didn’t return anything, I need enable logging to check what’s wrong with it

msiexec /i OutsideX64.msi /q /log log.txt

(Note that the log.txt file should be created in advance, otherwise an error message will show.)

In the log file we see such message

MSI (s) (C4:BC) [14:54:57:760]: Product: OutsideX64 — Error 1303. The installer has insufficient privileges to access this directory: C:\Program Files\OIX. The installation cannot continue. Log on as administrator or contact your system administrator.

By reading this log message, we know we need run this installer as administrator

 

To request Administrator privilege, add following line into our NSIS installer (at first line)

 

MinGW unable to find pkg-config

Recently I need build libewf on Windows, and MinGW is chosen as the compilation tool.

Open MSYS and run autogen.sh in libewf source directory, then following error is appeared

unable to find: pkg-config

 

I read source code of autogen.sh and realized that it’s trying to locate pkg-config at /mingw/bin directory,  Then I checked MinGW installation directory and bin folder, found there is no such pkg-config file. So we need install pkg-config manually.

 

Install pkg-config

At MinGW Wiki page it introduces two methods to install pkg-config, but using a pre-compiled version is much easier. Here is pre-compiled pkg-config download address from SourceForge. After downloading is completed, extract pkg-config.exe and move it to MinGW/bin directory, retry running autogen.sh we will found this problem is solved