L'uso di questo sito
autorizza anche l'uso dei cookie
necessari al suo funzionamento.
(Altre informazioni)

Monday, February 25, 2013

Antique Iron

An IBM 029 keypunch

This is a picture of a keypunch akin to the one I typed my first lines of codes on:













      PROGRAM SOMMA
C
C Calcola la somma di due
C numeri e stampa il 
C risultato 
C

      INTEGER A,B,SOMMA
      A=1
      B=3
      SOMMA=A+B
            PRINT(6,100),A,B,SOMMA
            STOP
 100      FORMAT(I4,1H+,I4,1H=,I4)

That' FORTRAN 66, Bay bee.

Friday, February 22, 2013

The twisted. The perverse. The developer.

Say you are running an android emulator for development reason and you want to copy some text to the (emulated) screen. That would be a CTRL+V on most platforms/applications.

But we developers have better ways, just:

# telnet localhost 5554
sms send 123123123 The text you want to copy
quit

You send an SMS to the phone, then in the emulator, open the message, copy the text, and paste wherever you want. Get it? Ain't that just beautiful?

This is the brain of developers laid bare for your wonderment. I kid  you not.

P.s: hats off to Stack Overflow for the tip
 

Thursday, January 24, 2013

Custom column names on Django ManyToMany fields.


Adapting Django  to legacy databases requires you to control table and column names.

manage.py inspectdb does a nice enough job of it (but beware of missing to_field on ForeignKey relationshiops when not linking to the primary key). 

ManyToMany fields, however, are left in the cold. Table name can be set with db_table=, but there is no (documented) hook to influence column names. Finer control can be achieved through the relatively new 'through' argument: that, however, kinda ruins many of the ORM language and of the admin application capabilities.

I googled myself blind and visited a few blind alleys. Postgres, for instance, does not have updatable views, or one could use a view to sort of rename columns - without actually doing it - thus appeasing django's engine; updatable views could be emulated with a CREATE RULE, but I decided against going there.

I dived in django code - the related.py and construction.py files - not pretty .I will heretofore direct to those files anyone extolling to me the clarity of python coding.

I eventually came across a Django Snippet that the author appears to have  retracted, but that the internet wayback machine still preserves. It did still require a modification, but I finally came up with:





from django.db import models



class CustomManyToManyField(models.ManyToManyField):

    def __init__(self, *args, **kwargs):

        source = kwargs.pop('source_db_column', None)

        reverse = kwargs.pop('reverse_db_column', None)

        if source is not None:

            self._m2m_column_cache = source

        if reverse is not None:

            self._m2m_reverse_column_cache = reverse

        super(CustomManyToManyField, self).__init__(*args, **kwargs)

# later.... class TipoCommesse(models.Model):     id          = models.IntegerField(primary_key=True)     descrizione = models.TextField() # This field type is a guess.     tipo_fasi   = CustomManyToManyField('TipoFasi',db_table='t_fasi4t_commessa',source_db_column='id_tipo_com',reverse_db_column='id_tipo_fase')     def __unicode__(self): return self.descrizione     class Meta:         managed =  False         db_table = u'tipo_commesse'         verbose_name_plural='TipiCommesse'
Note the managed = False line in the Meta inner class indicating that syncdb & Co. need not alter the database for this type. Besides being a sane precaution to set on everything when dealing with legacy DBs, it is doubly necessary here because finding out how to persuade Django to honor the column specifications when actually creating the tables proved to be beyond my ability - that's the above mentioned - and by now infamous - construction.py file. The effect is that (as can be seen with manage.py sql, with manage=True) Django would still generate columns of the form re11rel2_id even for the custom m2m field.




Also note that this trick is fragile: it depends on django actually using the 'column' and 'reverse_column' names when currying the attribute accessor (don't ask). This has already been broken once in the past.


Finally, a big 'Thank You' to Quentin Tarantino for making Django searches a more interesting experience with his "Django Unchained" release ;-)

Monday, October 22, 2012

Isole Venete

Il burino di Burano,
Su un muretto qui a Murano
mentre pensa alla Morena
e, col viso un po' murino,
mangia mesto una murena.

Se ne andrà forse a Mirano,
il burino di Burano,
ben lontano da Murano,
per dimenticar Morena.

--Ettore Sacrestia.

Tuesday, October 9, 2012

Libertà di

Ha ragione Mario Pirani quando chiama repellenti le tirate dei siti neonazisti contro Shlomo Venezia.

Però trovo molto pertinenti le osservazioni di questo articolo di Slate ("Hate Speech Hypocrites"): come si fa a dire ai musulmani che non possiamo impedire blasfemie contro Maometto mentre - ad esempio - non ci facciamo grossi problemi nella regolamentazione del discorso sull'Olocausto?

Io - con tutti i problemi che comporta - credo che la posizione di Slate sia l'unica compatibile con un'idea coerente di libertà d'espressione.

Monday, October 8, 2012

Dormire, forse?

Pare che bisognerebbe aver letto un numero considerevole dei seguenti libri. Armarsi di laboriosità, o procombere?
  1. The Republic, Plato
  2. Organon, Aristotle
  3. Nicomachean Ethics, Aristotle
  4. City of God, Augustine
  5. Summa theologiae, Aquinas
  6. The Prince, Machiavelli
  7. Novum Organum, Francis Bacon
  8. Discourse on Method, Rene Descartes
  9. Meditations on First Philosophy, Rene Descartes
  10. Leviathan, Thomas Hobbes
  11. Ethics, Spinoza
  12. An Essay Concerning Human Understanding, John Locke
  13. Monadology, Leibniz
  14. Principles of Human Knowledge, Berkeley
  15. A Treatise of Human Nature, Hume
  16. Dialogues Concerning Natural Religion, Hume
  17. The Social Contract, Rousseau
  18. The Principles of Morals and Legislation, Jeremy Bentham
  19. Critique of Pure Reason, Immanuel Kant
  20. Phenomenology of Spirit, Hegel
  21. Utilitarianism, John Stuart Mill
  22. Vindication of the rights of Women, Mary Wollstonecraft
  23. Either/Or, Soren Kierkegaard
  24. Method of Ethics, Sidgwick
  25. Thus Spoke Zarathustra, Nietzsche
  26. Communist Manifesto, Karl Marx
  27. Principia Ethica, G. E. Moore
  28. Being and Time, Martin Heidegger
  29. Tractatus, Wittgenstein
  30. Philosophical Investigations, Wittgenstein
  31. Being and Nothingness, Jean-Paul Sartre
  32. The Second Sex, de Beauvoir

Thursday, September 27, 2012

Disavventura artica allitterativa

Una squadra di ricercatori, inviata al circolo polare artico da una gelateria biologica per sperimentare nuovi gusti, era intenta a raccogliere materie prime. Ad un tratto, un branco di cani selvatici li sorprese, rubando loro i preziosi prototipi di gelato. La disavventura fu raccontata così:
 
"Eravamo lì chini
a raccoglier licheni,
quando alcuni cani
han rubato quei coni."

Wednesday, September 5, 2012

Quelli che leggono le loro tesi su Radio 3

Oggi, verso la una, c'era una ragazza (ragazzina?) che diceva cose del tipo  

"Non c'è quasi bisogno di presentarla, questa 'SolidaritatLied'. Molti di voi ricorderanno che è inserita alla fine di un film del 1932 con sceneggiature di Bertolt Brecht...."

Insomma, faceva tenerezza. Invece quelli che ce l'hanno messa, a leggere la sua (esoterica, per i più) tesi in un giorno di fine estate, per tappare un buco di palinsesto, mi fanno abbastanza rabbia.

Thursday, August 2, 2012

Il centro storico di Modena e i capponi di Renzo.

Leggo, spazientito, sul blog di "In ascolto":

'Nei giorni scorsi l’Assessore Sitta ha detto che il centro storico è “il più bell’Outlet del mondo“… Noi la pensiamo diversamente. Perché gli outlet sono i nemici numero uno dei centri storici. Al pari dei centri commerciali. E un Assessore allo Sviluppo economico dovrebbe esserne consapevole. Perché il contesto degli outlet non è minimamente paragonabile a quello dei nostri centri storici, così ricchi di cultura, di storia e di eccellenze architettoniche. In secondo luogo perché nei centri storici c’è vita vera e la si respira. Anche grazie ai negozi che animano le vie del cuore della città ed agli imprenditori che li conducono con amore per il proprio mestiere e per la propria città.Negli outlet regna l’artificiosità e il tentativo di ricreare le atmosfere dei centri storici non ha avuto risultati positivi, anzi. E poi non ci sono i commercianti, con la loro storia e la loro passione. Ci sono gli industriali del commercio, poca anima e molta standardizzazione.
Invitiamo dunque Sitta a evitare, in futuro, tali similitudini'




E rispondo....

Io invece – senza con ciò condividere la stragrande maggioranza delle iniziative di Sitta – ritengo che sia questo tipo di prese di posizione, gattopardesche e apparentemente di alto profilo, a decretare la stagnazione e morte dei nostri centri storici. Un po’ come quando si fa notare ai commercianti che uno dei motivi per cui i loro fatturati calano è il livello dei prezzi e ci si sente rispondere che i prezzi non c’entrano e i problemi sono “ben altri”. Poi se uno scava un po’ scopre che i “ben altri” problemi si risolvono ponendo limiti ferrei alla concorrenza. Ma tò.

Se è vero (com’è vero) che i nostri centri storici sono “così ricchi di cultura, di storia e di eccellenze architettoniche” non dovrebbe essere poi impossibile utilizzare queste caratteristiche per farne diventare la parte commerciale concorrenziale con gli outlet. Dopo tutto, mi pare che Benetton, bieco industriale del commercio com’è, in centro se la cavi piuttosto bene (o mi sono perso una puntata?) . Oppure bisognerà concludere che i commercianti con la loro storia, passione e quant’altro, preferiscono fare la fine dei capponi di Renzo.

Monday, July 30, 2012

The olympic record in bad taste.

Am I alone in thinking that the 2012 Olympics opening ceremony has taken kitsch to an entirely new record, that future generations will have to strive very hard to emulate?