Alsa, surround and CA0106

March 21st, 2008

This is more a remain­der for me: in order to make the sur­round work for mp3s with the CA0106 driver with alsa (for me it’s a Sound Blaster Live! 24 bit), here’s the .asoundrc that should be used:

pcm.!dmix {
   type plug
   slave {
       pcm surround51
       channels 6
   }
}
pcm.!default {
   type plug
   slave.pcm "dmix"
   slave.channels 6
   route_policy duplicate
}

3 Comments, tagged with Geekness, Linux

Inclusive range() in Python

March 6th, 2008

The Python’s built-​in range() is an extremely useful func­tion, but has a little prob­lem: it doesn’t include the right extreme of the range. For exam­ple, a call to range(1, 10) will be eval­u­ated to this a list of num­bers from 1 to 9 (not includ­ing 10):

>>> range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Today I need for a work a range() func­tion that includes the right extreme, so I had to develop mine. Here it is:

def inclusive_range(start, stop, step=1):
    """
    A range() clone, but this includes the extremes
    """
    l = []
    x = start
    while x <= stop:
        l.append(x)
        x += step
    return l

Of course there are faster imple­men­ta­tions of this func­tion around here (and if you know one, please let me know) and surely this one is not one of the fastest, but it works and that solves my prob­lem right now.

7 Comments, tagged with Coding, Python

Forcing ImageField width/height in django

March 2nd, 2008

Ultimately I had to force the size of a uploaded image in the django admin area to a fixed dimen­sion of 620x250px. Even if it could look a simple thing, in fact it isn’t.

The main issue is that even if an Image­Field has a width_field/height_field option that refers to (pre­sum­ably) inte­ger fields that will be auto-​filled with the image size, we can’t ran a val­ida­tor across those fields (we can do so only in a form, but my prob­lem was to val­i­date the image in the admin area). So we have to man­u­ally load the image in memory and run a custom val­ida­tor that uses PIL to get the needed infor­ma­tion and val­i­date the image.

(Con­tinue reading…)

0 Comments, tagged with Coding, Django, Web

Microblogging

July 29th

twitter (feed #2)
Python's date & time functions are horrible. Really. [krat]
2:31pm via Twitter
twitter (feed #2)
Wondering whether I should buy a new set of hearphones or if I should try to fix the old ones [krat]
11:13am via Twitter

July 28th

twitter (feed #2)
discovered beeseek (http://beeseek.org), looks like a very interesting project [krat]
6:08pm via Twitter

July 26th

twitter (feed #2)
just wrote down some help numbers for my next trip, the most important one being the italy's embassy [krat]
2:12pm via Twitter

July 24th

twitter (feed #2)
that's what I call hot weather [krat]
2:00pm via Twitter

July 23rd

twitter (feed #2)
Looking for an (italian|english)<->bulgarian dictionary [krat]
2:05pm via Twitter
twitter (feed #2)
home, sweet home. [krat]
10:10am via Twitter

July 22nd

twitter (feed #2)
Heading to bulgaria (sunny beach) this summer. Not one of the classical holidays places, that's for sure. [krat]
8:50am via Twitter

July 19th

twitter (feed #2)
I hate hotels. [krat]
2:32pm via Twitter

July 17th

twitter (feed #2)
Back in Italy. Discovered this P3 disgusting thing. Want to go back in Spain. [krat]
12:20pm via Twitter

Powered by Lifestream.

Search

« Authored by Giuliani Vito Ivan »