2007-11-20

How to set font properties in matplotlib create graph

1. Create font dict like this
- font = { 'fontname':'Tahoma', 'fontsize':16 }
2. When you want to change font for example in title use like this
- matplotlib.pylab.title(u'some text', **font)

2007-11-01

Install Webmin on Ubuntu

1. Add deb http://download.webmin.com/download/repository sarge contrib to /etc/apt/sources.list file. (make sure that you have uncommented all universe repository)
2. sudo apt-get update
3. sudo apt-get install webmin

2007-10-25

How to integrate reCAPTCHA with Django

1. Sign up with reCAPTCHA for get public and private key.
2. Download reCAPTCHA for Python.
3. Copy captcha.py to location in your PYTHON_PATH so that you can import it. (e.g /usr/local/python2.5/Lib/site/packages)
4. Now your Django site can use reCAPTCHA.
in your view use reCAPTCHA like this.

import capcha

def captcha_view(request):
captcha.displayhtml(RECAPTCHA_PUB_KEY) # use for display reCAPTCHA in template.
captcha_obj = captcha.submit( request.POST['recaptcha_challenge_field'],
request.POST['recaptcha_response_field'],
RECAPTCHA_PRIVATE_KEY,
request.META['REMOTE_ADDR'] ) # use for create captcha object for check result.
if captcha_obj.is_valid:
return success
else:
return error

2007-10-06

How to use MySQL RegExp

You can use RegExp in MySQL like this.
- SELECT column_name FROM table_name WHERE column_name COLLATE utf8_bin REGEXP '^.* [a-zI]$'

Note: COLLATE is use for use case sensitive in SQL.

2007-09-29

Java jar file.

1. You can extract it and edit "manifest.mf" for edit class path.
2. You can use class inside jar file after extract it to include in one project (you may want to build project in one jar file).

2007-09-17

Using User info outside request in Django

1. Create "middleware" directory in project directory.
2. Create python file name "__init__.py and "threadlocals.py" in "middleware" directory.
3. in side "threadlocals.py" copy this code
    # threadlocals middleware
try:
from threading import local
except ImportError:
from django.utils._threading_local import local

_thread_locals = local()
def get_current_user():
return getattr(_thread_locals, 'user', None)

class ThreadLocals(object):
"""Middleware that gets various objects from the
request object and saves them in thread local storage."""
def process_request(self, request):
_thread_locals.user = getattr(request, 'user', None)

4. in "settings.py" add
"project_name.middleware.threadlocals.ThreadLocals" to the MIDDLEWARE_CLASSES variable.
5. using like this
from project_name.middleware import threadlocals
user = threadlocals.get_current_user()

For more information >> Go to CookBookThreadlocalsAndUser

2007-09-05

Problem BIGINT in Jython

You must convert Python Long object to Java Long object before execute sql command.

Example: id = Long(data[0])
difficulty = utils.calc_sentence_diff(data[1])
cursor.execute(update_sql, (difficulty, id))

2007-09-01

How to set multi django projects on one apache

Use PythonInterpreter in Location setting.
<Location "/something">
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonInterpreter mysite
</Location>
It don't need if you use different VirtualHost.

2007-08-28

RPM Command

Install : rpm -i software-2.3.4.rpm
Update :
rpm -U software-2.3.4.rpm
Install with dependencies problem :
rpm -i software-2.3.4.rpm --nodeps
Unistall :
rpm -e software-2.3.4
List :
rpm -qa | less, rpm -qa | grep name

2007-08-27

Untar command

1. .tar.bz2 use this : tar -jxvf filename.tar.bz2
2. .tar.gz use this : tar -zxvf filename.tar.gz

2007-08-26

Install Apache2 and mod_python on Ubuntu

Use this command sudo apt-get install apache2 libapache2-mod-python
This command for restart apache2 : sudo /etc/init.d/apache2 -k restart

Problem with Flex HTTPService ObjectProxy

Flash player can't convert ObjectProxy to ArrayCollection if you have only 1 item in ObjectProxy.

2007-08-23

How to send email with Django

1. In setting.py define and set values for EMAIL_HOST, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD.
2. In your views import django.core.mail.EmailMessage and SMTPConnection.
3. Create instance of EmailMessage e.g
email = EmailMessage('subject', 'message', 'from_email', list of recipient)
4. Send email by use send method e.g email.send()
5. SMTPConnection use for set connection when you want to send multiple messages in one connection if not create SMTPConnection it will create connection every call send() method e.g
connection = SMTPConnection()
email = EmailMessage('subject', 'message', 'from email', [list of recipient email], connection=connection)