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

 

 

How to remove Gitlab banned IP

Recently I have a problem with Gitlab: My colleague had mistakenly typed wrong password multiple times on Gitlab login and all of us cannot access Gitlab because of IP ban.

It take a while for me to find out how to remove the banned IP on Gitlab. So I write it here for anyone can save their time:

Firstly, open redis client:

sudo /opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.socket

List the item with key contains “rack”:

redis /var/opt/gitlab/redis/redis.socket> KEYS *rack*

The result may like this:

1) cache:gitlab:rack::attack:allow2ban:ban:1.2.3.4

You can remove the ban using DEL command:

redis /var/opt/gitlab/redis/redis.socket> DEL “cache:gitlab:rack::attack:allow2ban:ban:1.2.3.4”

 

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

Tư vấn 1

Mình có thằng em họ tên X đang học cao đẳng ở Hà Nội. Một hôm thấy mẹ nó gọi điện giọng khẩn thiết:

– Cháu ơi, thằng X nhà bác đang yêu con Y nào ấy. Cháu bảo nó giúp bác với: Bảo nó tập trung học hành đi đừng có yêu đương linh tinh. Bác nói nó chẳng chịu nghe.

– Ơ cháu thấy thằng X bình thường ở nhà cũng có chịu học hành quái đâu, suốt ngày đi chơi điện tử?

– Ừ thế nên bác mới nhờ cháu …

– Thế thì cháu nói thật, bác có ngăn nó yêu thì cũng bằng thừa vì không yêu đương gì thì nó cũng có chịu học đâu. Chi bằng giờ bác liên hệ với con Y, bảo nó nếu thương thằng X thì cố mà bảo ban nó học hành, không sau nó vô công rồi nghề ăn bám mày thì ráng chịu.

– Ờ hay! Mày nói có lý, để bác triển khai luôn!

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,
	)
);