Skip to content

Instantly share code, notes, and snippets.

View mobilestack's full-sized avatar

Tony mobilestack

View GitHub Profile
@mobilestack
mobilestack / gdal geos for python33 on Windows7 x64.md
Last active August 29, 2015 13:55
Install Gdal for Postgis on Windows7, x64, Python3.3

I am developing a Django site and my development machine uses Windows7, X64, since Postgis is more or less the best option, I decided to migrate my database from sqlite3 to Postgresql, and on production side, migrating Mysql to Postgresql.

So on development side, I install the Postgresql from a binary installer, which includes an optional Postgis extension for intallation. Although it says Gdal is included, but my Python3.3 just cannot find it. If I test it in Python:

from osgeo import gdal

or

from django.contrib.gis import gdal
@mobilestack
mobilestack / proj installation on linux.md
Last active August 29, 2015 13:55
proj.4.8.0 install failure on Linux

https://code.zmaw.de/boards/2/topics/895

to add --without-jni, so it is

./configure --prefix=/home1/username/proj --without-jni

in the downloaded and extracted proj file.

Then when installing Postgis on Bluehost, just download postgis and run inside the extracted file folder:

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

#########################
# .gitignore file for Xcode5
#
# NB: if you are storing "built" products, this WILL NOT WORK,
# and you should use a different .gitignore (or none at all)
# This file is for SOURCE projects, where there are many extra
# files that we want to exclude
#
# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
# and https://gist.github.com/adamgit/3786883
@mobilestack
mobilestack / django-translate.md
Last active August 29, 2015 14:02
django translate issue

./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

@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:

@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 / 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 / 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