Le blog de Alf

Permission required decorator for django

Very long time since last post. The new thing in my geek life is I’ve switched to Django.

My last issue today was to display an error message instead of redirecting to login page when the use doesn’t have permission. Here is a decorator which replace the permission_required of django. Feel free to rename it to avoid confusion ;-)

Aucun vote pour l'instant.

Talk about Wisss during the Acceleo Day at RMLL 2009

Long time not posting here. I’ve had a lot of work and nothing really interesting to post. I just inform you that I will make a speech about Wisss during the Acceleo Day in Nantes, at L’école des Mines, next friday at 2:30 pm.

More information at :



Aucun vote pour l'instant.

Array search performance

You probably have often searched for a value in an array using the in_array() function. Reading php|architect’s Guide to PHP Security by Ilia Alshanetsky, I’ve noticed that searching on values can be slower than searching on keys. I’ve wanted to compare performance between the three methods to check a value in a white list and it’s amazing how slower is in_array(), look at the result :

Aucun vote pour l'instant.

Zend Pdf and PNG transparency issue

Currently working on PDF generation, I’ve noticed that drawing a big PNG image with transparency (about 600×800, 150kB) brings the script computation up to 20 seconds. I’ve raised the bug in the Zend Framework issue tracker and for now, don’t forget to remove transparency in your background image if you can.

See the bug at :  http://framework.zend.com/issues/browse/ZF-3392

Aucun vote pour l'instant.

Wrapping text for Zend Pdf

A common issue in Zend_Pdf is to wrap text in a box. I’ve found partial solutions such as wrapping text each 80 characters for instance but the line width can vary regarding the font and the character width. Since we can’t rely on the character count unless using a monospaced font, we have to wrap text on the real box width.

In partial solutions, I’ve found a function which computes the real width of a string according to the font and the font size. By aggregating every chunks, I’ve made my getWrappedText() method which returns a string with the correct \n :

Votre notation : Aucun Moyenne : 5 (2 votes)

Integration of Scriptaculous slider in Zend framework

For a customer need, I’ve integrated the scriptaculous slider as shown here in Zend framework.

To achieve this, I’ve created a formSlider view helper which is then used by a slider form element.

The view helper and form element code is here. To allow ZF to find the helper, don’t forget to add path to helper in your bootstrap :

Aucun vote pour l'instant.

Autoresize textarea

I was looking for a javascript which could automatically resize a textarea but the ones I’ve found were a bit buggy or ugly, so I’ve written mine. There’s just a tiny bug with copy/paste with mouse.

Aucun vote pour l'instant.

How to extract audio from a DVD and encode to flac

To see information about the dvd :

mplayer -identify -frames 0 dvd://

To encode the 17 chapters of the first title of a dvd :

for i in $(seq 17) ; do mplayer -vo null -ao pcm -ao pcm:file=$i.wav:fast -chapter $i-$i dvd://01 ; flac $i.wav --best & done

Aucun vote pour l'instant.

Apache Virtualhost generator

Currently I’ve not much time to work on Wisss :-( However, I will make a tiny dsl and generator to have a virtualhost file generated (independent from Wisss, which already generate a vhost). I’ve already done this with a shell script but it will be more powerful and easy to maintain for a few hours of work.

The initial need is for my own server but it will also be useful for my company. The goal is to provide our best practice for vhost in a tool.

Votre notation : Aucun Moyenne : 5 (2 votes)

New features in Wisss : authentication, acl, blocks

Following my last post about authentication, I’ve implemented it in Wisss. I’ve also added a simple ACL management which retrieves all resources, roles and privileges from database and constructs a Zend_Acl object in the boostrap. I’m not very happy to have to retrieve all stuffs about ACL each time, but for now, I have no time to implement something smarter.

Aucun vote pour l'instant.