Django first steps

May 22nd, 2009

When I started doing web development I choose symfony because at the time (it’s been 3 years) I only knew JSP and PHP. I’ve used symfony for some projects and I like it very much.

Now, I’m learning django because I’m curious how is the python way in web development.

The Model definition in django is, IMHO, much more clever and elegant. No need to write a schema file like in symfony. The ORM and QuerySet are very well designed. I never tried doctrine in symfony, but Propel is more tedious to use than QuerySet.

Setting up a django project is quite easy and fast. I don’t need to setup apache and related suff. django comes with some handy scripts. Symfony has handy scripts too :-) but I like django more.

Well, there is a lot of stuff to learn, but so far, I’m very excited to use django in future projects.

  • Share/Save/Bookmark
Author: promag Categories: Web Development Tags: ,

How to invert my site images and CSS

May 3rd, 2009

While configuring WordPress I found a nice theme named inove. But it is too bright for me. So I tried to invert colors. But to do that I need to invert all images and colors in the CSS.

Let’s begin with CSS. I found a simple script that inverts all colors in CSS. The original script is a little buggy and I prefer passing arguments to scripts:

import re
import string
import sys

p6 = re.compile("#[0-9a-f]{6}[;\s]", re.IGNORECASE)
p3 = re.compile("#[0-9a-f]{3}[;\s]", re.IGNORECASE)
filepath = sys.argv[1]

content = file(filepath,'r').read()

def Modify (content):
    text = content.group().lower()
    table = string.maketrans(
                   '#0123456789abcdef ;',
                   '#fedcba9876543210 ;')
    result = text.lower().translate(table)
    return result

content = p6.sub(Modify,content)
content = p3.sub(Modify,content)

out = file(filepath,'w')
out.write(content)
out.close()

Save this script as invertcss.py and invoke the following in the theme parent folder:

sudo find . -name "*.css" -exec python /path/to/invertcss.py \{\} \;

To invert images I use convert from image magik package:

sudo find . -name "*.jpg" -exec convert \{\} -negate \{\} \;
sudo find . -name "*.png" -exec convert \{\} -negate \{\} \;
sudo find . -name "*.gif" -exec convert \{\} -negate \{\} \;

I had to manually change named colors in CSS, like black to white, and restore some original images that I wanted like the header and some icons. But the point is, some python and bash scripting saved some time, at least it was fun.

  • Share/Save/Bookmark
Author: promag Categories: Programming, Web Development Tags: , ,

promag in python

May 2nd, 2009

This experience proves my nickname explanation in my About page, with python:

def perms (lst):
    if lst:
        return [[x] + ps
                for x in lst
                for ps in perms([e for e in lst if e != x])]
    else:
        return [[]]

print 'My nickname is '+[''.join(x[:6]) for x in perms("programmer")][26]

Running the script outputs:

python promag.py
promag

There is the list permutation function that is invoked with ‘programmer’. All permutations are prunned to length 6, because that was long enough for my nick. Funny that currently I’m 26 years and it’s the promag permutation index.

  • Share/Save/Bookmark
Author: promag Categories: Programming Tags: