Amazing weblog

A fantastic weblog on programming: Word Aligned.

Posted 2007-12-16T03:04:56Z

Mixing configuration files for WSGI

Here's the useless hack of the day: how to mix a Paste Deploy configuration file with a Python script to deploy the WSGI app. The configuration file for Paste Deploy uses the common INI syntax, which uses either # or ; for comments. We can insert Python code into the INI file after the ;, since it can be used in Python to finish a statement. The statement is simply a list with a number inside, since it is valid Python code and also denotes a section in the INI file.

The last step is wrapping the INI configuration in triple quotes, and we have:

[0]; import sys, os
[1]; from paste.deploy import loadapp, loadserver
[2]; application = loadapp('config:%s/%s' % (os.getcwd(), sys.argv[0]))
[3]; server = loadserver('config:%s/%s' % (os.getcwd(), sys.argv[0]))
[4]; server(application); """

[server:main]
use = egg:Paste#http
port = 8081

[app:main]
use = egg:Paste#static
document_root = %(here)s/htdocs

;"""

The WSGI application can now be deployed using either:

$ paster serve file.ini
$ python file.ini

Posted 2007-12-03T17:48:06Z

Elis Regina

Lista de discos da Elis Regina (riscados o que eu tenho):

  • Viva a Brotolândia
  • Poema de amor
  • Elis Regina, 1963
  • O bem do amor
  • Samba - Eu canto assim
  • 2 na bossa
  • O fino do fino
  • 2 na bossa número 2
  • Elis, 1966
  • 2 na bossa número 3
  • Elis especial
  • Elis - como & por quê
  • Aquarela do Brasil
  • Elis Regina in London
  • ...em pleno verão
  • Elis no teatro da praia
  • Ela
  • Elis, 1972
  • Elis, 1973
  • Elis e tom
  • Elis, 1974
  • Falso brilhante
  • Elis, 1977
  • Tranversal do tempo
  • Elis especial
  • Elis, essa mulher
  • Saudade do Brasil
  • Elis, 1980
  • Montreux Jazz Festival
  • Trem azul
  • Luz das estrelas
  • No fino da bossa 1
  • No fino da bossa 2
  • No fino da bossa 3
  • Elis vive

Coletâneas que eu tenho:

  • Nada será como antes
  • Pérolas raras
  • Os sonhos mais lindos
  • O melhor da música de Elis Regina
  • Elis Regina Millenium
  • Elis revisitada
  • Pérolas
  • Perfil
  • Elis Regina 30 anos
  • Elis, 20 anos de saudade

Posted 2007-12-03T16:13:49Z

Programming Nirvana

I've reached a new level on programming — I'm just not sure if for better. Here's some code that I wrote yesterday (it's amazing how much programming I do when I'm without an internet connection!):

data = itertools.imap(
        lambda row, seq=sequence, sel=selection: map(
            lambda d: filter_seq(d[0], sel, d[1]),
            zip(seq.values(), row)
        ), data)

I get bonus points because this snippet is inside the filter_seq function, so it's recursive! That's two lambdas, two maps, a zip and a recursion in a single line!

Posted 2007-10-24T01:02:45Z

More entries