Archive for September, 2009

Getting Drupal 7 (development snapshot) running on Ubuntu

Monday, September 28th, 2009

Notes before starting

  • At time of writing, only experimental snapshots of Drupal were available with the actual Drupal 7 release being some way off. The Drupal 5.x or Drupal 6.x series is recommended if you want to use Drupal in production
  • This guide was written against Ubuntu 8.04
  • This guide assumes
    • You have apache, mysql and php happily installed on your machine
    • That you are serving websites out of /var/www/
    • That that sites under /var/www/ are accessible in your browser via http://localhost/

Instructions

  • Download Drupal 7 from the development release section at and http://drupal.org/project/drupal
  • Extract the folder and rename the extracted folder to drupal7
  • Move the folder to an appropriate place on your webserver, such as under /var/www/
  • Create a fresh settings file for your new Drupal 7 site. You should use the supplied settings file as a basis, eg.
    • cp sites/default/default.settings.php sites/default/settings.php
  • Make the settings file writeable, so that the installer can edit it, using
    • chmod a+w sites/default/settings.php
  • Create a database for your Drupal 7 site
    • Log into mysql, eg.
      • mysql -uroot -p
    • Create a database once logged into mysql from the ‘mysql>’ prompt, eg.
      • create database drupal7;
    • Create a user for the database and grant permissions from the ‘mysql>’ prompt, eg.
      • GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON drupal7.* TO ‘drupal7user’@'localhost’ IDENTIFIED BY ‘drupal7password’;
  • Run the install script as follows
    • Browse to your new Drupal site at http://localhost/drupal7/install.php
    • Elect to proceed with a normal Drupal install (ie. not minimal) in your chosen language
    • As you proceed through the wizard, the installer may encounter issues creating certain directories for Drupal on the file system. If so, ensure then do the following
      • cd to the root of your drupal7 directory
      • mkdir sites/default/files
      • mkdir -p sites/default/private/files
      • mkdir sites/default/private/temp
      • Change the ownership of the created directories to belong to user account under which the web server runs under (www-data)
        • chown -R www-data:www-data private
        • chown -R www-data:www-data files
    • The wizard now asks you to configure the database settings. In the form presented by the wizard, replace the user ‘admin’ with the ‘drupal7user’ you created earlier and point at the drupal7 database. Remember to put in the correct password for ‘drupal7user’
    • If you get a 500 error in the last step, then ignore it and elect to continue through to the error page. This will actually let you continue the install
    • If you get the error starting with something like “Fatal error: Allowed memory size of 16777216 bytes exhausted” then allocate Drupal more memory in the settings file (see See http://drupal.org/node/90605 for more information), eg. Add the line
      • ini_set(‘memory_limit’, ‘30M’);

Hopefully now you should be good to go!

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!

Open Letter to the Irish Government on Open Source Driven Innovation

Friday, September 18th, 2009

“Recent years show that openness and collaboration is essential to the generation of innovation in the software sector. Technology increasingly means software. In Ireland, we can see that the production of hardware technology in many, but not all, cases is providing ever diminishing returns. Here we outline some key policy recommendations that are crucial to the fulfilling the vision of making the Irish Smart Economy a reality for the software industry through the adoption and encouragement of Open Source technologies.”

The above extract is from a paper we are submitting to the Innovation Taskforce as requested by the Department of Taoiseach. The draft paper is available at Positioning Ireland as an International Innovation Hub

Please note, we are submitting the paper ahead of the deadline which is Friday the 18th of September. We appreciate any feedback, support or criticisms you may have. Please post them as comments below.

Simple straight up caching for pages served by Heroku

Wednesday, September 16th, 2009

So you’ve got an app that’s ticking along nicely; being served up a good steak in a 5 star restaurant – but you’d like to boost it’s performance with some caching. For those who develop their apps on the Heroku platform, a great way to do this is to cache a dynamic page using Varnish. This means that your page is served up super fast without hitting Rails/Sinatra/whatever. And best of all it requires no extra gems or anything, just a well placed one-liner in your controller.

Firstly, you can only use this technique if all users that visit this page expect to see the exact same content – in other words you have no ‘per user’ customised content on a page. To help understand how this type of caching works, imagine that the first time your page (let’s say an Events index page) is hit it is turned into a static html page for a pre-defined amount of time (let’s say 60 seconds). Anyone else who visit this page (ie. anyone else who visits this particular controller action) during the next 60 seconds gets that static html page. After the 60 seconds the static html page is removed from the cache. Thus the next hit will cause your underlying dynamic page to be invoked; then the caching process kicks off again lasting another 60 seconds. And so on and so fourth.

With the increasing amount of web applications that call APIs, such as Twitter’s API, this is a really easy way to ensure that you do not end up spamming a service provider with an unreasonable number of calls per hour. This is the technique we use on www.thelisbontweety.com to keep our API overhead down.

So how do you do this? Simply put something along the lines of

response.headers['Cache-Control'] = ‘public, max-age=60′

as the first line of your action for the page you wish to cache. The max-age setting means that this will be cached for 60 seconds. After you put this in your application and redeploy to Heroku, you can see if it’s working by using http://hurl.it

Just enter the  URL for your action and click Send. You should see something like “Cache-Control: max-age=60, public” in the output if it’s working.

And that’s it! No need to install anything. Just cache your little heart out with Varnish. Top marks to chaps at Heroku for making this so easy to use out of the box at Heroku. For more on this technique check out their HTTP caching docs at http://docs.heroku.com/http-caching

Packaging Ruby Apps for Ubuntu: Dissecting an existing Ruby Ubuntu Package

Wednesday, September 9th, 2009

One of the best ways to learn about how a Ubuntu package is put together is reverse engineer the package into it’s constituent components. We are going to take a look at how to do this for the chef application and it’s related libchef library is packaged as a Debian package.

* Visit the page http://packages.ubuntu.com/karmic/ruby/chef
* Under the Download chef section, download the package via the ‘All’ link into a directory called chef
* Visit the page http://packages.ubuntu.com/karmic/ruby/libchef-ruby1.8
* Under the Download libchef-ruby1.8 section, download the package via the ‘All’ link into a directory called libchef1.8

From the following guide (http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages) you can learn how to ‘unzip’ a Debian package. This is easy as they are pure ar archives. Here’s what we need to do

* In the chef directory, run the commands

ar vx chef_0.7.8-0ubuntu2_all.deb
tar -zxvf data.tar.gz

* In the libchef1.8 directory, run the commands

ar vx libchef-ruby_0.7.8-0ubuntu2_all.deb
tar -zxvf data.tar.gz

Now you can study the layout of the of the data payload of the package (this is where to look in order to study the anatomy of the application as it was being packaged). This layout is what will be of most interest to you.

If you have an application in a particular programming language that you wish to package, pick a similar application for which a package already exists and dissect it as shown above. Then bend your app into a similar shape in terms of directory layout before attempting to package it. To find out more about how to create your own Ubuntu packages check out this great video by Horst Jens Ubuntu: Making a .deb package out of a python program. It’s worth the effort of watching it to the end!

Happy packaging!