Skip to content

Instantly share code, notes, and snippets.

View mobilestack's full-sized avatar

Tony mobilestack

View GitHub Profile
@mobilestack
mobilestack / chatpdf-zh.ipynb
Created March 25, 2023 11:14 — forked from ninehills/chatpdf-zh.ipynb
ChatPDF-zh.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mobilestack
mobilestack / pyspider_install_fix.md
Last active July 16, 2018 15:28
pyspider installation with pycurl ssl problem

pip uninstall pycurl

export PYCURL_SSL_LIBRARY=openssl

pip install pycurl

from transloadit/python-sdk#4 @ifedapoolarewaju

@mobilestack
mobilestack / nginx.conf
Created April 29, 2018 03:35 — forked from revant/nginx-files.conf
Frappe CORS for nginx
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 January 14, 2018 06:28 — forked from bellbind/ecc.py
[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
mobilestack / dummy-web-server.py
Created September 1, 2017 07:20 — 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.
#!/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 November 12, 2016 13:41 — forked from scotttam/apns.py
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
mobilestack / similar_files_parser
Created September 4, 2014 07:20
I use this to parse badwords files from several sources
"""
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 September 1, 2014 08:49
from python datetime object to int
tt = target_user.created_time
tt_int = time.mktime(tt.timetuple())
@mobilestack
mobilestack / deploy Django on AWS EC2.md
Created July 27, 2014 15:43
【deploy Django on AWS EC2】

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 August 29, 2015 14:03
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

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: