Skip to content

Instantly share code, notes, and snippets.

CREATE DATABASE bot2_local
WITH OWNER = opquast
ENCODING = 'UTF8'
TABLESPACE = temesis_dev
LC_COLLATE = 'fr_FR.UTF-8'
LC_CTYPE = 'fr_FR.UTF-8'
CONNECTION LIMIT = -1;
apt-get intall libxapian-dev
184 apt-get install libxapian-dev
185 apt-get install apt-xapian-index
186 ./configure --prefix=$VENV --with-python && make && make install
187 apt-cache search xapian
188 apt-cache search libtool
189 apt-get install libtool
190 ./configure --prefix=$VENV --with-python && make && make install
191 apt-get install libltdl-dev
192 ./configure --prefix=$VENV --with-python && make && make install
pip install django-haystack==2.3.1
pip install git+https://github.com/notanumber/xapian-haystack.git
# Check and correct /lib/python2.7/site-packages/xapian_backend.py L64 for python 2.6
apt-get install uuid-dev
apt-get install zlib1g-dev
apt-get install g++
export VENV=$VIRTUAL_ENV
@martinsam
martinsam / split_word.py
Last active August 29, 2015 14:16
Patch for xapian.InvalidArgumentError: Term too long (> 245):
def split_word(word, length=230):
return (word[n:n+length] for n in range(0, len(word), length))
def prepare_YOUR_FIELD(self, obj):
return u' '.join(item for word in obj.YOUR_FIELD.split() for item in split_word(word))
@martinsam
martinsam / checklists_models.py
Created February 16, 2015 14:25
CHECKLIST : Génération de liste de critères
def generate_criteria_list(self):
thema = ChecklistField.objects.filter(
checklist=self,
type=COLUMN_TYPES['PRIMARY']).values_list('pk', flat=True)[0]
level = ChecklistField.objects.filter(
checklist=self,
type=COLUMN_TYPES['PRIORITY']).values_list('pk', flat=True)[0]
cfv = CriterionFieldValue.objects.prefetch_related('fieldvalues').select_related('criterion').filter(
Q(field=level) | Q(field=thema),
@martinsam
martinsam / timezone.py
Last active August 29, 2015 14:13
Get Timezone : Continent/Country
#!/usr/bin/env python
#http://stackoverflow.com/questions/7669938/get-the-olson-tz-name-for-the-local-timezone
from hashlib import sha224
import os
from os import listdir
from os.path import join, isfile, isdir
infoDir = '/usr/share/zoneinfo/'
from datetime import datetime
from django.db.models import Manager
from django.db.models.query import QuerySet
class TodoMixin(object):
def is_done(self):
return self.filter(done=is_true))
#ecrire ici vos nouvelles méthodes
class TodoQuerySet(QuerySet, PostMixin):
@martinsam
martinsam / gist:5721535
Created June 6, 2013 13:38
Git : revert-to-a-commit-by-sha-hash
If you want to commit on top of the current HEAD with the exact state at a different commit, undoing all the intermediate commits, then you can use reset to create the correct state of the index to make the commit.
# reset the index to the desired tree
git reset 56e05fced
# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
@martinsam
martinsam / gist:5636033
Last active December 17, 2015 16:00
django: Formset parameters
from django.utils.functional import curry
from django.forms.models import modelformset_factory
ManagerFormset = modelformset_factory(User, ManagerForm, extra=0)
ManagerFormset.form = staticmethod(curry(ManagerForm, selected=selected, company=company))
form = ManagerFormset(queryset=coworkers)
@martinsam
martinsam / gist:5525185
Last active December 17, 2015 00:59
pre-commit - Check po
if check_po /home/sam/opquast/pdn/locale/fr/LC_MESSAGES/django.po | grep 'FUZZY'; then
echo "\033[44m----------------------------------------------------\033[0m"
echo "\033[31m FUZZY présent dans locale/fr/LC_MESSAGES/django.po\033[0m"
exit 1
else
echo -n "\033[32m"
check_po /home/sam/opquast/pdn/locale/fr/LC_MESSAGES/django.po
echo -n "\033[0m"
fi