Archive for the ‘Ubuntu’ Category

Hello Planet KDE! Ruby makes an appearance in Grantlee

Thursday, July 8th, 2010

So this will be the first time theirishpenguin makes it onto Planet KDE! And no better time – blogging straight from the KDE community feast that is Akademy! It’s been a superb week, in the stunning city of Tampere in Finland. It’s Day 6 of the event, a day which has been quite a Ruby-tinted one. First up, I had the pleasure of hacking on Grantlee, a Django-inspired string templating engine in Qt, with Stephen Kelly; adding Ruby support to the code generator example it ships with. Also, after talking to Cornelius Schumacher from OpenSUSE I learned that Ruby’s splashed all over the place – even helping power the OpenSUSE Build Service which allows packages to be easily built for any distro. Cool, eh?

Grantlee’s an interesting project already in use in Akonadi integration and KJots, providing an elegant templating solution. It’s available on gitorious.org in the Grantlee repo. It was good fun hacking on it, particularly useful picking up on some of Stephen’s Ninja skills with git! At least it gives a couple of Irish lads something to do while all the Germans and Spaniards are talking about the World Cup!

The organisation of Akademy 2010 has been top notch, from the welcome packs with all the details you need to get oriented – to the big screen for the footie in the hacker room. This was matched by the friendliness of everyone who turned up to the event and the local Finnish. Even these two fellows had a great time coding…

Duck typing at Akademy
I feel a duck typing joke coming on. Me too!

There’s been some interesting BoF (Birds of a Feather) sessions, in particular the KDE Bioinformatics session with Luca Beltrame and KDE for Scientists session, again with Luca and also Stuart Jarvis. Some of the ideas raised pushed me to start working on getting ActiveResource support into Qt on Rails, to make hitting remote APIs possible from a Qt client app.

Well it’s 15 minutes to kick off in tonight’s semi-final. If anyone out there wants to talk about anything Ruby, or get a quick demo of Qt on Rails, then feel free to ping me. You can comment to this post or find me on twitter (theirishpenguin).

Last night we went Dutch… Tonight who knows…

Qt on Rails v0.1 released. But is this Ruby-based Qt and KDE app framework doomed?

Monday, June 21st, 2010

Ruby has changed the way developers build web applications. Since popularised by the Rails framework, programmers no longer stumble around in the dark with disparate web forms; instead they are able to clearly focus on the business problem and expose a well-modelled domain in a easily testable manner. Traditionally used in data-heavy domains, today’s web apps now encroach on the desktop’s home turf of rich highly-functional applications – something years ago thought impossible. And most surprisingly, through clever use of patterns and conventions, they’ve arguably become the easier of the two to develop. Given this, could desktop developers learn from the web app approach? This is in part the motivation behind Qt on Rails – let’s use a conventions-based approach to building desktop applications and clients. Let’s harness the ease and expressiveness of the Ruby language. And let’s have a clean consistent domain model underneath the hood with a comprehensive suite of tests to boot. A grand idea; but right now, it’s on course to fail…

List Page - Disc Jockeys
Main window listing Disc Jockeys (Click the image to enlarge)

What does this framework look like?

What exactly is Qt on Rails? Well first, let me just make a little guilty admission. This blog post is aimed at Ruby and/or Rails developers first, then Qt/KDE developers second. This is not because I believe one camp is more important than the other. It is because I really want to bring Rails dev’s on-board to KDE/Qt development and I see a real need to give them a first-class Qt toolkit; to make desktop apps as brilliant and easy to develop as their web apps. If Qt on Rails ever makes it as far as being a fully mature framework, I hope that a Rails developer using it for the first time will find it a very familiar experience. The directory structure, naming conventions and overall architecture (to date at least) has been chosen to that end. But I hope to do an article focusing on approaching this project from a more on Qt/KDE perspective. So what is Qt on Rails like?

Well, imagine you just wrote a Rails web application. You’re finished! Let’s say we just built a web app for a fictional company called RAD Radio. We have two important things in our system – Disc Jockeys and Sponsors for the radio shows. So we have this really neat model layer sitting on top of our database. It handles all our business logic and things like validation of data being persisted – let’s reuse this… verbatim! This is our line in the sand! Design choice 1, Qt on Rails literally reuses everything from the model layer down already within your Rails application!

If we start from the front end of our proposed desktop application and work backwards, we want to have a Qt app which consists of various different screens, some of which may be on display simultaneously. This is a little different from the web, because generally on the web you can think of having just one screen and this gets blown away on each request (unless AJAX intervenes, but still you get the overall point). In a Qt desktop app we decide that our initial screen is to be “main” window for our application. Clicking on a button may cause a new window to launch, for example, a window to edit a Disc Jockey’s details, but the main window will remain there, though not active. This kind of difference (from your typical web behaviour) presents a difficult challenge and will have a big effect on our architecture – for example, it has influenced my decision not to try and reuse anything for the controller layer generated in a Rail’s application. Back to our story, we have a main window as our starting point, which you can see in the figure above. It should have a way to navigate between different parts of your application. This is achieved through the big command link buttons at the top of the window. In our web application, each part of our application is based on different sources of data (called resources when using RESTful terminology). Clicking on the Sponsors command link button would cause the grid to be refreshed with Sponsor records. And then clicking on the Disc Jockeys command link button refresh the grid with Disc Jockey records again.

This sounds reasonable so far. A quick side note though; bear in mind this is still early days for Qt on Rails. I’m sure many good KDE and Qt developers may be horrified at the UI decisions made above. I’m not a Qt or KDE expert! This is another big challenge. One of the most crucial areas we need help on is getting feedback on how Qt and KDE applications are generally laid out, what widgets are used for what purposes and so on. In essence, what are the best practice guidelines for HCI in something like KDE and how can we incorporate that into the apps we generate with Qt on Rails.

So we are looking at the main window, which contains a list of Disc Jockeys in a grid – how does this work? Well, first we need to be aware of what Qt is giving us here. The list widget that you see on screen is a Qt widget called a QTableView. It is concerned only with displaying stuff. Underneath that we have a QAbstractTableModel. This holds the data, it does not care about how it will be displayed. Now it’s worth pointing out that a QAbstractTableModel has nothing to do with the Rails concept of a model. You see, the Qt folks have used the MVC pattern in their architecture for donkey’s years now; and it’s important to not confuse the two different uses of the same paradigm. The QAbstractTableModel is an object into which you stick a whole bunch of Rails records that you wish to display in a list. We then plug the QAbstractTableModel into the QTableView widget and that’s how your records are displayed. It’s also important to note that when a QTableView sees the QAbstractTableModel being plugged in – it has absolutely no idea that the underlying records are of type Disc Jockey. Think of the QAbstractTableModel as an adapter between a collection of records for a particular Rails model and the QTableView widget which will ultimately display them. Probably most importantly, remember that

  • A Rail’s model equates to one record
  • Whereas a QAbstractTableModel equates to many records – it sits on top of a collection of Rails records and allows them to be displayed in something like a QTableView widget

Note: The Qt API is incredible. It’s extremely comprehensive! Check it out at http://doc.qt.nokia.com You will want to look at the “C++ Application Development Framework” for the version of Qt you develop with. One big tip to note down – where it talks about something like a QAbstractTableModel in the docs – is that it is referring to the C++ world. In your head just translate this to Qt::TableModel – now you can happily use all the documentation available. Also, in your code you will always write Qt::AbstractTableModel, never QAbstractTableModel.

So to edit a Disc Jockey record I select a row and click the Edit button near the bottom of the page. Hey presto! An Edit Disc Jockey form appears…

Edit Form - Disc Jockey
Form for editing a Disc Jockey (Click the image to enlarge)

Nice! And when you click the Save button the Edit form is dismissed and the list of Disc Jockeys in our main window is refreshed!

Cool! But where do all the Qt on Rails files live?

Qt on Rails is installed in the vendor/plugins directory of your Rails app (see http://github.com/theirishpenguin/qtonrails for more details on how to install). Under vendor/plugins/qtonrails/ there is a directory called app/ which holds the Qt application code. In turn, app/ is divided into the following subdirectories, with each subdirectory corresponding to a layer in our application framework, listed here from the highest level (like the HTML stuff in a web app) to the lowest (the controller in our case – as everything from models down to db is handled by vanilla Rails).

  • qdesigns – XML markup files (with a .ui extension) which are to Qt screens/widgets what HTML files are to HTML pages/elements
  • ui_proxies – A Ruby representation of .ui files – this is an autogenerated layer which you don’t really need to worry about
  • qpresenters – Where the presentation logic (not any business logic) for your screen lives
  • qhelpers – A place to put logic that you wish to reuse across presenters
  • qviews – Where we decide exactly how we will build a view for a particular controller action (I accept that the name ‘qviews’ is confusing; maybe ‘qviewbuilders’ would be better or something totally different)
  • qcontrollers – Where we decide what data to retrieve for a particular action (though we don’t specify ‘where to go’ in the way a Rails controller has render() or redirect_to() methods)
I am the Executioner…

So here’s the flow of control. In our vender/plugins/qtonrails directory we have a ‘run’ command. When we execute it, the command…

  1. Fires up a Qt Application instance
  2. Asks our (very primitive) Router to take a given route and instantiate a QView and a QController for it
  3. The QController then fetches data depending on the action (just like a Rails action) and hands off the data to the QView
  4. The QView then decides what screen should be build (or whether to stay on the same screen and perhaps just refresh a list of records)
  5. Once the appropriate Screen has been built, it is displayed with a show() call. At this point the user will then see something happen on-screen.

The above is pretty much like one request-response cycle in a Rails app. Now we play the waiting game

  • The user does some*thing like selects a row and clicks the Edit button.
  • At this point the QPresenter comes into play. The QPresenter is your window widget. I didn’t tell you then, but the QPresenter was created earlier in the QView layer when we call the constructor for the window (ie. the QPresenter) we wish to display). I’m open to the fact that QPresenter may not be the best name for this! Anyway, the QPresenter contains your presentation logic. In our case, the user has just clicked the Edit button on the MainWindow presenter. This causes the handler for the event – the edit_clicked() slot to be called. Qt uses a brilliant concept called Signals and Slots to handle events in your application – a Signal is something that acts as a trigger (such as a button being clicked) for a Slot; a Slot simply being a function dedicated to doing something useful in response. A Signal is connected to a Slot using the aptly named connect() method. I neglected to bore you with this little detail earlier but this connection was carried out in the constructor for the QPresenter (ie. the window) which took place a few steps back when we mentioned that the QView layer decided what screen is to be built
  • Finally, the slot – edit_clicked() in this case – asks the Router to take a given route and now we’re back to step 2 of the flow of control outlined earlier
  • Phew!
Make it so, Jim!

So that’s it in a nutshell. How do get all this lovely goodness to turn your Rails web app into a skeleton desktop app? One command, mon ami! From the root of your Rails directory simply run

./script/generate qtify DiscJockey Sponsor

So let’s say you have no Rails app right now. Here’s how to get to a basic web app and skeleton desktop app in double quick time!

Firstly, just a quick note on OS dependencies. Qt on Rails has mainly been developed to date on Kubuntu 9.04, Kubuntu 9.10 and the Ubuntu Netbook Remix 9.10. For these platforms, you can install the packages mentioned in the “First Install the appropriate packages” section of this Developing Qt4 Applications using Qt Designer and Ruby on Kubuntu article, which also goes into more detail on QtRuby development if you’re interested. This QtRuby bindings article on the KDE TechBase also gives some useful info on the Ruby bindings for Qt.

We’ve not tried this yet on Windows or Mac, but here’s a Windows QtRuby install guide by Richard Dale and a QtRuby on the Mac install guide. So you are welcome to try and install QtRuby on one of these platforms but we can’t promise anything!

Perhaps, most excitingly of all, Qt on Rails apps can be deployed to Maemo devices such as the N900! Check out this related Deploying your Qt on Rails apps on the N900 (Maemo) article! And MeeGo support will surely follow sometime soon!

Ok, let’s cook you up a Rails app. Here we are using Rails 2.3.5 and assuming you are at a Linux command line (see Qt on Rails github project page for more installation details of Qt on Rails itself)…

rails RadRadio

cd RadRadio

./script/plugin install git://github.com/theirishpenguin/qtonrails.git

./script/generate scaffold DiscJockey name:string date_of_birth:date programme_name:string radio_slot:time max_num_guests:integer next_review:datetime

./script/generate scaffold Sponsors name:string signed_up_on:date

rake db:migrate

./script/generate qtify DiscJockey Sponsor

cd vendor/plugins/qtonrails

./run

# If ./run on it's own gave you a permission error you can try 'ruby ./run' instead

# Oh yeah!

What you see is almost what you get…

Hopefully, you should be seeing an app around about now. Once you have some rows in the list of disc jockeys or sponsors (create some DJs using the New button), you will see that cells of the grid that make up the list can be edited in-place. This is quite a powerful feature to have out of the box. An Edit button is provided also, though if you plan to provide an Edit button to your users, which launches a form, then you should probably make the grid read-only so as not to confuse them by having two ways of editing. As this is a early prototype of the framework, I’ve left the Edit button and in-place editing enabled, trusting you to tailor them to your app’s needs. If you were going to switch off in-place editing you would probably also want to select the entire row (rather than just one cell) when you click on a cell in the row.

Let’s have a quick look at form validation in action. Add a validates_presence_of validator to your DiscJockey and Sponsor Rails models so that they look as follows

#In app/models/disc_jockey.rb (under root of your Rails app, not under qtonrails)

class DiscJockey < ActiveRecord::Base
validates_presence_of :name
end

#In app/models/sponsor.rb (under root of your Rails app, not under qtonrails)

class Sponsor < ActiveRecord::Base
validates_presence_of :name
end

Close and restart the RadRadio Qt on Rails app. When you hit the New button and try to create a new Disc Jockey or Sponsor without a name, you will see that the Rails model validation kicks in and you get a validation message telling you that you need to correct the name field. Validation also works if you are editing a record after clicking the Edit button, however validation messages don’t appear if you edit a record in-place in the grid (just because I haven’t had a chance to implement that yet).

Again, as it’s an early release there’s also plenty of bugs in there, such as a crash if you try to click the Edit Button without selecting any row. A list of issues is maintained on the Qt on Rails Issue Tracker. Check it out to see what limitations currently exist and add to it if you spot a new problem!

Doomed?

As you can see, this codebase is being opened up quite early. A good start has been made – but the project is still very embryonic! Surely, it’s a bit early to be talking about doom? Well, unless hacking on Qt on Rails appeals to some developers out there it will certainly die a merry death on the great scrapheap of nice projects that just didn’t make it. Why? Not only is there a lot of work that needs to be done, but also it’s more fun to work on the project when there’s a crew involved, which also brings new ideas and energy to any project. Otherwise it’s unsustainable.

But life wouldn’t be fun it it wasn’t a bit of a challenge, right? If you think this kind of project might interest you, if you’re not put off by insurmountable odds, then know that your framework needs you! Drop me an email at declan [[AT]] weuseopensource [[DOT]] com or twit a quick tweet on twitter (theirishpenguin). The Qt on Rails Issue Tracker is a good place to start looking for things to hack on. Or you’re welcome to fork the project on github and develop that killer feature you’d like to see in there!

Qt on Rails, because it’s at an early stage, is an easy place to start – there isn’t lots of code to weigh you down. The framework itself is very thin, the majority of the code is actually Rails style generators to take the Rails model layer and build the Qt/KDE app on top of it. Because of the tiny codebase, it shouldn’t be hard too get your head around what’s going on.

Qt on Rails doesn’t want to be doomed!

It’s intended that Qt on Rails gives Ruby and/or Rails developers an outlet to develop first class desktop apps using the best available framework. Rails developers often ask, “If I want to build a great cross-platform desktop app, what GUI toolkit would I use?” The answer varies and there no one headline GUI toolkit/desktop framework that currently has mindshare amongst Ruby developers and works great across multiple platforms. Given that Qt is currently so strong across the Linux desktop, commercial Windows applications, Macs and mobile platforms such as Maemo and MeeGo why shouldn’t it be the first thing you reach for when building a Ruby desktop app? Come help us build Qt on Rails! Stave off the doom!

Lifting the lid on Open Jam!

Friday, April 16th, 2010

Open Jam was an Ubuntu Ireland lead event which invited all members of the Open Source community to come along to Enterprise Ireland’s Dublin offices at East Point on Saturday the 27th of March. And come along they surely did, really show-casing the diversity of groups we have here in Ireland – users of Open Source software, developers, admins and advocates. The timing of Open Jam was to coincide with the Ubuntu Global Jam – where contributors to the Ubuntu project focus on finding, prioritising and fixing bugs as well improving documentation, artwork and more. The ‘Open’ in Open Jam was to extend that spirit to everyone – independent of their area of interest or skillset – to collaborate, learn and share.

After the welcoming talk, some people got straight down to business, while others took the opportunity to chat and chill out after a long week in the office. Thanks to the excellent organisation skills of David Scanlon of Enterprise Ireland the event sported two rooms – one main room where you could hack away on your favourite project and another where liked-minded folks could get together and have a BoF (Birds of a Feather) session on a particular topic. Tunes were supplied on the day, pumped through Enterprise Ireland’s very tasty A/V system, by Luis Bethencourt – a.k.a. Mr Ubuntu Studio (Ubuntu Studio is a multimedia creation flavor of Ubuntu that Luis leads). In the BoF room, Rory Geoghegan kicked off the proceedings with a great intro to the Python programming language. This was followed by Anton Krasovsky’s highly popular talk on Erlang – which seemed to bring out the inner developer in everyone and sparked a meandering conversation through programming patterns, architectures and practices of every language under the sun. Anton is the author of pavo.me – a mulitmedia Twitter client for any pretty much phone that supports Java.

After lunch, which was graciously sponsored by Microsoft, Rory McCann gave an insightful talk on Ubuntu’s software collaboration platform Launchpad. Laurent Coudeur, part of the GNOME translations team, presented on the theme of language translations. He’s always on the lookout for people to help the translation effort (especially regarding Irish, so if you’re interested in helping then get in touch with him on his blog, where he also has a write up and more photos of Open Jam). Away from the lightning talks, Halo Labs, which is a community of Independent IT Service Providers, were beavering away on Linux appliances like Workgroup Server & Asterisk Box, with Patrick O’Conner and Russell Davies probably scooping the award for being the most industrious attendees!

Musical talent was a feature of the day, with Harry van Haaren from U.L. providing a really interesting lightning talk on his work in progress Luppp project; hooking up a MIDI board to his C++ based looping software – allowing part of a live instrument performance to be looped on the fly and built upon. UCD Open Source Labs (represented by Alexander Ufimtsev, Keith Byrne, Aidan Church, David Murphy and Chris Duffin) announced their availability to to support Open Source projects by providing facilities for collaboration, project planning and development of Open Source software – check out the UCD Open Source Labs website for more details.

The Open Source .NET scene had a strong presence with Dublin Alt.NET members on hand ready to participate in any conversation that had the mere mention of the words ‘design pattern’ :-) Andrea Magnorsky introduced the audience to the .NET DLR (Dynamic Language Runtime), which allows languages such as Ruby and Python to run on the .NET framework. Mono hackers Alan McGovern and Jérémie Laval gave a lively talk on the Mono framework, MonoDevelop and related platforms such as MonoTouch for the iPhone and Moonlight. Qamir Hussain presented on A.I. & Distributed Agent frameworks which he’s working with at the moment. Later in the day, Rory McCann was back on stage, this time with Larry O’Neill, to give a talk on the facinating Open Street Map project, which marches on mapping the world in an Open fashion. Oh and some random walked in off the street and chipped in with a quick talk on Qt, Ruby and Rails :-)

To round off, again a big thanks to David at E.I. for being such a kind host and also Laura Czajkowski, Jeffrey Roe and Qamir Hussain for helping to organise the event. It’s great to have Enterprise Ireland helping events like this, which really boost the Open Source community and innovation in Ireland. Most of all, thanks to you, everyone who showed up and helped make it a great event. The good news is that there’s no let up in the flood of Open Source events in the next few weeks with OSSBarcamp on April 17th and Open Spaces Coding Day on April 24th. Phew! Being Open was never so easy!

P.S. While the resulting projects need not be Open Source, a superb sounding collaborative event that’s on the horizon and worth a mention is Dublin’s Startup Weekend! This could be your chance to get that great idea in the back of your head implemented over a weekend sprint with other techies involved. It’s being organised by Sean Murphy and if interested visit the Startup Weekend website for more details.

P.S. If you want to leave your twitter handle to get in contact with others at the event then feel free to edit it into the Open Jam Attendees List

And finally, some more Open Jam pics…

Getting Google Calendar to work with KDE’s KOrganizer, Kontact and KMail (on Kubuntu 9.10 Karmic Koala)

Friday, February 19th, 2010

Woah! That’s a lot of K’s in the title! But it’s all in the name of getting your calender talking to your desktop so it’s for a good kause (sorry!)

There’s this great package in KDE that has a really cool name called Akonadi (pronounced Ahh-Kon-ahh-dee if you want to impress your friends!). But more than just a cool name it does cool things – particularly in the realm of syncing data on your desktop with a remote server. Ooo yeah, including Google’s servers. Akonadi is one of the ‘pillars’ of the KDE platform and here’s how you can use that pillar to prop up your schedules and calendaring with KOrganizer-Google integration. It’s easy on Kubuntu Karmic!

– Install the Google data package for Akonadi
sudo apt-get install akonadi-kde-resource-googledata
– Ensure the Akonadi Tray Utility is running by performing the following steps
– Search for Akonadi in the search box of the Kickoff Launcher (KDE’s “Start” menu). Click the Akonadi Tray Utility that is found
– Go to the tray on the bottom right of your beautiful KDE desktop and click the small arrow, if necessary, to to expand all the tray icons
– You should see an icon for Akonadi. Right click on it and select ‘Start Akonadi’
– This should start the Akonadi server. You can verify this by right clicking the icon again and checking to see that there is now a ‘Stop Akonadi’ option
– Right click on the Akonadi icon yet again and select ‘Configure’
– Under the Akonadi Resources configuration, click Add and elect to add a Google Calendar Data Resource
– Enter your login details for your google account
– Next it’s off to Kontact. Go to the Calendar in Kontact
– There should be a small Calendar pane on the bottom right to set up calendar resources. Click the Plus sign to add an “Akonadi (Provides access to calendars stored in Akonadi calendar folders)”
– In the resulting popup, choose the google resource in the list and ensure that Events is ticked to the right of it. (I didn’t try to get Todos or Journals working because I don’t use them)
– Hey presto! All your calendar details should now be pulled into KOrganizers calendar! Hurrah!!!

Just to note, at time of writing I found that I had to search and find the Akonadi Tray Utility on restarting the computer. Once it’s in the System Tray elect to start Akonadi as we did above and you’re back in the game! If you find a solution to this minor inconvenience on restarting your machine then please post below!

Thanks to Christian Mangold for this article which served as a great reference.

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!

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!

Bringing Back the Spirit of the Amateur Programmer

Wednesday, August 26th, 2009

In a blog post this month, Richard Dale (the man behind Qt/KDE’s Smoke bindings) eloquently phrased a noble goal,

“In the 1980s there were lots of computer magazines that used to publish programming articles with BASIC code, that everyone could input and run on their own computers. However, in the 1990s such large scale end user computer programming pretty much died out – tweaking the odd web page isn’t quite the same thing. One of the assumptions that the Free Software movement makes is that every user is also a programmer of some sort, who is able to tweak the software on their computers. I hope we can get back to that spirit, and change the way that people think about KDE programming, because at the moment there is a tendency to think it is hard and that only the ‘C++ gods’ like David Faure or Thiago Macieira can do it. In fact it is pretty easy to write small Python and Ruby apps and plasmoids, or to write a little script to message an app over DBus. We just need to get communities of like minded people together who write tutorials on TechBase, create blog entries with code (like the 1980s BASIC articles), and help beginners get started. These ubiquitous end user programming environments in Kubuntu (and other distributions I hope) will make it possible to do that.”

This really sums up something that would be fantastic to see over the next few years. There’s so many gadget lovers and technology geeks out there – the type of people who would’ve probably punched those BASIC tutorials into a Commodore 64, an Amstrad CPC464 or ZX Spectrum back in the good old days – that feel left behind as they perceive professional programmers to have blazed ahead a path that cannot be caught. But in many ways nothing could be further from the truth. For any programmer, there’s always some guy or gal that’s coding something more challenging or doing cleverer(er) stuff on the next machine. It’s all relative. And since software turned into a mainstream industry over the last couple of decades, it’s been the programmers doing the simplest tasks that have made the megabucks whilst the hardcore wizards of machine code and assembly have seen their demand dimish.

So next time you think there’s no point in picking up a few programming skills give a language like Ruby or Python a shot. Hopefully, with the continuing progress of Kubuntu and other distro’s to make programming more accessible, you’ll have the perfect environment to do so!

VirtualBox and Running a Virtual Ubuntu Image within an Ubuntu Host

Friday, March 27th, 2009

“What?” you say, “that’s a lot of Ubuntu going on! Why would you want to do such a thing?” The answer – for testing applications, replicating environments or perhaps running a few servers on one box.

This guide should work pretty well for any Linux distro, though you may need to replace the aptitude commands with the package manager of your choice. Here we’ll install a Hardy Heron guest inside an Intrepid Ibex host. Afterwards, we’ll also use dselect with apt in order to clone the packages on a machine we wish to replicate onto our guest OS. Oh ho the fun! Here goes…

We’ll start from scratch on your developer (host) machine with no prerequisites. Here are the steps
* Install the VirtualBox program
sudo aptitude install virtualbox
* Install 7zip, needed to extract downloaded image
sudo aptitude install p7zip
* Download Ubuntu 8.04 Hardy Heron iso image from http://virtualbox.wordpress.com/images/ubuntu/
* Make a new folder called my_temp
Move the downloaded file into my_temp
cd into my_temp
* Extract image
p7zip -d downloaded_imagefile
This should yield a folder called something like ubuntu-8.04-x86.
cd into this directory and run
- ‘mv VDI/ubuntu-8.04-x86 ~/.VirtualBox/VDI’
* Create a new virtual machine
- Run VirtualBox (should be in Accessories under the Applications menu or just type ‘virtualbox’ at the command line)
- Click the New button to create a new virtual machine
- Create a name for your Virtual Machine and set it’s OS Type
- Set the base memory to 256MB
- Elect to add an ‘Existing Hard Disk’, you the Add button and choose the ubuntu-8.04-x86.vdi under the ~/.VirtualBox/VDI directory
* Run and customise new virtual machine
- You should now have a new Virtual Ubuntu machine at your disposal. Start it up by clicking the Start button.
- Log in with ubuntu/reverse as username password. Double check that this is correct by looking at the site you downloaded the image from
- Once logged in change the password through the System/Administration/Users and Groups menu
- Install ‘Guest Host Additions’ from the Devices menu of the running window of you virtual machine. GHA allow you to copy and paste between the host and guest OS’s, along with a raft of other improvements. Tip: If your mouse gets stuck in the virtual machine window then use the right control key to let it escape.
If the GHA install does not work (due to a timeout) then you will need to install the Guest Host Additions manually, as follows
i) On your real Ubuntu machine (ie. the host) download the file that was specified as a URL in the popup that was displayed when you previously tried to install Guest Host Additions – if you forget the URL try to download the GHA again from the Devices menu and when the URL appears copy and paste it into FireFox running on your host machine. Note: The GHA are installed onto your host machine.
ii) Once downloaded, move the file to /usr/share/virtualbox on your host machine and create the following symlink (as virtualbox won’t recognise the file if it has the revision number in the filename)
sudo ln -s /usr/share/virtualbox/VBoxGuestAdditions_2.0.4.iso /usr/share/virtualbox/VBoxGuestAdditions.iso
iv) Once again try to install ‘Guest Host Additions’ from the Devices menu of the running window of you virtual machine. This time it will pick up the local file you downloaded.
* Create a shared folder – to swap files between your host and your VM
- On your host machine create a directory you will use for sharing
- On your running virtual machine create a directory you will use for sharing
- From the Devices menu of the running VirtualBox windows select Shared Folders and set the ‘folder path’ to the folder you just created on your host. Give it a friendly name in the ‘folder name’ field and elect to make it permanent. Then on your VM run
mount -t vboxsf the_friendly_name /path/to/folder/on/virtual/machine

Note: That vboxsf is the filesystem type that VirtualBox is using for shared folders

Now you should be ready to go with your VM. Congratulations!

As a final step you may want to take this vanilla Ubuntu machine update it so that it has the same packages as another machine, in the case where you are looking to replicate an environment. Use dselect and apt to do this as laid out in the following guide Restore Packages using dselect on Kevin von Zonneveld’s blog.

As a final step you may want to install any other software that is not covered by aptitude packages – such as programs for which no debian package exists or for things like Ruby on Rails gems. It shouldn’t take you long to put these on your new virtual machine and “hey presto!” you’re ready to rock!

Phusion Passenger Configuration File Location – passenger.conf

Wednesday, March 4th, 2009

This was not easy for me to find! My beloved Ruby on Rails apps just sitting there untweaked! Google and even the Passenger website didn’t specify where the config file may be found. And eventually it made a startling difference to my apps performance – possibly given that I’m trying to host a few sites at once – so it would be nice if it was easier to learn about how to setup the config file when new to Passenger,

Out of the box on a vanilla passenger install there is no passenger configuration file. However, there are a lots of configuration options and you can either dump these into

a) /etc/apache2/apache2.conf file (messy) or
b) Create a new file called passenger.conf under the /etc/apache2/conf.d directory as files in thei directory automatically get loaded by apache
c) Create a passenger.load file in mods-available and then enable the module

By the way, this setup is on Ubuntu, your mileage may vary depending on your distro. For an example passenger.conf file see this one, just be sure to get the ‘LoadModule passenger_module’, ‘PassengerRoot’ and ‘PassengerRuby’ settings correct. You may already have these specified correctly in your apache2.conf file if you already have passenger working; if so you can reuse these values.

Apparently the recommended PassengerMaxPoolSize is 2 if you’re on a 256 MB Virtual Private Server System that’s running things like MySQL and keep the PassengerMaxInstancesPerApp smaller than this. If you’re running a couple of rails sites then maybe set PassengerMaxInstancesPerApp to 1 if you want to have 1 instance always available for each site. A RailsSpawnMethod of ’smart’ can also lead to better performance depending on your setup.

Certainly playing around with this config file helped me greatly improve my sites’ responsiveness for little effort and in particular it got the usage of the all important swap space down.

One final tip for today is to install htop (is available through aptitude). This gives a very useful and pretty display of the ‘top’ commands information and can make monitoring things like memory and swap at a glance much easier. So armed with this knowledge go forth and spawn! Well, till you run out of memory at least!

Installing Drupal on Ubuntu (Gutsy) in a few easy steps

Friday, November 28th, 2008

Drupal is a great solution if you’re looking for a CMS system. In order to sneakily install LAMP with the minimum of fuss, I usually just install mod php and mod mysql (the apache related modules for php and mysql respectively) and that triggers pretty much everything else to be pulled automatically! So, from the command line…

sudo aptitude install libapache2-mod-php5

sudo aptitude install php5-mysql

… should give you Apache, MySQL and PHP in one fell swoop. Just to be sure that all is well run the following install commands

sudo apt-get install mysql-server
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install php5-mysql

Then download and install Drupal (version 6.6 at time of writing) at http://drupal.org and follow their install guide.

One final tip, if there’s any problem with your apache installation’s configuration, you can install phpMyAdmin in order to plough through these problems as it will supply its own configuration. For example, I got the database configuration error when I was trying to connect to my database for the first time using Drupal

“Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that Drupal supports.”

Turns out my apache config was dodge as when I did a ’sudo apache2ctl restart’ I got the following…

“apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”

Installing phpMyAdmin and choosing apache2 when prompted during this process did the trick. Now go forth and Drupal!