Install Python 2.7 for CentOS 6

CentOS 6 uses Python 2.6 by default.

The following is how I install Python 2.7 and Django with official packages.

$ yum install python27 python27-devel python27-setuptools

$ yum install libffi-devel openssl-devel

$ pip2.7 install requests[security]

$ pip2.7 install uwsgi virtualenv virtualenvwrapper Django MySQL-python

Then uwsgi will use python2.7 automatically.

Advertisements

Notes on Android Multiple Threads

Service, IntentService, HandlerThread / Thread, AsyncTask.

Which one to use? What should be noticed?

Here is a comparison:
Notice parallel problem on various Android versions for AsyncTask:
Lifecycle of Threads should be considered carefully.
Threads are still running even if main thread has called finish().
Application components running in the process that’s killed are consequently destroyed. (http://developer.android.com/guide/components/processes-and-threads.html)

Install Qwt for Multiple Qt SDKs on Windows

I’ve installed Qt-4.8.6-MinGW and Qt-5.3.1-MSVC2013_64 together, because I’m going to build my application both 32bit (MinGW) and 64bit (MSVC2013). So I have to build Qwt for both Qt SDKs. What’s more, I’m using the only one QtCreator installed by Qt-5.3.1-MSVC2013_64, which has to support both SDKs with the same source code.

1. Build and Install Qwt Plugin for QtCreator
As said in Qwt User’s guide, QtCreator is “a different version of the Qt libraries you want to build your application with”, QtCreator supplied by Qt5 installed is built with MSVC2010 32bit (QtCreator –> Help –> About Qt Creator).
a) Build Qwt with MSVC2010 x86 Qt5 SDK (NOTICE: same version as QtCreator) first, and get plugin for QtCreator.
Just build following the user’s guide: update qwtconfig.pri, qmake qwt.pro, nmake, and nmake install.
b) Install plugin
Copy $QWT_INSTALL_PREFIX\plugins\designer\qwt_designer_plugin.dll to X:\Qt\Qt5.3.1\5.3\Tools\QtCreator\bin\plugins\designer\

2. Install Qwt Documentation
Open QtCreator, Tools –> Options –> Help –> Documentation –> Add
Select qwt-6.1.0.qch file downloaded from Qwt site

3. Build and Install Qwt Headers/Libraries for Qt SDKs
a) Build and Install Qwt with MSVC2013 x64 Qt5 SDK
     Build and install as the user’s guide, and then copy features/* (qwt.prf, qwtconfig.pri and qwtfunctions.pri) to X:\Qt\4.8.6_mingw482\mkspecs\features\win32\
b) Build and Install Qwt with MinGW x86 Qt4 SDK
     Build and install as the user’s guide, and then copy features/* (qwt.prf, qwtconfig.pri and qwtfunctions.pri) to D:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\mkspecs\features\win32\

4. Test
Copy qwt-6.1.0\examples\simpleplot.cpp to a test directory, let’s use “X:\simpleplot\”.
Create X:\simpleplot\simpleplot.pro with the following contents:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG   += qwt
TARGET    = simpleplot
TEMPLATE  = app
SOURCES   =  simpleplot.cpp

Open project with QtCreator (you can see Qwt in UI designer now)

If you built Qwt with shared library (*.dll), maybe you should copy qwt.dll to the folder your exe exists.

[Reference]
http://qwt.sourceforge.net/qwtinstall.html
http://qt-project.org/doc/qt-4.8/qmake-advanced-usage.html#adding-new-configuration-features

Update password for Busybox system

On SMP865x board, passowrd is managed with “/etc/shadow” file by Busybox (crypt(3), MD5).

Here is how to update the password (On Debian only, Slackware doesn’t support it):

mkpasswd -5 -s 'YourPassWord'

Then use the output update /etc/shadow file.

And here is a python command for the same purpose too (Python 2.x. If using Python 3.x, replace print to print()):

python -c 'import crypt; print crypt.crypt("YOURPASS", "$1$YOURSALT")'

From http://serverfault.com/questions/330069/how-to-create-an-sha-512-hashed-password-for-shadow , we can change it for more purpose.

6 is the type of hash for SHA-512

  • 1 -> MD5
  • 2a -> Blowfish (not in mainline glibc; added in some Linux distributions)
  • 5 -> SHA-256 (since glibc 2.7)
  • 6 -> SHA-512 (since glibc 2.7)

I’d recommend you look up what salts are and such and as per smallclamgers comment the difference between encryption and hashing.

Update: The string produced is suitable for shadow and kickstart scripts.

To use the python script on Slackware automatically, I use mkpasswd to generate random salt (Only Slackware supported. It doesn’t work on Debian):

python -c 'import crypt; import os; print crypt.crypt("YOURPASS", "$1$" + os.popen("mkpasswd").read())'

I did not found a way working on every OS. —- It seems that I should learn more about crypt.