Friday, December 31, 2010

Looking for a job...

I'm looking for a job - Python / Django Developer (remote work is preferable, but Google HR are welcome)

Brief Curriculum Vitae

Keywords: Linux, Free Software, Python, PyGTK, Django, Resume :-)

Thursday, December 3, 2009

Convert SVG to PNG

1. sudo apt-get install librsvg2-bin

2. for i in *.svg; do rsvg -h 96 -w 96 $i `echo $i | sed -e 's/svg$/png/'`; done

PS: man rsvg for more options and command description.

Thursday, November 19, 2009

What is the best comment in source code you have ever encountered?

Read this topic on StackOverflow and have fun! :)

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

Friday, September 4, 2009

Django: ManyToMany field and custom CheckboxSelectMultiple widget

In one of the previous posts I showed how to create a custom widget to use with Multiple Choice model field, but you can also use it as widget for ManyToMany field.

Models/fields definition:

class Genre(models.Model):

    slug = models.CharField(primary_key=True, max_length=32)
    title = models.CharField(unique=True, max_length=64)

class Movie(models.Model):
    title = models.CharField(blank=True, max_length=70)
    director = models.CharField(blank=True, max_length=100)
    genres = models.ManyToManyField(Genre, blank=True, null=True)
    ...

And here a form based on a Movie model:
from model import Movie
from widgets import CustomCheckboxSelectMultiple

class MovieForm(forms.ModelForm):

    class Meta:
        model = Movie

    def __init__(self, *args, **kwargs):
        super(MovieForm, self).__init__(*args, **kwargs)
        # Custom widget for genres selection
        self.fields['genres'].widget = CustomCheckboxSelectMultiple(
            choices=self.fields['genres'].choices)
        # Removing "Hold down "Control", or "Command" on a Mac, to select more than one."
        self.fields['genres'].help_text = ''

Sunday, August 30, 2009

Cinemania: First Blood

Cinemania 0.2 (codename 'First Blood') is ready for testing ;-)


Bellow is a short installation instruction:

  1. Install prerequisites:
    apt-get install python-imdbpy python-imaging
  2. Checkout cinemania buildout from SVN:
    svn co https://cinemania.svn.sourceforge.net/svnroot/cinemania/buildout cinemania_buildout
  3. Bootstrap the buildout:
    cd cinemania_buildout/
    python2.5 ./bootstrap.py
    and run buildout script:
    ./bin/buildout -c devel.cfg
  4. Setup initial database and run django web server:
    ./bin/django syncdb
    ./bin/django runserver
  5. Point your browser at http://localhost:8000/
    for site administration http://localhost:8000/admin/

Saturday, August 29, 2009

Quick and simple vsftpd configuration

  1. Install vsftpd server:

    apt-get install vsftpd

  2. Edit /etc/vsftpd.conf file:
    ...
    # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    anonymous_enable=NO
    #
    # Uncomment this to allow local users to log in.
    local_enable=YES
    #
    # Uncomment this to enable any form of FTP write command.
    write_enable=YES
    #
    # Default umask for local users is 077. You may wish to change this to 022,
    # if your users expect that (022 is used by most other ftpd's)
    local_umask=022
    ...
    First we close anonymous access to FTP, but instead allow local users to log in and grant them permission to write on FTP.
    ...
    # You may restrict local users to their home directories. See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    chroot_local_user=YES
    ...
    # Specifies the directory vsftpd changes to after a local user logs in.
    # There is no default value for this directive.
    local_root=/home/ftp
    ...
    Next we restrict local uses to /home/ftp directory.

  3. By default /home/ftp, doesn't have a write permission for unprivileged users (i.e. not root). There are two possible solutions: made /home/ftp directory writable for all users, i.e. chmod a+w /home/ftp or limit write access to group members only, it's a better approach so you can easily grant/close write access to any appropriate user by changing their membership in privileged group:
    # addgroup ftpusers
    # chgrp ftpusers /home/ftp
    # chmod g+w /home/ftp
    # adduser username ftpusers
That's it! Now our user can upload files on FTP server.