Skip to content

Instantly share code, notes, and snippets.

@mobilestack
mobilestack / pyspider_install_fix.md
Last active Jul 16, 2018
pyspider installation with pycurl ssl problem
View pyspider_install_fix.md

pip uninstall pycurl

export PYCURL_SSL_LIBRARY=openssl

pip install pycurl

from transloadit/python-sdk#4 @ifedapoolarewaju

@mobilestack
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
mobilestack / ecc.py
Created Jan 14, 2018 — forked from bellbind/ecc.py
[python]basics of elliptic curve cryptography
View ecc.py
# 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
mobilestack / dummy-web-server.py
Created Sep 1, 2017 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
View dummy-web-server.py
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@mobilestack
mobilestack / apns.py
Created Nov 12, 2016 — forked from scotttam/apns.py
Sends an Apple Push Notification with Python
View apns.py
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
mobilestack / similar_files_parser
Created Sep 4, 2014
I use this to parse badwords files from several sources
View similar_files_parser
"""
badwords source: https://github.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words/blob/master/en
badwords source 2: http://urbanoalvarez.es/blog/2008/04/04/bad-words-list/
"""
f = open("badwords.txt")
lines = f.readlines()
lines2 = []
for i in lines:
#remove trailing and prepending space
@mobilestack
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
mobilestack / deploy Django on AWS EC2.md
Created Jul 27, 2014
【deploy Django on AWS EC2】
View deploy Django on AWS EC2.md

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
mobilestack / south_add_column.md
Last active Aug 29, 2015
south add column of a foreign key contraint type
View south_add_column.md

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

db.create_index

after db.alter_column

though create_index is only for speed consideration.

This is for add a new field of fk constraint:

@mobilestack
mobilestack / django-translate.md
Last active Aug 29, 2015
django translate issue
View django-translate.md

./manage.py makemessages -l zh_CN
要大写的CN而不是小写的,之后
./manage.py compilemessages

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