Category Archives: Python

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. https://github.com/variable/django-rest-framework-queryset 

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

 

Writing static typed style code in dynamic type language

I am not sure who else is doing this but I have a static typed language background and I tend to write code in static type style. Don’t assign different value types to the same variable Let’s see what dynamic type in the simplest form in Python:

While this is perfectly legitimate, but it’s… Read More »

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 »

What’s wrong with this statement?

This morning I made a code change to log some stuff in a core package and created a pull request, the change was very simple: from

to

One of the team lead pointed out the statement has a problem, and it was a life saver, but I won’t tell you why just yet,… 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/2.4.7.1/lib/python2.7/site-packages/ download the xml file https://warai.googlecode.com/files/haarcascade_frontalface_alt.xml 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