sudo apt-get install nginx
sudo pip install gunicorn
/home/ubuntu/my_project -- path to the folder containing manage.py
/home/ubuntu/my_project/my_project -- path to the folder containing settings.py
$USER -- your username
def break_list_by_code_words(l, words): | |
'''Breaks 1-d list in groups by code words. | |
['Code_word_1,'abc','123','sd','Code_word_2','34253','123','Code_word_3','1231','4545'] --> | |
[[Code_word_1,'abc','123','sd'], ['Code_word_2','34253','123'] ,['Code_word_3','1231','4545'] ] | |
''' | |
flag = False | |
ret = [] | |
block = [] | |
for i in l: |
# you might need to install cmake | |
#!/bin/bash | |
# | |
# [email protected], 2014-02-07 | |
# which is not ideal, see http://stackoverflow.com/a/677212/1392758 | |
python=`which python` | |
if type python2 > /dev/null 2>&1; then |
sudo apt-get install nginx
sudo pip install gunicorn
/home/ubuntu/my_project -- path to the folder containing manage.py
/home/ubuntu/my_project/my_project -- path to the folder containing settings.py
$USER -- your username
### http://www.peterbe.com/plog/uniqifiers-benchmark | |
def uniqify(seq): | |
seen = set() | |
seen_add = seen.add | |
return [x for x in seq if not (x in seen or seen_add(x))] |
#'Iterable' means object has an __iter__() method. | |
isiterable = lambda obj: isinstance(obj, basestring) or bool(getattr(obj, '__iter__', False)) | |
from collections import Iterable | |
isiterable = lambda obj: isinstance(obj, Iterable) | |
#https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable |
def fix_string(string): | |
ret = '' | |
for char in string: | |
try: | |
ret += char.encode('cp1252').decode('cp1251') | |
except: | |
ret += char | |
return ret |
#models.py | |
from django.db.models import Aggregate | |
class Concat(Aggregate): | |
def add_to_query(self, query, alias, col, source, is_summary): | |
#we send source=CharField to prevent Django from casting string to int | |
aggregate = SQLConcat(col, source=models.CharField(), is_summary=is_summary, **self.extra) | |
query.aggregates[alias] = aggregate | |
def __init__(self, col, distinct=False, **extra): |
from sklearn.feature_extraction import DictVectorizer as DV | |
vectorizer = DV(sparse = False) | |
v = vectorizer.fit_transform(df.T.to_dict().values()) | |
new_df = pd.DataFrame(v, columns=vectorizer.feature_names_) |
def sort_df(df, column_idx, key): | |
'''Takes dataframe, column index and custom function for sorting, | |
returns dataframe sorted by this column using this function''' | |
col = df.ix[:,column_idx] | |
temp = pd.DataFrame([]) | |
temp[0] = col | |
temp[1] = df.index | |
temp = temp.values.tolist() | |
df = df.ix[[i[1] for i in sorted(temp, key=key)]] |
def get_filelist(path, extension=None,only_folders=False): | |
'''Returns list of files in a given folder, without going further | |
Parameters | |
--------- | |
extension: Collect only files with this extension | |
only_folders: Collect only folders names | |
''' | |
filenames = [] | |
if not only_folders: |