Debian and Ubuntu server locale and encoding

I recently had «fun» supporting server installation of software that needed locale set properly.

In Debian, you can just use

dpkg-reconfigure locales

and the console GUI will pop up.

In Ubuntu server, you’ll more steps to make^

And make full use of UTF, please:

Django soft image thumbnail replacement

Using new template tag, you’re now free to cache images before rolling out new design and avoid heavy load (maybe via random call)!

<img src="{{img.url|thumb:"500x500"%}" />

{% if rand % 10 }
{with newthumb=img.newthumb %}}

or <!-- {{img.url|thumb:"500x580"%} -->

{% endif %}

MySQL with Django on Debian

First, install MySQL driver for Python:

sudo apt-get install python-mysqldb

Next, modify your config of MySQL:

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:


Alternative mirgation path:

Python chroot

What is important to remember is that chroot will allow you cd into /, and that will correspond to the dir you chrooted in:

for opt in glob.glob("/*"):
    print "\t-> %s" % opt

    print "Chroot FAIL"
    print os.getcwd()
except Exception as e:
    print "Chroot OK"

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[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)
            global program_run
            thread_run = True
            while thread_run:
                if isData():
                    c =
                    if c == quit_key:
                        thread_run = False
                        program_run = False
            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():

    #test for terminal condition or timeout...

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

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()

Читать далее

Installing MongoDB 1.8.1 on Ubuntu 11.04 and PyMongo

Install everything you need:

sudo apt-key adv --keyserver --recv 7F0CEB10
sudo nano /etc/apt/sources.list

Next, add a line to sources.list:

— on Ubuntu

deb dist 10gen

— on Debian

deb dist 10gen
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo apt-get install python-setuptools
sudo easy_install pymongo

Next, test the connection:
Читать далее

Django nginx Debian

How to make a simple install of django onto small Debian-6 VPS.
I’ll stick with flup, which enables python to serve fastcgi and some other protocols.
I use it in conjunction with nginx, which in turn is used save memory.

Читать далее