sabato 23 luglio 2011

Ignore a word in a regular expression

Today a friend of mine asked me a tricky regexp related question: he wanted to match against a set of strings like:

WORD_FOO
WORD_BAR
WORD_FOOBAR
WORD_QUUX
WORD_FAR

He did want to match and store any string starting with WORD_ and followed by a valid word, unless it was FOO. So it should match all the aforementioned lines but WORD_FOO.

Tricky.

He was using something like /^(WORD_[^\s]+)$/, so I suggested using [^\s|VERSION] (I did wake up only a few moments before), but of course that doesn't work, since it would exclude all strings containing the characters V, E, R, S, I, O, N.

It took me some digging, but finally I found this answer on StackOverflow that documents the use of negative look-arounds.

Using these constructs I managed to get this regex: WORD_((?!FOO\W)\S+) that satisfies the requirements (you can check it on Rubular).

How does it work?


(?!FOO\W) checks the next characters of the string. If they DON'T (!) contain the word FOO followed by a non-word (whitespace, etc) character (\W), then the matching will be made against \S+ (one or more non whitespace characters). So you'll get the second part of the word in your \1, $1, etc.

If you want to ignore all sub-strings starting with FOO, you can get rid of that \W.

mercoledì 20 luglio 2011

Good tip on better font rendering in Fedora

I just finished reading this good tip on how to obtain better font rendering on Fedora.

Results are good, so I just wanted to share the link :)

martedì 19 luglio 2011

OTRS Apache + mod_perl configuration on Debian/Ubuntu

In protest against Google censorship of Blogger blogs in some countries, this post has been moved to Wordpress.

Questo post è stato spostato su Wordpress in protesta contro la censura applicata da Google su richiesta dei governi di alcuni paesi.

lunedì 18 luglio 2011

Find and download VirtualBox guest additions ISO for Fedora 15

RPMFusion release of VirtualBox doesn't bring VirtualBox guest additions ISO, so you're off to download it yourself.

The ISO is available from the official site download section, just go to the folder of your version and look for the VBoxGuestAdditions.iso file.

domenica 17 luglio 2011

Running an external process from Ruby

Running an external process from a Ruby script is quite easy: use backticks (output = `command`) or the %x method (output = %x[command]).

There are more options like system and exec and even more advanced ones like popen, popen3 and popen4 that allow you to manage process stdin/stdout/stderr.

A good resource with more examples is Nate Murray's 6 Ways to Run Shell Commands in Ruby.

mercoledì 13 luglio 2011

Find packages starting with a string with apt or aptitude

Searching for packages with apt-cache or aptitude is quite easy, but what if we want to find a package name starting with a specific string?

With apt-cache:

$ apt-cache search mysql | grep '^mysql'
mysql-cluster-client - MySQL database client (metapackage)
mysql-mmm-agent - Multi-Master Replication Manager for MySQL - agent daemon
mysql-mmm-common - Multi-Master Replication Manager for MySQL - common files
mysql-mmm-monitor - Multi-Master Replication Manager for MySQL - monitoring daemon
mysql-mmm-tools - Multi-Master Replication Manager for MySQL - tools


With aptitude:

$ aptitude search ^mysql
p   mysql-admin  - GUI tool for intuitive MySQL administration
p   mysql-client  - MySQL database client (metapackage)                              
v   mysql-client-4.1  - 
p   mysql-client-5.1  - MySQL database client binaries
i A mysql-client-core-5.1  - MySQL database core client binaries
[...]

domenica 10 luglio 2011

JMeter e il load testing che vorrei

Questo è un rant. Ve lo dico subito, così potete non leggerlo.

In questo post voglio lamentarmi di JMeter, non perché sia un cattivo strumento di load testing, anzi, è sicuramente il migliore del panorama open. Il problema è che non è abbastanza.

La complessità delle web application moderne è tale che i test di carico basati su banali sequenze di URL richiamate in serie non garantisce affatto un risultato credibile.

Un tool moderno dovrebbe essere in grado di generare "modelli di comportamento degli utenti", in modo da poter testare carichi reali delle web app, sia partendo da una singola navigazione (con analisi dei possibili comportamenti applicabili in una pagina), sia estrapolando i modelli da log già esistenti di utilizzo. Inoltre, dovrebbe permettere di emulare automaticamente i comportamenti del browser riguardo al caricamento di immagini, css, js, etc. Ad esempio:

  • l'utente effettua il login alla webmail (load della pagina di login e tutti gli elementi correlati, chiamata POST per il login, caricamento dell'interfaccia della webmail e relativi elementi correlati)
  • l'utente controlla la inbox e clicca su uno dei messaggi (chiamata GET o AJAX per spostarsi alla visualizzazione del singolo messaggio)
  • l'utente risponde al messaggio (ancora, chiamata GET o AJAX per caricare l'interfaccia di composizione del messaggio; all'interno di tale interfaccia potrebbero essere presenti altre chiamate al server, ad esempio per l'auto-completion nel campo degli indirizzi)
  • l'utente invia il messaggio di risposta, viene ricaricata la inbox (chiamata POST o AJAX che implica anche un test di carico per il server di posta, chiamata GET o AJAX per ricaricare la inbox)
  • l'utente effettua il logout (chiamata GET o AJAX, caricamento della pagina di saluto)

Il tool, sostanzialmente, dovrebbe essere in grado di ricostruire le interfacce tra i vari elementi della web app e permettere di costruire i modelli di comportamento senza tener conto dell'implementazione spicciola, ma lavorando su concetti più ad alto livello.

Poi, per replicare un carico reale della piattaforma, si potrebbero creare diversi gruppi a cui applicare diversi comportamenti (ma questo si può già fare con JMeter).

Con una base del genere, poi si potrebbe iniziare a sperimentare sul serio, per misurare le prestazioni del sistema in casi che ancora non si sono verificati (es. pubblicazione in homepage di qualche grosso portale ed "effetto slashdot", pubblicazione di una news "virale" o vero e proprio attacco virale (facebook worms) alla piattaforma per cui la condivisione tra utenti cresce esponenzialmente, etc).

domenica 3 luglio 2011

Google+, Android, la pervasività del social

Da quando ho questi aggeggi Android, ho usato i servizi di Google molto più di quanto avessi mai fatto prima. E' strano, per me, perché non amo molto Google, né il cloud. Il cloud non lo amo per nulla, in effetti.
Almeno com'è implementato ora.

Mi piacerebbe - e forse, chissà, col tempo ci arriveremo - poter scegliere separatamente infrastruttura e servizi, per esempio. Vorrei poter scegliere di usare Google+, ma salvare le foto su Flickr. Oppure Smugmug. O, ancora, in raw su Amazon S3 o Dropbox.

Vorrei poter leggere i feed (magari anche offline, grazie alle funzionalità di HTML5) e salvare i bookmark su un servizio di mia scelta, non necessariamente usando Google Reader e Google Bookmarks. Per esempio, io ora uso Fastladder per aggregare i feed e una installazione di scuttle su un server privato per salvare i bookmark.

Sarebbe bello se ci fossero delle API aperte (W3C? Mi senti?) per permettere ai vari servizi di scambiarsi i dati e migrarli quando IO lo decido. E se un giorno volessi togliere tutto? Facile, farei un backup dello storage (Amazon S3? Dropbox? Ubuntu One?) e poi cancellerei tutto.
Milioni di broken link :)
(e di oggetti storati nella cache di Google o salvati su altri milioni di hd nel mondo)

Ormai sono anni che si parla di Semantic Web come di quello che sarà il Web 3.0, ma forse sarà la standardizzazione del cloud e dei servizi che su di esso si appoggiano a costituire il prossimo passo.

Mount an Android Honeycomb device under Linux

So, Android Honeycomb only uses the MTP protocol for the USB connection. Linux has decent support with mtpfs, and the instructions are quite easy to follow (this article is based on that one).

First of all, after installing mtpfs, create a new directory (I'm using transformer since I own an Asus Transformer, feel free to use whatever you want):

$ sudo mkdir /media/transformer
$ sudo chmod 755 /media/transformer
$ sudo chown your_username:root /media/transformer

Then edit /etc/fstab

$ sudo vim /etc/fstab

And add:

mtpfs  /media/transformer  fuse  noauto,users,umask=033,allow_other  0 0

Save, exit, then mount

$ sudo mount /media/transformer 

Important: umount the device before unplugging, or you risk corrupting the filesystem.