Skip to content

Instantly share code, notes, and snippets.

mobilestack /
Last active Jul 16, 2018
pyspider installation with pycurl ssl problem

pip uninstall pycurl

export PYCURL_SSL_LIBRARY=openssl

pip install pycurl

from transloadit/python-sdk#4 @ifedapoolarewaju

mobilestack / nginx.conf
Created Apr 29, 2018 — forked from revant/nginx.conf
Frappe CORS for nginx
View nginx.conf
location @webserver {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
mobilestack /
Created Jan 14, 2018 — forked from bellbind/
[python]basics of elliptic curve cryptography
# Basics of Elliptic Curve Cryptography implementation on Python
import collections
def inv(n, q):
"""div on PN modulo a/b mod q as a * inv(b, q) mod q
>>> assert n * inv(n, q) % q == 1
for i in range(q):
if (n * i) % q == 1:
mobilestack /
Created Sep 1, 2017 — forked from bradmontgomery/
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
Very simple HTTP server in python.
./ [<port>]
Send a GET request::
curl http://localhost
mobilestack /
Created Nov 12, 2016 — forked from scotttam/
Sends an Apple Push Notification with Python
import socket, ssl, json, struct
import binascii
# device token returned when the iPhone application
# registers to receive alerts
deviceToken = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
thePayLoad = {
'aps': {
'alert':'Oh no! Server\'s Down!',
mobilestack / similar_files_parser
Created Sep 4, 2014
I use this to parse badwords files from several sources
View similar_files_parser
badwords source:
badwords source 2:
f = open("badwords.txt")
lines = f.readlines()
lines2 = []
for i in lines:
#remove trailing and prepending space
mobilestack / dateTime2Int
Created Sep 1, 2014
from python datetime object to int
View dateTime2Int
tt = target_user.created_time
tt_int = time.mktime(tt.timetuple())
mobilestack / deploy Django on AWS
Created Jul 27, 2014
【deploy Django on AWS EC2】
View deploy Django on AWS

Solve a deployment problem

Problem:psycopg2 not found

This afternoon I have met a problem for my website, it is not accessible due to an error of psycopg2, which is a module for python to connect with Postgresql database. I would like to document this to public for anyone in future for a referrence.

After the problem occurred, I blamed AWS, that everything was running OK and it just suddenly failed. The fact is that I didn't change anything in between, which is annoying. Or maybe one of the system upgrade suggested by AWS was the reason, I remembered that several packages was installed, but it seemed the problem had not really instantly occurred. But anyhow, the problem has to be solved, after waiting for serveral hours, I started to debug it. The problem states that:

ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

which apprently means that psycopg2 is not found by my web server.

mobilestack /
Last active Aug 29, 2015
south add column of a foreign key contraint type

in south migration, if add a new column of foreign key constraint, only one line is fine. However, if changing from one existing field which is not a foreign key type, i.e. only a integer type, then should add a line of code


after db.alter_column

though create_index is only for speed consideration.

This is for add a new field of fk constraint:

mobilestack /
Last active Aug 29, 2015
django translate issue

./ makemessages -l zh_CN
./ compilemessages

chrome cached files, but not able to discover, or on the server side, some files are cached