Tuesday, May 8, 2007

Install a PDF printer

By default, CUPS-PDF is not installed, so grab it by using sudo apt-get install cups-pdf. You should then be able to add a fake printer that will convert print jobs to PDF files. Go to System -> Administration -> Printing to bring up the Printer configuration dialog. Select New Printer from the toolbar, and walk through the New Printer Wizard. You can give the printer pretty much any name you want. PDF seems like a logical choice. The Description and Location fields are optional.

On the next screen, when asked to select a connection, choose Virtual Printer, and leave the device URI as it is: cups-pdf:/. Next, on the screen where you can select a Printer from the database, choose Generic. On the next screen, choose PostScript as the Model and as the driver for the printer. Then you'll see a screen that says "Going to create a new printer PDF at cups-pdf:/." Click Apply and you should have a virtual PDF printer.

Links of Interest

Monday, May 7, 2007

Get NetworkManager working after suspend

After going into standby mode ("suspend") or hibernation, NetworkManager might refuse to connect to your network of choice. The trick is to restart NetworkManager after standby. You will need to create two files.
sudo touch /etc/acpi/suspend.d/07-network-manager.sh
gksudo gedit /etc/acpi/suspend.d/07-network-manager.sh

Now paste the following in Gedit, save and close.
/etc/dbus-1/event.d/25NetworkManager stop

sudo touch /etc/acpi/resume.d/63-network-manager.sh
gksudo gedit /etc/acpi/resume.d/63-network-manager.sh

Now paste the following in Gedit, save and close.
/etc/dbus-1/event.d/25NetworkManager start

Links of Interest
Ubuntu wiki's NetworkManager page

Thursday, May 3, 2007

Set Up Ruby on Rails with Postgresql

To set up Ruby on Rails to work with Postgresql, do the following:
Install Ruby:
sudo aptitude install ruby rdoc irb libyaml-ruby libzlib-ruby ri libopenssl-ruby

Install RubyGems (this is an aptitude/apt-get style utility that handles ruby programs)
Get the latest version from here
wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
tar xzvf rubygems-0.9.2.tgz
cd rubygems-0.9.2/
sudo ruby setup.rb
sudo gem update --system

Install Rails using RubyGems:
sudo gem install rails -y

Install PostgreSQL:
sudo aptitude install postgresql-8.2 postgresql-client-8.2 postgresql-client-common postgresql-common postgresql-doc-8.2

Now you have two choices. You can either install a pure Ruby PostgreSQL driver for Rails called postgresql-pr (slower) or you can install the native driver postgresql.

To install the postgresql-pr driver
sudo gem install postgres-pr

To install the postgresql driver
You need to install some more packages, or the installation will fail:
sudo aptitude install ruby1.8-dev libpq-dev
POSTGRES_INCLUDE=/usr/include/postgresql sudo gem install postgres

Enabling PostgreSQL
To start using PostgreSQL under your username, you first have to create a new PostgreSQL user. After a fresh installation of Postgres, the only (Linux) user that can create databases/users is the user "postgres", so we must "login" under its name.
sudo su postgres

Now we use the createuser script to create a new user.
createuser -P

(-P means "assign password") You will be asked some questions, just answer as follows, replacing YOUR_USER_NAME with your user name (BEEP cyclic redundancy check error BEEEEP)
Enter name of role to add: YOUR_USER_NAME
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y

Now type

to become yourself again.

Your First Rails Project
When you create your Rails projects, you have to tell Rails to use your PostgreSQL database, like this:
rails my_super_duper_project -d postgresql

Now, with your new super duper project created, you must modify the config/database.yml file so that Rails knows your username and password. In that file you will find THREE (3) "paragraphs" that look like this:
  adapter: postgresql
username: YOUR_USER_NAME

Just change the password fields to match your password. Also, you can notice that there are three databases, one that ends with "_development", another one with "_test" and another one with "_production". You create these databases using the createdb script:
createdb YOUR_PROJECT_development
createdb YOUR_PROJECT_production
createdb YOUR_PROJECT_test

Links of Interest
Ubuntu wiki's Rails Page
PostgreSQL in Ruby on Rails
RubyGems download page
Glom's initial Posgres configuration page