Very often I found on the web ContentProvider examples based on a SQLite table that describes, as a constraint, to have a column named _id to be used as primary key. Also the official Android Dev Guide introducing in Creating a Content Provider tells to
Be sure to include an integer column named “_id” (with the constant _ID) for the IDs of the records.
This way of done it could be considered a good best practice when the Content Provider that I have to implement is based on a single table. It’s also very useful because the fact that widgets like ListView works by default with Content Providers that provides an integer identifier called _id, but it couldn’t be considered a constraint.
Infact, if the Content Provider you have to implement is not trivial and, for example, is based on data coming from more than one tables, the rule to use for the identifier column the _id name is unconfortable and it makes the phase on design of the data model warped.
Now I try to describe a not so much complicated example where the use of _id as identifier column name is impossible and I’ll make an example of how to build a Content Provider to manage this case without leaving the facilities guaranteed to the trivial way of done.
Continue Reading »
Tags: android, database, mobile
Posted in english, programming | No Comments »
Per tutti coloro che li davano per morti e per tutti coloro che li stavano aspettando, ecco, sembra siano tornati gli eBook. Perlomeno si è tornato a parlarne e c’è chi, addirittura, ci sta scommettendo per il proprio business.
Non sto certo parlando dei pdf, che invece di essere mandati in stampa, vengono in messi in vendita sulla rete, ma sto parlando di edizioni digitali vere e proprie affiancate o meno a quelle cartacee.
Continue Reading »
Tags: digital publishing, eBook, new media
Posted in digital publishing | No Comments »
È da qualche tempo che tengo d’occhio il mercato dei dispositivi di lettura basati sulla tecnologia eInk. Di recente mi sono deciso ad acquistarne uno che mi permettesse, oltre al godere del piacere della lettura su tale dispositivo, di fare qualche esperimento riguardo ai formati supportati da questi dispositivi.
Dopo avere provato il CyBook ho deciso di acquistare il BeBook, non perché il CyBook non sia un buon eBook reader, ma perché il BeBook offriva, almeno sulla carta, il supporto molti più formati di file come, ad esempio, il formato epub, rtf e doc.
Per arrivare a tale decisione mi sono basato su due recensioni che ho trovato in rete e che elenco di seguito perché le ritengo molto ben fatte e, dopo aver provato il dispositivo in questione, rispondi alla realtà:
Per quanto riguarda le mie prove, mi sono concentrato nel verificare i formati supportati e sulla reale fruibilità e leggibilità di libri nei vari formati. Quello che si nota infatti è che questi eBook reader usino programmi differenti e con diverse interfacce in base al formato da leggere rendendo, di conseguenza, diverse l’esperienza di lettura differente. Questo fatto potrebbe essere considerato normale per formati intrinsecamente diversi come un pdf, che è formato a layout fisso, e un mobipocket, che non impone un layout ai contenuti (reflowable text), ma talora, come vedremo più avanti, succede anche per formati teoricamente e strutturalmente simili.
Continue Reading »
Tags: bebook, cybook, digital publishing, eBook, eReader
Posted in digital publishing, hardware | 6 Comments »
Yesterday I was googling to find the algorithm to covert a netmask (in the dotted decimal format like 255.255.255.0) in corresponding cidr to manage a database migration, but I can't find it. So I wrote it in PHP.
The following function takes a valid netmask in the dotted decimal format as a string in input and returns the corresponding cidr prefix length as int:
PHP:
-
function netmask2cidr($netmask) {
-
$cidr = 0;
-
foreach (explode('.',
$netmask) as $number) {
-
for (;$number> 0; $number = ($number <<1) % 256) {
-
$cidr++;
-
}
-
}
-
return $cidr;
-
}
Useful links
Tags: netmask, networking, PHP
Posted in english, programming | No Comments »
If you need to copy an XML document to another filtering it from a specific element node, a good solution could be the use of XSL. The starting point is the so called "identity" template as introduced with an example in the XSLT Recommendation itself:
XML:
-
<xsl:template match="@*|node()">
-
<xsl:copy>
-
<xsl:apply-templates select="@*|node()"/>
-
</xsl:copy>
-
</xsl:template>
The above template copies all attributes, @*, and all nodes being children of other nodes, node(): element nodes, text nodes, comment nodes and processing instruction nodes. Everything is copied. "Recursion" in the above case is when the template ends its job by calling other templates including itself.
Copying everything is no fun but becomes very useful when we add exceptions to the copying. It gets useful when we "copy everything but". The step by step approach in the copying is the big trick. For each attribute, element, etc., we can decide to do something else by adding other templates overruling the copying behavior.
Let's start hacking our XSL stylesheet to do something more fun...
Continue Reading »
Tags: XML, XSL
Posted in english, programming | No Comments »
Copio per realizzare la cassetta da ascoltare in macchina o da regalare alla fidanzata e nel farlo mi esprimo, creo qualcosa di mio, che mi identifica e dunque sono. Così riassumo come l'autore di questo ottimo saggio spiega come il dominio della copia sia passato col tempo dalle case discografiche al consumatore.
Il saggio in questione però parte dal principio, da quando dicendo "Vado a comprare la quinta di Beethoven" si intendeva lo spartito e non il cd, vengono toccati tutti i passaggi culturali legati alla musica e ai supporti su cui essa è stata scritta e registrata nell'arco del tempo. L'autore scrive con uno stile chiaro, molto ben documentato e per nulla pesante. A parte il titolo provocatorio, il libro in questione è un ottimo saggio che racconta della musica e dei sui supporti, dei musicisti e delle persone che hanno lavorato, inventato e amato per e grazie alla musica.
Il viaggio che Assante ci fa fare nel tempo con il suo racconto è piacevole e pervaso dell'amore che, evidentemente, lui stesso ha per la musica e per quegli oggetti che, come consumatore di musica, ha comprato, collezionato e curato. Anche la musica vista come bene di consumo viene portata allo scoperto e come essa attraverso i suoi modi di essere fruita non sia tanto "importante per la soddisfazione che può generare ma per come agisca in qualità di marchio di differenziazione socio-culturale".
Ho letto con piacere questo libro anche se, forse, non l'avrei mai comprato se non avesse avuto quel titolo un po' provocatorio e se non fosse stato pubblicato affidandosi a un sito di "self publishing" come ilmiolibro.it.
Continue Reading »
Tags: copyright, music, new media
Posted in libri | 1 Comment »
I recently solved a problem common to many heavy used web application following an idea of a friend of mine.
The problem is how to efficently manage the sessions of a web application when the number of them is high (500,000 for example) and the use of them his quite frequent (˜50,000 pages/day in my case).
A common approach is to store web sessions in a database table where the session identifier and the expiry date are indexed, but due to the fact that each time a session is used (read) is also updated (written), while the number of them grows, the time spent to update the indexes associated to the web session table grows too. The result of this situation, relatively to the hardware you use, is that to update a session the application could take 2-5 seconds: a time that is not adequate to the world wide web.
So a better solution has to be applied or better we have to adapt the databse solution to the number of sessions that has to be managed.
I don't consider my solution particulary smart, but it's very simple, effective and could easily scale...
Continue Reading »
Tags: database, PHP, web
Posted in english, programming | No Comments »
Grazie al CyBook Tour ho avuto la possibilità di provate uno dei più interessanti eBook reader basati sulla tecnologia
E Ink attualmente in commercio. L'oggetto in questione è il CyBook Gen3 (nella foto) della francesce Bookeen.
Per lavoro mi interesso eBook e per essere più precisi di ePublishing e quindi la settimana di prova che mi è stata concessa mi ha dato la possibilità di verificare alcune curiosità legate al mondo degli eBook reader di questo genere. In particolare mi sono soffermato a studiare i formati supportati e quali difficoltà si incontrano nella produzione di libri in tali formati perché siano utilmente fruibili su device di questo genere, soprattutto considerando di partire dai formati già disponibili all'interno di una produzione libraria tradizionale.
Continue Reading »
Tags: cybook, digital publishing, eBook, eReader
Posted in digital publishing, hardware | 3 Comments »
If you want to delete, for example, only .bak files throughout a directory tree you can try with the following command:
$ find . -name *.bak -exec rm {} \;
Using the same approach you can solve more complex problems. For example you can delete recursively all directories older than one week:
$ find . -mtime +7 -type d -exec rm -rf {} \;
Another example, for subversion users, could be the way to clean up a check-out directory:
$ find . -name lock -exec rm {} \;
Or a way to drop all .svn metadata directories:
$ find . -name .svn -exec -type d rm -rf {} \;
Now it's up to you to find other examples...
Tags: shell commands, unix
Posted in english, programming | 1 Comment »
La lettura attenta del saggio di Paolo Legrenzi sul credere fornisce gli strumenti per capire quando sia importante, nella nostra vita quotidiana, il credere ciò di cui non siamo siamo certi. Se non credessimo nelle cose, in noi stessi e negli altri la vita sarebbe impossibile.
Ho letto con piacere questo libro, l'ho trovato stimolante e accurato: l'autore spiega con esempi e molti riferimenti alla letteratura tutti i meccanismi del credere in tutte le sue forme.
Molto interessante l'analisi dei meccanismi attraverso i quali noi supercrediamo quando dobbiamo dare delle stime riguardo a noi, al nostro lavoro, alle nostre scelte e conoscenze. In particolare, questo supercredere lo vedo applicare da me e dai miei colleghi e collaboratori giornalmente nel lavoro che faccio (consulente software).
Immediatamente si spiega perché la realizzazione di software è spesso in ritardo rispetto alla data di consegna prevista, e perché un buon project manager deve saper applicare il giusto "moltiplicatore" di stima a finire in base alla propensione al supercredere di ciascun elemento del suo team: appliccare i giusti moltiplicatori aiuta a fare una stima complessiva più accurata.
Posted in libri | No Comments »