venerdì 29 aprile 2011

jQuery on Rails 3

Ruby on Rails is an open source web application framework for the Ruby programming language. The last version of this framework is the 3.0.0 released Aug 29, 2010. By default, when you start a new Rails application with:
rails new my-app
by default it uses prototype as javascript framework. Now prototype isn't the best solution for all developers so you might want to use jQuery instead.
To use jQuery you need to create a new rails application with the following command instead:
rails new my-app -J
notice the "-J" option that skips the creation of the prototype files in the new app.
Now you have to download jQuery from its website and put the jquery-x.x.x.js file inside the public/javascripts folder of your application.
Now download the file rails.js from http://github.com/rails/jquery-ujs and put it inside the public/javascripts folder too.
Now you need to add a reference to jQuery inside the application layout. To do so, open the file app/views/layouts/application.html.erb and add the following code:
<%= stylesheet_link_tag 'jquery-ui-1.8.5', 'scaffold' %>
<%= javascript_include_tag 'jquery-1.4.3', 'jquery-ui-1.8.5', 'application' %>
You're done! Now you can use Ruby on Rails with jQuery.
Happy coding!

giovedì 28 aprile 2011

Basic GIT configuration

Git is a distributed revision control system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development. Once you installed Git, you may configure some basic parameters like username, email, ecc. To do so you can use the following commands:
Set the username:
git config --global user.name "pinco pallino"
Set the user email:
git config --global user.email "foo.bar@somehost.com"
Enable the ui color option:
git config --global color.ui true
Hope this helps

martedì 26 aprile 2011

How to start/stop/restart delayed_jobs from the command line

Delayed Jobs is a background processing tool written in ruby. When you use it inside a Ruby on Rails application, usually you start it with:
rake jobs:work
If you need to start delayed jobs from a Capistrano task or from a monitoring framework like God, you should use the following commands.
To start:
script/delayed_job start
To stop:
script/delayed_job stop
To restart:
script/delayed_job restart

Hope this helps.

mercoledì 20 aprile 2011

How to enable WebGL support in Firefox 4 (Linux)

WebGL is a Web-based Graphics Library. It extends the capability of the JavaScript programming language to allow it to generate interactive 3D graphics within any compatible web browser.
To enable WebGL support in firefox 4 using Ubuntu 10.04 you have to install the library libosmesa6 with the following command:
sudo apt-get install libosmesa6
After this start up firefox and in the url bar type:
about:config
and press enter. Say ok to the alert message and in the search box type "webgl". Double click on "webglosmesalib" parameter and enter the library path (like in the screenshot below).
Enabling Firefox 4 WebGL support.

For me it's:
/usr/lib/libOSMesa.so.6
Now quit and restart Firefox and WebGL support shoul be active.
Enjoy!

mercoledì 6 aprile 2011

How to remove all Rubygems inside a RVM gemset

The only way to uninstall all the gems inside a RVM gemset is to use the following command:
$ rvm use 1.9.2@my-gemset
Using /home/user/.rvm/gems/ruby-1.9.2-p180 with gemset my-gemset
$ gem uninstall gem1 gem2 gem3 ...
A bit boring, don't you think? A way to automate this process is through the following command:
gem uninstall `gem list | cut -d" " -f1 | tr '\n' ' '`
If you don't use RVM to manage different Ruby versions, maybe you have to change the command above in something like this:
sudo gem uninstall `sudo gem list | cut -d" " -f1 | tr '\n' ' '`
Pay attention to copy all the "`" characters.
In this way you can uninstall all the gems only with one command.
Hope this helps :-)

giovedì 20 gennaio 2011

Wake on lan con Ubuntu

Certe volte può essere necessario accendere da remoto un pc collegato alla nostra rete LAN. Per fare ciò è necessario anzitutto abilitare il pc che vogliamo accendere a fare il boot qualora esso riceva un particolare segnale sull'interfaccia di rete.
Entriamo quindi nel bios e cerchiamo qualcosa di simile a: "Remote wake up", oppure "Wake on lan" e abilitiamolo come mostrato nell'immagine che segue.
A questo punto è necessario conoscere il MAC address (indirizzo fisico) dell'interfaccia di rete del pc che vogliamo accendere. Se il pc in questione ha ubuntu, possiamo reperire tale dato con il comando:
ifconfig
Generalmente l'interfaccia che ci interessa ha come nome eth0 e l'indirizzo MAC è quello presente alla voce "HWaddr". Se invece stiamo usando window$, possiamo dare da terminale il comando:
ipconfig /all
Il dato che ci interessa è sotto la voce "Indirizzo fisico".
Segnamoci il dato e passiamo ora ad Ubuntu.
Installiamo il pacchetto wakeonlan a meno che non sia già installato con il comando:
sudo apt-get install wakeonlan
Fatto ciò sempre da terminale diamo il comando:
wakeonlan 11:22:33:44:55:66
dove ovviamente 11:22:33:44:55:66 sarà l'indirizzo MAC del pc che intendiamo accendere e il gioco è fatto. La risposta del programma sarà la seguente:
Sending magic packet to 255.255.255.255:9 with 11:22:33:44:55:66
e vedremo come per magia il pc accendersi automaticamente.

martedì 18 gennaio 2011

Traduzione in italiano della label "Algorithm" in LyX

Durante la stesura di un documento in LyX, sia essa una semplice relazione, oppure una tesi, può capitare di dovere inserire il listato di un programma. Per fare questo si seleziona il menu Inserisci > Oggetti flottanti > Algoritmo. Dall'interno della nuova area creata, selezioniamo quindi la voce listato di programma dal menu Inserisci e si procede alla scrittura del codice che ci interessa e dell'eventuale didascalia.
Procedendo poi con la compilazione, scopriamo l'amara sorpresa: nel file .pdf generato, la label è in inglese!
Listato di esempio con label in inglese.
La soluzione del problema è più semplice di quanto si possa pensare. Andiamo nel menu Documento > Impostazioni e nella nuova finestra selezioniamo dalla parte sinistra la voce Preambolo di LaTeX. Nella parte destra della finestra possiamo inserire il nostro preambolo LaTeX personalizzato. Inseriamo quindi il seguente codice:
\usepackage{algorithmic}
\floatname{algorithm}{Listato}
In questo caso ho scelto di sostituire la parola "Algorithm" con "Listato" perchè la ritenevo più adeguata alla trattazione del documento che stavo scrivendo. Naturalmente la scelta è del tutto soggettiva ed è sufficiente modificare il contenuto dell'ultima coppia di parentesi graffe per adattare l'output di LyX alle proprie necessità.
La soluzione al problema della label.
Facciamo quindi click su Applica e poi su Chiudi. A questo punto proviamo a compilare nuovamente il file e a generare il pdf per verificare il risultato ottenuto.
Listato corretto con label in italiano.
Il problema è causato dal fatto che la traduzione in italiano di LyX non è completa al 100%. In ogni caso, per tradurre anche altre label che si comportano allo stesso modo (Teorema, Lemma, ecc...), il tipo di approccio da adottare è sempre lo stesso.