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

Yesterday

twitter (feed #2)
headache. [krat]
7:17pm via Twitter

March 9th

twitter (feed #2)
I hate scribd. [krat]
7:58pm via Twitter
twitter (feed #2)
Drawing fancy charts for my thesis. For some definitions of "fancy". [krat]
4:34pm via Twitter

March 8th

twitter (feed #2)
it's probably better to have a break now, my eyes feel quite tired [krat]
5:45pm via Twitter

March 7th

twitter (feed #2)
cleaning dead RSS feeds from google reader. Apparently, more than half my feeds are dead. [krat]
9:58am via Twitter

March 6th

twitter (feed #2)
I forget things lately. A lot. Damn stressful life. [krat]
4:28pm via Twitter

March 5th

twitter (feed #2)
Another reason to love LaTeX is that you can put your text under version control [krat]
7:24pm via Twitter

March 4th

twitter (feed #2)
Focaccia and beer as study lunch: absolutely priceless. Only downside is that now it's kinda difficult to stay awake. [krat]
2:21pm via Twitter

March 3rd

twitter (feed #2)
I just decided to buy "Flatland" by Edwin Abbot. Only problem is that I won't have time to read it 'til after my graduation [krat]
3:14pm via Twitter
twitter (feed #2)
I'm probably not gonna make this year's #pycon-it. Awful. [krat]
11:34am via Twitter

March 2nd

twitter (feed #2)
God bless \LaTeX [krat]
6:27pm via Twitter

March 1st

twitter (feed #2)
just wrote almost ten pages for my thesis, I guess I'm on a good rhythm [krat]
7:02pm via Twitter

February 26th

twitter (feed #2)
my thesis writing is interspersed by short killing rounds at sauerbraten. That's a good way to get stressed even more. [krat]
5:26pm via Twitter

February 25th

twitter (feed #2)
Just sped up my graph generation procedure with #matplotlib of about 50%. How nice. [krat]
5:48pm via Twitter

Powered by Lifestream.

Search

« Authored by Giuliani Vito Ivan »