Tag Archive for 'tutorial'

Using PostgreSQL With Ruby on Rails on OS X

Following on from my last post for getting PostgreSQL up and running nicely on Mac OS X, my next task was getting it playing nicely with ruby on rails - I’m off on a rails course next week so I’m getting stuff ready. :)

It appears that there is currently two/three gem packages for using postgresql with ruby: postgres, ruby-pg, and pg - and from what I can make out, they’re all maintained by the same team now, (postgres was the original package, but it got abandoned - ruby-pg and pg are the replacements). As such, i’ll go with the newer ruby-pg gem…

sudo env ARCHFLAGS="-arch i386" gem install \
 ruby-pg -- \
 --with-pgsql-lib=/opt/local/lib/postgresql83 \
 --with-pgsql-include=/opt/local/include/postgresql83

Then finally, when writing the database.yml entry for connecting to postgresql, we have to define our adapter as follows:

development:
  adapter: postgresql
  database: test_dev
  encoding: unicode
  host: localhost
  user: XXXXX
  password: XXXXX
  timeout: 5000

Install PostgreSQL on Mac OS X Leopard

This type of guide is all over the internet, but I’m too lazy to search for one every time I want to do this. ;) So here’s a brief overview of how I got PostgreSQL set-up nicely on Mac OS 10.5…

Setting Up Our Environment

Using a text editor of your choice, add the following lines to the bottom of the /etc/profile file (you’ll need to be an administrator to do this):

# MacPorts
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
 
# PostgreSQL
export PATH=/opt/local/lib/postgresql83/bin:$PATH

Now before we move on, make sure that you have MacPorts installed.

Continue reading ‘Install PostgreSQL on Mac OS X Leopard’

Sync Your Things Database via Dropbox

Dropbox is a great service, I’m using it happily to keep my files in sync across multiple computers - I’m even using it to keep all of my passwords in sync, but I’ve thought of another great use… How about syncing my Things database between my macs (as this is my to-do list manager of choice)?

This is not fully tested yet, (just thought of it this morning) so i’ll update a bit later and report on as to wether things goes completely mental, but the way I’ve done this is as follows…

Make sure Things is completely shut down, then open up a terminal and type in the following commands:

cd ~/Library/Application\ Support/Cultured\ Code/

This moves us into the correct directory. First, to be on the safe side - we’ll take a backup of our files…

cp -R Things Things.bak

Now just move the Things directory into your dropbox and create a symbolic link in its place.

mv Things ~/Dropbox/
ln -s ~/Dropbox/Things Things

Fingers crossed this should have the desired results! :)

Update: It works!!! :D On the second computer all you need to do to get the ball rolling is to close down Things, open up a terminal and type the following commands:

cd ~/Library/Application\ Support/Cultured\ Code/
rm -rf Things
ln -s ~/Dropbox/Things Things

Note - my 2nd mac only had a fresh install of Things - no data. I installed it, opened it up (so the initial database was created), then did the above.

SSH Shared-Key Setup - SSH Logins Without Passwords

SSH is a great tool for remotely accessing another machine, but entering your password every time you log into a remote box can be a pain if you would like to set-up some background scripts to connect to a server and do something (i.e. a backup script running as a cron job). Here’s how I set-up my Mac to be able to log into my server without the need for a password to be entered each time - the instructions should be good for any variant of Unix/Linux, but you need to take into account path names etc. on your machine.

Continue reading ‘SSH Shared-Key Setup - SSH Logins Without Passwords’

A Better Ls for Mac OS X

I’m a bit of a command-line freak and like to spend a fair amount of time with the terminal open… As such I like to spend a small amount of time getting the terminal set-up nicely. Other than changing the default colour scheme and font, one (slightly) more drastic change is to replace the standard implementation of ls for one that is slightly more configurable.

The default ls on OS X comes from BSD and compared to the GNU/Linux alternative is slightly lacking when it comes to comes to changing how things look - so what I like to do is replace it with the GNU ls available in MacPorts - this allows me to get a terminal setup like below:

terminal.png

Continue reading ‘A Better Ls for Mac OS X’

CSS Styled Tables

Veerle comes up with another look at styling tables with CSS. A great read.

In 2005 I wrote an article about styling a table with CSS. After receiving so many requests I finally decided to give in and write another tutorial. Seems like a popular topic and an interesting one to share some tricks on how you can nicely style them. This article is about the proper usage of tables, for tabular data. How you can implement them with accessibility in mind and how to make them appealing for the eye using CSS.

read more

(0)

Install phpPgAdmin on Ubuntu 7.10

Update: These instructions have been tested and work fine in the latest version of Ubuntu (8.04, Hardy Heron).

phpPgAdmin is a web based GUI for administrating a PostgreSQL database server.

Here’s some quick notes on getting it installed easily on Ubuntu 7.10…

In the terminal enter the following:

$ sudo apt-get install phppgadmin

This will set up and install all of the phpPgAdmin packages. It will also set-up and configure Apache and php5 for you too if you haven’t installed these already.

Next we need to create a symlink to phpPgAdmin so that Apache can find it:

$ sudo ln -s /etc/phppgadmin/apache.conf /etc/apache2/conf.d/phppgadmin.conf

Now if you navigate to http://localhost/phppgadmin you should be greeted with the phpPgAdmin screen. If your user account has a PostgreSQL account however, you will be logged in automagically.

Optionally, if you would like to be able to use the phpPgAdmin interface as the default ‘postgres’ administration account,1 you will need to do the following2

$ sudo gedit /usr/share/phppgadmin/conf/config.inc.php

Now find and change the following line

$conf['extra_login_security'] = true;

to

$conf['extra_login_security'] = false;

Save and close gedit. Now all you need to do is restart Apache.

$ sudo /etc/init.d/apache2 reload

Now if you head on over to http://localhost/phppgadmin all should be ready for you.


  1. I am assuming here that you have set-up your PostgreSQL server using my set-up instructions and therefore have a password protected ‘postgres’ account and that logins require passwords. 

  2. Please make sure you have read the above footnote and understand the security implications of allowing this type of access to your database server - if you have not secured your administration accounts, do it now! 

Creating New Accounts in PostgreSQL

Getting a new account set up on PostgreSQL is a simple process…

Create our new user:

$ sudo su postgres -c createuser daz

Then you have to give this new user role a name (I called it daz), and then say ‘y’ to the question “Shall the new role be a superuser?” if you want the user to be an administrator.

Give the user a database password (this does not have to be the same as their unix password):

$ sudo su postgres -c psql
postgres=# ALTER USER daz WITH PASSWORD 'mypassword';
postgres=# \q

Finally, give the new user a database to play with:

$ sudo su postgres -c createdb daz

Pretty straight forward… :)

Install PostgreSQL on Ubuntu 7.10

If you are using the latest version of Ubuntu (8.04 - Hardy Heron), you might find these slightly updated instructions useful.

This quick walk-through are my notes for installing the PostgreSQL database server and the PgAdmin administration application on Ubuntu Linux, and also set up the server so it allows access to other PC’s on your network.

Before we move on, this guide was tested on the current release of Ubuntu Linux, (7.10 - Gutsy Gibbon) and PostgreSQL 8.2, but it should also be applicable to older versions (of Ubuntu and PostgreSQL) and other Debian based distros.

Continue reading ‘Install PostgreSQL on Ubuntu 7.10’

Adding/Deleting Rows in TableKit Tables Revisited

TableKit is a great javascript library for making your HTML tables fully editable. However, one problem is that you can’t add or delete rows from the tables…

I came up with a solution to this not so long ago, but it still had a problem - TableKit caches the tables on loading, so after we update the table body (adding or deleting a row) the sorting and editing of the table is completely screwed! :( However, with a little more work, and some help from one of the guys in the office - we’ve finally got this cracked! :)

Continue reading ‘Adding/Deleting Rows in TableKit Tables Revisited’