Category Archives: Programming

Virtualenv is suddenly broken on MacOS – SSL module is not available

After a while, maybe one year after I install virtualenv on my Mac, there is an error when I run a python script in virtual environment:

Could not fetch URL ... : There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping

After researching on Google, finally I found this solution:

brew switch openssl 1.0.2j

Hope that it would work for you too.

Unsupported compiler — pybind11 requires C++11 support!

Today I tried to install dlib on my CentOS 6.7 server using this command:

pip install dlib

There is an error:

Unsupported compiler — pybind11 requires C++11 support!

To fix this issue, we need to replace the C++ compiler in /usr/bin by newer version.

So we have to install newer gcc version and replace the c++ compiler with the newer one.

Firstly, we have to install some additional required packages:

 

sudo yum install svn texinfo-tex flex zip libgcc.i686 glibc-devel.i686

Then find gcc available versions:

svn ls svn://gcc.gnu.org/svn/gcc/tags | grep gcc | grep release

I found that gcc 5.5.0 is okay to fix the error above. So I install gcc 5.5.0

svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_5_1_0_release/

Get source of additional prerequisites:

cd gcc_5_1_0_release/

./contrib/download_prerequisites

 

Building gcc could eat much memory. If your server has less than 2GB RAM, you should create swap file:

 

SWAP=/tmp/swap

dd if=/dev/zero of=$SWAP bs=1M count=500

mkswap $SWAP

sudo swapon $SWAP

Now build gcc:

 

mkdir build

cd build

../configure

make

Building gcc can take 1 hour. So we have to wait now.

After building successfully, we can install it

make install

Now the new c++ compiler is installed in /usr/local/bin/ folder. We need to replace the current c++ compiler with this newer one.

We backup the current compiler first:

 

mv /usr/bin/cc /usr/bin/cc4.4.7

mv /usr/bin/c++ /usr/bin/c++4.4.7

 

Then create symbolic link to the newer version

 

ln -s /usr/local/bin/cc /usr/bin/cc

ln -s /usr/local/bin/c++ /usr/bin/c++

 

Now I can install dlib without the error above:

pip install dlib

After installing, there is an error when importing dlib into python

ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20′ not found (required by /usr/local/lib/python2.7/site-packages/dlib/dlib.so

To fix it, we replace the lib in /usr/lib64 with the newer one that we have just built:

mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.old

ln -s /usr/local/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6

 

 

Install Gearman PHP on CentOS 6

Recently I have to install Gearman on CentOS6. It was really a painful experience.

Firstly I simply installed it via yum, as the official documentation said:

yum install gearmand

So suprising! It was installed successfully.

“We are lucky this time” I think and continue to install Gearman-php

pecl install gearman

But the error occored:

Configure: error: Please install libgearman

The solution to fix it is straight foward:

yum install libgearman-devel

Then install the PHP extension again, it would work properly:

pecl install gearman

CodeIgniter library wrapper for TinyPNG

Today I have to use TinyPNG to reduce the image size which is uploaded by users. I found the Tinify library on TinyPNG site. However, I want to create a library wrapper for it so I can easily use it in other CodeIgniter project. It just takes a little time now but it can help us save much time in the future.

I have upload to Github so that everyone can use it. You can get it here: https://github.com/nonggiatu/ci-tinypng

Happy coding 😉

Redirect loop when using Facebook login on Amazon hosted sites

When using Facebook PHP SDK to allow users loging in with their Facebook account on a website which is hosted on Amazon and accessed via HTTPS you may get an error: Your site is stuck after redirected from Facebook after authentication and redirect forever.
To fix it, just add option trustForwarded and set it to be true when construct Facebook object:

$facebook = new Facebook(
	array(
		'appId' => '123',
		'secret' => 'abc',
		'trustForwarded' => true,
	)
);