Davide Targa website

Programming, web development and open source

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:
1
$ git config --global user.name "Your Name"
  • Set the user email:
1
$ git config --global user.email "foo.bar@somehost.com"
  • Enable the ui color option:
1
$ git config --global color.ui true

Hope this helps

Manage Delayed Jobs From 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:

1
$ 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.

Remove All Gems Inside a Rvm Gemset

Sometimes you may need to uninstall all the rubygems inside a gemset.

The problem is that the only way to uninstall all the gems inside a RVM gemset is to use the following command:

1
2
3
$ 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?

Ubuntu Wake on LAN

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.

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"

Send a Dynamically Generated File in Rails 3

Sometimes can be useful to send a file to the user instead of rendering a page. When you have a fixed location for the file you simply achieve this with a link to the file inside the view, but there may be some cases in wich you have to dinamically generate the file to send. To do this you have to add a new custom action to the controller wich you want to add the download to. In this example let’s suppose to have a simple blog application where the user can download the content of a post in text format.

PUF: A Wget-like Url Fetcher

PUF stands for parallel url fetcher is a beautyful download tool for UNIX-like systems. It is similar to GNU wget, but with puf you have the ability to download many files in parallel.

Case Insensitive Validation in Rails 3

The default uniqueness validation (using sexy validations) in Rails 3 is case sensitive. This is not always a good thing.

For example if you wrote the following class, with the following validation:

1
2
3
4
Class User < ActiveRecord::Base
  validates :username, :presence => true, :uniqueness => true
  ...
end

these usernames will pass the validation and will be stored in the database:

1
foo, Foo, fOo, fOO, ...

To avoid this problem you should make a change to the previous model in order to make the uniqueness validation case insensitive. To achieve this you have to pass an hash of parameters to the uniqueness validator. The new code may look like this:

1
2
3
4
Class User < ActiveRecord::Base
  validates :username, :presence => true, :uniqueness => {:case_sensitive => false}
  ...
end

Hope this helps :)

Install Rvm on Ubuntu

RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems. Let’s see how to install it!

Installing Aptana Studio 3 on Ubuntu

Aptana Studio is an open source integrated development environment (IDE) for building Ajax web applications. It includes support for JavaScript, HTML, DOM, and CSS with code-completion, outlining, JavaScript debugging, error and warning notification and integrated documentation.

If you install the plugin version of the Aptana Studio IDE on an existing installation of eclipse done by the official ubuntu repository, the installation procedure may not work. To solve this problem you must install a few packages through the command line or through Synaptic.