Category Archives: Python

Minimal Django script setup

Notes about python logging

Consider the following code

Executing above: It won’t log anything to console, because it default to level warning It won’t log anything to console, because no stream has been set

Executing above: Running basicConfig(…) default adds the stream to stderr (unless specified explicitly) to root logger It sets the root logger level to… Read More »

Django Rest Framework QuerySet

I have just created this python library so that you can query the remote api just like the Django queryset. It is particularly usefully when used in Django ListView with pagination. 

Posting image to thumbor using requests package

Seems like there are not many code sample there, and the requests documentation was giving the wrong hint to use files={‘file’: open(‘image.jpg’)} which you will end up getting 415 response code. I think I will just share my working sample code here to save someone’s time


PHP developers should try Python.

PHP and Python both are dynamic typed language, so there is no point the discuss anything related in this aspect. Exception is first class citizen

Prints ‘Caught’ Let’s look at PHP:

Better functions Imagine you can write functions like this

Short-lived vs Long-lived Almost all PHP scripts are short-lived, including most frameworks, which… Read More »

Python OpenCV Facial Detection On OSX

Just a code snippet to demo Python script using OpenCV

Installation: pip install numpy (sometimes you might need to run as sudo) brew tap homebrew/science brew install opencv export PYTHONPATH=/usr/local/Cellar/opencv/ download the xml file and place it in the same folder.

Django CMS Haystack 2.0 Search Index

Currently django-cms-search doesn’t support haystack 2.0 yet, so here is my modified version to work on haystack 2.0 based on