Archive for the ‘Uncategorized’ Category

Getting started with PostgreSQL when developing Rails applications

Friday, May 7th, 2010

If you’re familiar with MySQL and trying out PostgreSQL for the first time while doing some Ruby on Rails development, things can initially seem quite unfamiliar. A great first article to look at is available on the OLM on Rails site at Switching Rails to PostgreSQL. Also at this early stage in your PG career you’ll need to know how to change things like user passwords so check the Examples section of the PostgreSQL Alter User docs.

Ok, after that you should know how to create a database in PostgreSQL, hook up to a Rails app and run migrations. Once that’s done, you’ll need to be able to do the same things that you were able to do in MySQL in the psql shell. Here’s the first commands you need…

  • typing ‘help’ displays help at any time
  • \? displays help with psql commands
  • \l lists databases
  • \c some_database connects to a database
  • \c with no argument tells you what database you’re currently connected to
  • \ds lists schemas within the currently selected database. A schema is simply a namespacing of tables within a given database
  • \dt lists tables in the currently selected database
  • \du lists all postgres database user accounts (more detail here)

Here’s  a list of good of stuff…

Doing Raw MongoDB Queries when using MongoMapper with Rails

Tuesday, May 4th, 2010

Even though, you’re using MongoMapper with Ruby and Rails, you may sometimes want to do queries using the Mongo database itself. Here’s how I do it (note: there may be a better way, please post a comment).

# Getting at the mongodb instance
MongoMapper.database

# Listing its collections
MongoMapper.database.collections

# Get at any collection while within any model (note: returns a Mongo::Cursor)
coll = MongoMapper.database['questions'].find({})

# Convert that collection to an array (useful!)
coll.to_a

# Display a collection (note: ‘each’ does an implicit ‘to_a()’)
MongoMapper.database['questions'].find({}).each {|x| puts x.inspect}

# In the Question model you can use this shortcut
# collection to get at the questions collection
collection.find({}).to_a

Hooking up a laptop to a projector using Nvidia Twinview on Kubuntu

Monday, March 29th, 2010

UPDATE 1: As far as it can be confusing as to whether Nvidia Twinview is changing the underlying resolution of your display. Here’s some tips that may help

  • Adjust the resolution ***before*** you hook up your laptop to a projector
  • If you adjust the resolution and it doesn’t look like what you would expect (eg. the bottom half your display is missing) then logging out and back in may help

UPDATE 2: I found that adjusting the display settings using a tool other than Twinview helped (in KDE on OpenSuse 11.2 I found that searching for sax2, a part of YaST, let me change my screen resolution without problems – once I dropped the screen resolution to be the same as the resolution of the projector then I didn’t need to mess around with Twinview at all).

Here is the rest of the original article…

The number of configuration options can be a bit daunting when you haven’t used Nvidia Twinview before. Here’s a quick simple recipe

* Set both the laptop screen to be the same as the maximum supported resolution of the projector (you can use the ‘Model’ dropdown list to choose between settings for the laptop and the projector). If you set the of the project to Auto and click apply the diagram should tell you the max supported resolution for the projector
* Ensure position is set to Absolute for both the laptop and the projector
* You can drag the actual boxes representing each screen in the diagram but the best thing to do is ensure they overlap as much as possible
* Finally click Apply and you should get a pretty good match. You may still need to resize the window you want to show in order to get the projector fully displaying it

ossdev-ireland: A new Irish Open Source Developers Group

Monday, January 18th, 2010

ossdev-ireland is a group set up to act as a melting pot for the various different Open Source groups in Ireland.

Many group mailing lists already exist in Ireland for individual technologies, development languages and frameworks. However, each community is sandboxed into its own world. As a result there is less chance for cross-pollination of ideas between FOSS technologies, communities and individuals. The ossdev-ireland mailing list is to augment the existing mailing lists as a place to share ideas across the entire Open Source development community in Ireland.

In particular, it would be great to see the outcomes of code jams, bug triage sessions, or even links to slides that were presented at a group meetup, posted here. You never know who may be interested!

So if you want to browse or join ossdev-ireland, please visit us at http://groups.google.com/group/ossdev-ireland

Qt Programming Tips

Saturday, January 16th, 2010

This is a little more of an unusual blog post. It’s going to simply house a slowly growing list of Qt tips over time. Here goes

* Qt has the concept of models baked in. Usually you will only want to use them if you have a list of records involved. So let’s say you have a list of contacts like in an address book then this could be encapsulated in a QAbstractTableModel. If you just want to display a record in one-off fashion you can just populate a bunch of form fields (such as QLineEdits).

Offline Documentation for Rails (and other Ruby gems)

Thursday, November 12th, 2009

I used to pretty much always install gems with the –no-ri –no-rdoc options to speed up installation. Recently however, I’ve found myself needing to get access to documentation whilst on the move. So just in case you don’t know how that works, here’s the deal.

* Install your gems as per normal (ie. don’t use –no-ri or –no-rdoc)
* Run the command ‘gem server’ from the command line
* Browse to http://localhost:8808
* And voila! You should have all the docs you need available by clicking on the rdoc link for any given gem
* But if you really want to get fancy check out the searchable Rails documentation at http://railsapi.com – there’s an online version as well as the downloadable (the links are at the top of the page and can easily be mistaken for an advert!)

Audacity Tip of the Day – How Not to Lose Data!

Saturday, September 19th, 2009

One issue when editing audio, is copy and pasting a section of a track from one open Audacity project to another. To save space audacity does not copy the underlying track completely to the new project, rather it links to it. This means that your second project (the one you are pasting into) is not completely self-contained as it depends on external files. This can be a quickfire way for the unsuspecting podcaster to lose a whole bunch of data (yes, me!). This problem is particularly nasty as you don’t realise something has gone wrong until you close and reopen the project – finding that a long stretch of audio containing your beautiful voice is missing. To avoid this, adhere to the following workflow when copy and pasting from one project to another.

* In the first project, select and copy the audio you wish to duplicate
* Paste the audio into the second project
* In the File menu of the second project, click ‘Check Dependencies’
* Click ‘Copy All Audio into Project (Safer)’
* Just to stress the previous point, you really do want to use the Safer of the two copying options. I’ve found that using the other option results in some of the audio I wanted to copy being truncated

* Save the project

By following this workflow you should hopefully avoid seeing what I call the ‘dreaded blue flat-line of death’ where, on reopening of a project, you find that the middle of a track has been lost. If you adhere to these instructions you should also be able to select ‘Delete orphaned files’ when it appears from time to time while reopening an Audacity project. However, due to the frustrating and sensitive nature of audio loss issues, I accept no responsibility for anything that goes wrong! Best of luck and happy editing!

5 Apache Troubleshooting Tips for Friday

Friday, February 20th, 2009

1) When you browse all your hosted sites and they’re all down then there’s a good chance Apache is too. Do a ’sudo /etc/init.d/apache2 restart’ and pay special attention to see if the ‘fail’ message appears. Not sure if you get as good an indication that the server is ‘ok’ if you just do the more graceful ’sudo /etc/init.d/apache2 restart’

2) It goes without saying but check your log files, especially the error.log file at /var/log/apache2

3) Under /etc/apache2/sites-available/my_cool_website.com, ensure that any custom ErrorLog’s or CustomLog’s you have set actually exist on disk – or else apache may fail to restart

4) Restart, restart, restart! When you enable sites or modules try not to forget to restart apache. It easy to change a setting such as the server url of your site in a sites-available file and forget the all import restart. You’d think I did this before!

5) When you migrate servers don’t forget to set your application or site directories to the appropriate user. This is distro specific; on Red Hat and Cent OS this is ‘apache’, on Ubuntu this is ‘www-data’. Others could be different again.

Bonus tip: Apache comes with mod_rewrite installed but not enabled. If you need it, be sure to enable it using a ’sudo a2enmod rewrite’ and ya, you guessed it, restart apache!

Site Outage – 19th Feb 2009

Thursday, February 19th, 2009

Hi folks! The (hardworking) Irish Penguin has just been resolving some issues that led to a site outage last night due to a server migration that almost went smoothly! Apologies if it led to any inconvenience. All it takes is one little misplaced command!

The outage has been resolved and will keep you posted if I notice any other issues.

Happy hackin!

Recording Sound in Kubuntu 8.10 (running KDE 4.1)

Sunday, September 14th, 2008

Exciting times ahoy! This weeks mystery was to get sound recording with the minimum of fuss. We’re not sure what soundcard is running inside the Dell Inspiron 1520 which was our test laptop but it seems to report itself as an HDA Intel SigmaTel STAC9205 in the system settings. Anyway, the first thing to do was to apt install audacity which can then be used for testing the recording functionality. Not being sure if the laptops builtin in mic had been detected correctly, we jacked in an external microphone into the mic socket.

This didn’t produce any encouraging results initially when we tried recording in audacity so we opened up the KDE volume controls by clicking the speaker icon on the taskbar and electing to open the mixer. Unfortunately the GUI controls for the mixer doesn’t have the full complement of volume controls so it was the good ol command line to the rescue – typing alsamixer in terminal brings up a nice range of controls. You can navigate between screens of controls with the tab key and jump from control to control using the left/right arrow keys. The trick was to navigate to the two controls marked ‘Capture’ and bump up the volume (they also need to be activated by pressing the spacebar when you’re on the control). Additionally, there were two controls marked ‘Digital’. One of these controlled the volume of the mic (via the up and down arrows) and the other switched between analog and digital mode (again via the up and down arrows). We found that the latter had to be set to ‘Analog I’ for the best result.

Then it was back to audacity to record a bit of chatter – and then lament how weird ones voice sounds when recorded! Now get mixing mon amis!

QUICK UPDATE (14 Sep 08)
One issue that occurred was that after recording a sample, it couldn’t be played back(“Error while opening sound device. Please check the output device settings and the project sample rate.”). Additionally, a second track couldn’t be recorded. The solution to these problems was to open the Preferences dialog and set both the Playback and Record devices to ALSA (default). Reference: http://audacityteam.org/forum/viewtopic.php?f=18&t=3377