mod_wsgi and mod_xsendfile on OS X 10.9 Mavericks

Updated on Nov 4, 2013: The following tricks may still work, however I have found a much easier solution. Simply install Xcode command line developer tools and you should be able to compile source code without issues:

After upgrading my Mac from 10.8 to 10.9 Mavericks my apache stopped working, so I have to reinstall mod_wsgi and mod_xsendfile. However, tricks are needed to compile and install these mods successfully.

Upgrade Xcode

Upgrade Xcode in App Store. As mentioned by Valerie:

I had to manually upgrade Xcode (after Mavericks upgrade) from the App Store & agree to its license because ./configure hung forever until I did that.


For mod_wsgi installation, create a soft link to OSX10.9.xctoolchain:

Then run configure under mod_wsgi source code directory:

It will generate a Makefile similar as follows:

However, this Makefile is not correct and running ‘make’ the compiler will complain something like:

Prepend the following line to CPPFLAGS value:

Save the Makefile and it will look something like:

Then make && install:

Modify /etc/apache2/httpd.conf to enable mod_wsgi:


Use the following command to compile and install mod_xsendfile:

Enabling HTTPS/SSL

After upgrading OS X the apache configuration was reset, but your original config is save to /etc/apache2/httpd.conf.pre-update. I need to enable SSL in httpd.conf again by uncommenting the following line:

Restart Apache and everything should work fine

Solution: dd too slow on Mac OS X

When I was cloning SD cards on Mac OS X using dd', it takes ages to get things done. I was using the following command:

It takes much less time when using /dev/rdisk2 instead of /dev/disk2:

The reason is that rdisks are "raw" thus resulting in a higher R/W speed, according to man hdiutil` [1]:

/dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code.


Facebook vs. Google advertisements

Since last week I’ve been investigating how to efficiently promote our website ( Our Facebook page got 139 likes a week ago, and now we have 175. Among the 36 new likes, 22 are from two Facebook campaigns. The first campaign cost 15 dollars and earned 20 likes, averaging 0.75 dollars per like with a click-through rate of 0.290%. In a way this is affordable and more efficiently than stand at international students’ dormitory in Shanghai and spread flyers. Three of us probably sent out around 100 flyers to international students but got nothing to our Facebook page nor website. The first campaign focused on gaining new likes and it went quite well; our second campaign cost 5 dollars, promoting a video post with a goal to earn new likes. This campaign boosted another 2,169 reach, 143 clicks and 2 new likes. Had the video been more engaging, probably we could have gotten more clicks, shares and likes. Since Facebook users nowadays are exposed more and more to various contents, it’s become increasingly difficult to get users engaged.

In the meanwhile, we also launched three campaigns on Google Adwords. So far we got 30 clicks and cost about 40 dollars. The average CPC is $1.36 — almost twice of that for FB, but the conversion rate is zero. No one has applied or enquired our pages (maybe due to the low volume). Google Adwords is different from Facebook. On Facebook you attract people to your FB page but not your website; whereas Google takes visitors directly to your website. FB leaves you a space for imagination, though. Once you get a page like from someone, he/she will be able to see the updates your page posts.

Suppose the Google CPC is twice of Facebook CPC, if one in two earned FB followers click one of our promoted posts, FB is doing better. That does not sound like a issue. I’d place all my bet on Facebook and maybe time to buy FB shares?

We also tried to promote on LinkedIn but failed to find appropriate ways. LinkedIn is mainly for serious jobs, not internships. Instagram neither, there seems to be a lot of robots on Instagram; it’s not clear for us to find a way to promote ourselves, either. So for the moment, we only consider Facebook and Google. Oh no, Facebook is our focus and Google is not helping much, but we still need to spend the remaining 90 dollars we got from a coupon, slowly.

A “normal” sed on Mac

The sed program on Mac is not a standard (GNU) one. To get the normal one, use brew:

After this, alter PATH. For example, add the following line to your ~/.bash_profile:

And now you have a normal sed!


A faster key repeat rate for Mac OS X

The fastest one can get via System Preferences is 2. You can set it to either 0 or 1, depending on your preferences.

To check your current repeat rate, issue the following command in Terminal:


Tastypie error handling with Unauthorized Exception

In Tastypie v0.9.15 unauthorized exception messages are not included in the response. The cause lies in the following code: (tastypie/, Line 601-602 in v0.9.15)

In the above snippet an empty response is returned, without including messages in exception.

In order to fix this, you can override this method in your model resources, for example:

Hi, the company I’m working for ( is hiring Website Backend and Frontend Developers to our platform team. We are building an open platform for youngsters to travel beyond boarders and we offer youngsters internship, language study, travel and volunteer opportunities. Please contact me if you are interested.

Upgrading Tastypie from v0.9.11 to v0.9.12 and above

Here are my notes on how to upgrade Tastypie from version 0.9.11 to 0.9.12, as there’re no release notes for v0.9.12. Release notes for 0.9.13 and above are available here:

1. override_urls() becomes prepend_urls(), the new name makes more sense since what the function does is to insert customized urls instead of replacing the default urls with your customized urls.

2. obj_* methods accepts different parameters. Before:

Now obj_get, obj_create, etc. accepts bundle as the parameter apart from keyword arguments. You can get request object from the bundle:

3. apply_authorization_limits is no longer in use and it’s replace with a finer grained authorization mechanism. For example:

Please note that *_list methods should return a list or raise exceptions; whereas *_detail methods should return boolean values or raise exceptions. For more information, see:

Hi, the company I’m working for ( is hiring Website Backend and Frontend Developers to our platform team. We are building an open platform for youngsters to travel beyond boarders and we offer youngsters internship, language study, travel and volunteer opportunities. Please contact me if you are interested.

OpenVPN client TLS-Auth problem on Windows

It seems that the OpenVPN Client on windows does not support TLS-Auth with a separate key file. So instead, you can paste your key contents in your openvpn client’s config file and use some thing like the following (inline ta.key):

When not using the above but using something like:

The server log shows something like:

funf smart phone data collecting


battery_life phone_temperature relative_activity screen_activity


老实说,收集了两天的数据,就能分析出这么点东西,着实让人失望。不过这个生成图像信息的程序是开源的,而且是用Python实现的,今后有空了也可以自己来分析一下收集到的数据。funf在我的手机上也经常不能响应,可以说这个app是十足的半成品。不过这个由来自MIT的团队开发的不仅仅是一个手机app,号称是一个Open Sensing Framework,前几天还刚刚被Google收购了。虽然是个半成品,但Google这个时候收购团队总比让他们羽翼丰满之后再收购所花的代价要小得多。

Installing mod_xsendfile on OS X Lion

First download mod_xsendfile.c from

Then compile and install it:

Add the following line to /etc/apache2/httpd.conf at the end of the first block of “Load” statements:

At last, restart the apache server

Hi, the company I’m working for ( is hiring Website Backend and Frontend Developers to our platform team. We are building an open platform for youngsters to travel beyond boarders and we offer youngsters internship, language study, travel and volunteer opportunities. Please contact me if you are interested.

XBMC and OS X firewall permission popups

I installed XBMC on my Mac OS X Lion and every time I open up the program, a firewall permission dialog pops up. It didn’t help even if I added the XBMC in my firewall configurations. Popups still show up. This link solves the problem neatly — You can generate a certificate and sign the program by yourself. After that the frustrating dialog should appear only once (at most). In case the link becomes invalid, here’s a screenshot of the instructions. Click to see the large picture.

Block unauthorized ssh login attempts (attacks)

My friends and I am working on a hobby project and  we need a Git server, so I set up one on my MacBook Pro. We access the repository via SSH. However when I checked the ssh log I found someone trying to get ssh access to my machine by guessing usernames. The log looks as follows:

I first tried to use DenyHosts, however, there are still attempts from other IP addresses. Since there are three of us accessing the repository, I configured the hosts.allow and hosts.deny manually: deny all hosts other than the IP addresses I trust.



Now the log file should be quite…

Migrating JComments to WordPress

I switched back to WordPress from Joomla! after I registered this new domain. After migrated all the posts to WordPress using FG Joomla to WordPress, I noticed the comments have not been transferred. After some digging I didn’t find satisfactory plugin to do that, so I wrote my own PHP script to fulfill this task. The code is also available from GitHub.

Downgrade Preview in OS X Lion

I’ve had enough with the slow Preview application in Lion. After some digging I found this tutorial to downgrade the Preview in Lion to the Snow Leopard version. Basically you need to have a copy of both the and /System/Library/PrivateFrameworks/MeshKit.framework from Snow Leopard. If you need to associate the default app to open pdf/png with the downgraded Preview, you have to delete the original

Update: after installing OS X updates you need to remove the again and put the SL to /Applications/ directory.

C a[i] vs i[a]

When following the MIT 6.828 open course, there’s one C source code discussing pointers in Exercise 4 of lab 1.

There’s one line of code in pointers.c:

Looks weird at first sight; but TCPL says in Chapter 5.3:

So: a[i] and i[a] are equvalent (if i is a constant). 🙂