Weblog

Convert select multiple widget to checkboxes in django admin form

I think this should be a nice post talking about the substitution of the default multiple select widget used in django admin interface to deal with m2m fields, with a multiple checkbox widget.

Yes I know, you may solve it this way, but I don't like such solution very much, and I think it is just not perfect for some reasons:

  • At the time of this writing the add related functionality (+) seems to be broken, throws an error, at least for me
  • It just can't be used with the django-mptt application, which is awesome to deal with data which have a tree like structure

So to graphically explain what we want to do here, say we want this ...

read the full post

Reverse selector engineering with mootools

What if you need to get the css selector which targets a DOM element given the element itself?

This is the case for example when you want to store some added information over an element and show it after recharging the page. In this case you may store the information in the local storage object together with the path to the element, in other words you must be able to store the element position inside the DOM

In this scenario ...

read the full post

MySQL, bad preformance of INFORMATION_SCHEMA queries

Recently I've discovered a quite big perfomance problem when running INFORMATION_SCHEMA queries on mysql.

In particular I found that on some systems (some mysql versions) a query like

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'db_table'

can take up to 0.1s to run!

Clearly such time interval is not acceptable, and I think it happens only with some versions of mysql because I've run some tests on my local machine and on the server where this site is running obtaining a result of 0.0007 seconds, we are talking about a difference of two orders of magnitude!

I've not investigated more about which mysql versions are affected and if there are any patches, I ...

read the full post

Glen Hansard, Milano 2013

Dunque oggi sono scassato come una merda, ma sono contento perché ieri sera sono andato in una disco tamarra di Milano a sentire Glen Hansard in concerto.

Inizio concerto ore 20:00, ore 20:00 meno qualcosa parcheggiamo a poca distanza dal locale, 3 bottiglie di vino alle spalle, ci incamminiamo verso l'ingresso e santo Carlo "Oh, ma è Glen!", scorge Glen camminare verso di noi diretto probabilmente ad una birra e paninazzo.

Molliamo di brutto filtri e armamentari e lo placchiamo. Flu rotto in culo si fa firmare l'ukulele ora vero e proprio cimelio. Poi è il momento della foto ed inizio a blaterargli qualcosa di incomprensibile riguardo al fatto che anch'io avrei voluto fargli firmare ...

read the full post

Development of a preview functionality with canvas

Do you remember the last post about canvas dealing with undo and redo functionality?

Now we'll see how to add a preview functionality, that is I want to see my straight line, or my circle, while keeping pressed the left mouse button and moving the pointer to change the shape size.

The first, bad, idea

Initially I thought that the way was to store the portion of canvas interested by the modification and restore it in the next mousemove call, so that the mousemove function has to respect the following flow:

  • restore the previous saved state
  • save the state of the portion of the canvas that now will be drawed
  • draw the new state

Such flow works, but doesn ...

read the full post