jquery autocomplete show suggestion on focus

Problem: jquery autocomplete does not show a list of suggestions on click
Note: Please do not mix up jquery.ui autocomplete with jquery.autocomplete plugin.

Here is a solution that may help:

     $("#inputfield").autocomplete(val,{
             selectFirst: true,
             autoFill:true,
             minChars:0,
             cacheLength:1,
             matchContains: true,
             mustMatch: true,
         }).bind('focus', function(){
           $(this).click();
         });

Symfony2 autoload mixing classes from different projects

This is not a framework problem.
It happens when PHP caching is enabled.
In my case it was opcache.

sudo vim /etc/php5/mods-available/opcache.ini

; configuration for php ZendOpcache module
; priority=05
;zend_extension=opcache.so    <-- comment this

error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1

Usually the reason is:

1. System development libraries packages are missing:

sudo apt-get install python-dev

Or other libs:
mysql – sudo apt-get install libmysqlclient-dev
lxml – sudo apt-get install libxml2-dev libxslt1-dev

2. You are not running pip from within your virtual environment:

source  yourenv/bin/activate
pip install YOUR_PACKAGE

3. Or when you installing PIL you need to specify:

CFLAGS='-march=x86-64' pip install PIL

Django Server Error (500)

First of all setup error reporting via email, I used gmail in this example.
You will neeed to put lines in your settings.py:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youruser@gmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

Reload the page with 500 error and check e-mail.

Common errors are:

1. ALLOWED_HOSTS = [‘yourwebsite.com’] # here you need to include hosts to allow
2. Check if you have included “staticfiles” app in:

INSTALLED_APPS = (
    'django.contrib.auth',
    .
    .
    'django.contrib.staticfiles',

Prince XML. Split table across pages.

Hi developers,

Try this layout in case you want to split a table across pages in a PDF document with Prince XML.
Header and footer contain absolutely positioned elements. Header and footer heights controlled by CSS properties and prince’s “flow” function.
In this example header will be repeated on each page but footer only once, at the end of the document.
Please note that if you want to change header or footer height you will need to change also margins for @page property.









Header
Absolutely positioned element 1
Absolutely positioned element 2
Absolutely positioned element 3
Absolutely positioned element 4
Absolutely positioned element 5
Table header
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.
Table contents on the page. Table contents on the page. Table contents on the page. Table contents on the page.

Now you can copy the contents above to example.html file and try it like this:

> prince example.html example.pdf

If you have no prince installed you can download it from here

How to delete messages from Gmail using python IMAPclient ?

Google does not delete all messages at once according to http://support.google.com/mail/answer/78755?hl=en.
So, first, you have to delete messages in each folder:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from imapclient import IMAPClient

client = IMAPClient('imap.googlemail.com', use_uid=True, ssl=True)
client.login('mymailbox@gmail.com', 'password')

folders = [
    'INBOX',
    '[Gmail]/Drafts',
    '[Gmail]/Important',
    '[Gmail]/Sent Mail',
    '[Gmail]/Spam',
    '[Gmail]/Starred',
]

for f in folders:
    fold = client.select_folder(f)
    res = client.delete_messages(client.search())
    res = client.expunge()
    client.close_folder()

#Google automatically will move deleted messages to "All Mail" folder. 
#Now we can remove all messages from "All Mail"

client.select_folder("[Gmail]/All Mail")
client.set_gmail_labels(client.search(), '\\Trash')
client.delete_messages(client.search())
client.expunge() 
client.logout()

More information on how to work with Gmail using python IMAPClient can be found directly at http://imapclient.freshfoo.com/browser/imapclient/livetest.py
Read the source code, Luke 🙂

How do you count messages in your gmail ?

Here is the short and dirtyeasy way how to:

First we need to install IMAPClient which extends standard module:

sudo pip install IMAPClient

from imapclient import IMAPClient

server = IMAPClient('imap.googlemail.com', use_uid=True, ssl=True)
server.login('mymailbox@gmail.com', 'password')

for f in server.list_folders():
    if f[2] == '[Gmail]':
        continue
    server.select_folder(f[2])
    all = server.search('ALL', None)
    print('%s : %s' % (f[2], len(all)))