This is more a remainder for me: in order to make the surround 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
}
The Python’s built-in range() is an extremely useful function, but has a little problem: it doesn’t include the right extreme of the range. For example, a call to range(1, 10) will be evaluated to this a list of numbers from 1 to 9 (not including 10):
>>> range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Today I need for a work a range() function 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 implementations of this function 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 problem right now.
Ultimately I had to force the size of a uploaded image in the django admin area to a fixed dimension of 620x250px. Even if it could look a simple thing, in fact it isn’t.
The main issue is that even if an ImageField has a width_field/height_field option that refers to (presumably) integer fields that will be auto-filled with the image size, we can’t ran a validator across those fields (we can do so only in a form, but my problem was to validate the image in the admin area). So we have to manually load the image in memory and run a custom validator that uses PIL to get the needed information and validate the image.
(Continue reading…)