MySQL with Django on Debian

First, install MySQL driver for Python:

sudo apt-get install python-mysqldb

Next, modify your config of MySQL: http://dba.stackexchange.com/a/8289

If you’ve already messed up the install, you can either drop/create database from scratch, or apply the following script to every table of your DB:

ALTER TABLE `table` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Alternative mirgation path: http://docs.joomla.org/Convert_a_MySQL_database_to_UTF-8

Nonblocking console input in Python

By Nemesis Fixx:

import sys
import select
import tty
import termios
from threading import Thread

program_run = True
input_thread_timeout = 0.005 #seconds
quit_key = '\x1b' # x1b is ESC

#check stdin for input...
def isData():
        return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])

#check n terminate program on terminal condition,
#from a separate thread
class waitOnInput(Thread):
    def run(self):
        old_settings = termios.tcgetattr(sys.stdin)
        try:
            tty.setcbreak(sys.stdin.fileno())
            global program_run
            thread_run = True
            while thread_run:
                if isData():
                    c = sys.stdin.read(1)
                    if c == quit_key:
                        break
                        thread_run = False
                        program_run = False
        finally:
            termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
            thread_run = False


t = waitOnInput()

#start work here...
i = 1

while program_run :
    if not t.is_alive():
        t.start()

    #test for terminal condition or timeout...
    t.join(input_thread_timeout)

    if t.is_alive():
        #continue work here...
        print i
        i += 1
    else:
        break

PyOpenCl on x64 system

UPD: I found unofficial binary builds here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl, use x86 builds.

Do not forget to install pytools.

I’ve been into some difficulties since i began installing that software, even with help of http://wiki.tiker.net/PyOpenCL/Installation/Windows. Читать далее

Scrapy 0.12 Parsing with python

based on Scrapy Tutorial

1. Install scrapy and dependencies

sudo apt-get install python-lxml
sudo easy_install -U Scrapy

2. Create project

scrapy startproject dmoz

3. Create item models

from scrapy.item import Item, Field
 
class DmozItem(Item):
    title = Field()
    link = Field()
    desc = Field()

Читать далее