Ellipse multiline

Aggiungere i puntini sospensivi (Ellipse multiline) alla fine di un paragrafo è cosa fondamentale.

qui un mixin sass per realizzarlo semplicemente

liberamente tratto da Martin Wolf



RcppArmadillo what a mess!

Ok lets try to setup your already under construction R package adding RcppArmadillo to it without the default RStudio project (as anyone suggests online).

Just in case you don’t know, Rcpp is an R package to import C/C++ code in R.
Armadillo is a C++ library for easy Linear Algebra handling.
RcppArmadillo is a package that depends on Rcpp package and enables to import armadillo data structures in R in a very easy way.

First of all, of corse, you have to install the RcppArmadillo package:

after a long installation, we can start to setup our R package.

Create a “src” folder in your package main directory.
Inside this folder you’ll put your C++ files structured as follow :

Each C++ function, to be exported in R, has to be preceded by an exporting declaration, so your cpp file will be something like:

Ok, now you want to document the exported function, but you don’t want to do it by hand (also because you’d lose your hand maded comments at each compilation), so we add some doxygen comments to our functions, in order to be automatically processed by roxigen2.
Note that inserting the “@keywords internal”, just as with roxygen2, you are imposing to not export this function in your R package NAMESPACE.

Ok, now the C++ compiler needs to be instructed to compile your code, Rcpp uses a file called MAKEVARS (for UNIX systems) and MAKEVARS.win for windows:

But when you want to test more than one Unix system, like Linux and OSX, you can fall in some troubles because it seems that this file depends on the system you are compiling your code.
(more in detail, clang++ (the c++ apple compiler), doesn’t support the -lopenmp flag) during the compilation phase)
To solve this problem I followed the instruction of another guy (hoping he will never delete this instructions, because I don’t want to copy and paste his work).
Of course, some instructions have to be changed if you are following my instructions, but you are a fucking coder, so it should be very easy.

I think there is an alternative way to do that, but I didn’t checked yet.
Anyway, I reccomend this CRAN link,  where it’s suggested to install the GNU fortran binaries in order to compile the package and avoid any compiling problem.

For sure following the instructions of that guy and installing the GNU binaries (without setting up in the “CRAN manner” the MAKEVARS file) everything works fine.

Now, if you have the R package “devtools”, using the “document()” or the “load_all()” functions, the code will be compiled and a new RcppExports.cpp file will appear in your src directory and, moreover, the RcppExports.R file will appear in your “R” main folder.
This files contain all the C++ exported functions, and the R file will have also your doxygen comments coverted in roxygen2 style.

At this point you can call your Cpp wrapped function in R with a call like:

The last and most important think to remember when working with matrices in C++ and R is about the indexes.

R has indexes starting from 1.
C/C++ has indexes starting from 0!

So, it’s a good idea, in case you are returning some indexes from C/C++ to R, to check them once they come back in R or before to return them back in R (I prefer the first one, because I like to leave the C/C++ code reusable in case I need it somewhere else).



Recuperare la query di un ActiveQuery

Dopo alcuni anni di sviluppo con Yii sono passato alla versione 2 del framework ed ora è finalmente possibile recuperare la query sql prodotto dall’oggetto ActiveQuery:

dove $query è un’istanza di ActiveQuery



Console.log in applicazioni Cordova

Sviluppando in Cordova/Phonegap per visualizzare i log prodotti da console.log() sul proprio dispositivo Android è necessario il seguente comando shell:

per completezza il 3 sta per “log”




JAVA_HOME e update-alternatives

Capita, almeno a me è capitato, di dover installare più versioni dello stesso software e dover passare da una versione all’altra.

per questo si usa update-alternatives.

ma se, per esempio, abbiamo due versioni di java, tali che l’esecuzione di:

dia un output del tipo:

se vogliamo che la variabile d’ambiente JAVA_HOME punti alla cartella dove si trova l’alternativa in uso, si può utilizzare questa definizione per JAVA_HOME


ricordarsi di aggiungere l’intera riga nel file ~/.bash_rc




Aggiungere File Types in WordPress

WordPress di default permette di fare l’upload solo di file di immagine, ma può capitare di dover aggiungere un file di diversa natura all’interno di un articolo.

Ad esempio nell’articolo precedente ho aggiunto il file con lo script di cui si parlava nel testo. Per poterlo fare ho dovuto aggiungere al mio file functions.php il seguente codice:

nell’esempio precedente permettiamo l’upload di file bash