Bringing Back the Spirit of the Amateur Programmer

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!

HOWTO: Add a secondary hard drive for Windows via VirtualBox 2.1.4 OSE

July 22nd, 2009

Sometimes one disk just isn’t enough. In fact most times! Here’s how to add an E Drive to your Windows Guest OS

  • In VirtualBox, go to the File->Virtual Media Manager
  • Click the New button to create a new hard disk and create a new hard drive file via the wizard (a .vdi file)
  • Ensure Windows Guest OS has been shut down
  • Click on the Settings button for your Windows Guest OS, and choose the Hard Disks tab
  • Add the .vdi file you just created to be a hard drive for the Guest OS by clicking the Add Attachmenticon on the right and selecting your .vdi file in the file explorer from the drop down list that appears, here is the typical order of drives on a system
    • IDE Primary Master: this is the main drive onto which your Guest OS is installed (very important!)
    • IDE Primary Slave: this is the first additional drive you add on (ie. the E: drive)
    • IDE Secondary Slave: this is the second additional drive you add on
  • Once your done start up you Virtual Machine Guest OS
  • Visit the Control Panel in Windows
  • If you’re using XP elect to ’switch to classic view’ on the left of Windows Explorer
  • Visit Administrative Tools->Computer Management
  • Under the storage node on the left, there should be a Disk Management node
  • A wizard should instantly popup to help you add the drive as soon as you click on this, agree to its demands
  • After the wizard, you should see a drive displayed as ‘unallocated’ as you scroll down the list of drives
  • Right click, select New Volume and before you know it you should be done!
  • Now go and open Windows Explorer and experience the joy that is an extra drive!

A Breath of Fresh Air – The Well Grounded Rubyist

June 9th, 2009

After a tough day in the office you want to catch up on the news, so you look at the ticker on a TV channel or tune in your car radio. Other days you’ll want to sit down with a meaty broadsheet and really take in the detail of what lies behind the headlines. This is a book about Ruby which which triumphs at walking the line between these two styles. The Well Grounded Rubyist aims to appeal to a developer that has been exposed to some Ruby coding and take their knowledge to the next level. And it succeeds brilliantly.

This is not a book about Rails or any other web frameworks; purely Ruby. Though much of the material will also apply to the 1.8.x series of Ruby, this is a book about the 1.9 version of the Ruby language. It’s broken into three parts – Ruby foundations, Built-in classes and modules and finally Ruby dynamics. But don’t let the title of Ruby foundations fool you for part one – this is not some remedial rush through the basics of Ruby in six chapters. Rather, after a couple of warm-up chapters, it moves quickly to clarify the key aspects of how classes and module inter-relate, as well things such as crystallising what ’self’ really means in different contexts in a Ruby program. The author sets out his stall early – what makes Ruby different from other languages is it’s focus on objects rather than classes. Everything else stems from this and by the end of the section you feel like you have an understanding of Ruby’s design and focus.

Part two of the book is Built-in classes and modules. Now that you know what makes Ruby tick, it’s time to get seeped in all aspects of the core library that ships with it. One of the problems when learning a language is that becoming familiar with all methods of a particular core class is a tedious task. It’s much more interesting to learn about concepts such as meta programming than memorising lists of methods by rote. But if you don’t take the time to familiarise yourself with the dusty corners of a language’s API then you’re less likely to think of those handy methods when a problem they would elegantly solve presents itself. At this point the book shifts gear to a more reference style of text. However, it still gives the reader an interesting story to follow as it documents arrays, hashes and other classes – throwing in the occasional golden nugget of information that will be a valuable additional to the toolbox of even experienced Rubyists. One side effect of the change in style is that this section is probably the most accessible to beginners. Again it’s broken down into six chapters. In addition to collections, it also covers topics such as regular expressions and file handling. Each topic takes a zero-to-hero approach meaning that you can bring little regular expression knowledge to the table yet still walk away learning an immense amount about the subject.

The final part of the book, Ruby dynamics, returns to the book’s roots from part one – a focus on imparting a deep knowledge of Ruby’s design. Before you even pick up this book you have an inkling that procs and lamdas are going to make a guest appearance at this late stage. And they do not disappoint. Extending the behaviour of objects takes centre-stage and meta-programming based techniques move quickly to the fore. Any block/proc/lamda confusion you may have will be a distant memory by the time you finish this section. Threading is also covered here – though a detailed discussion of 1.9’s new native OS threads vs green threads is left to one side to focus on the usage of threads regardless of which underlying type you use. Lots of material is also provided on querying objects; which is not only useful for program design but also invaluable as a debugging aid. The book really shines in this section because a lot of other texts make the mistake of going into ’super-boffin’ mode at this point, leaving the reader lost, whereas the author here continues to provide patience and context to get you round that final lap on you way to becoming a Well Grounded Rubyist!

This book cannot be all things to all people. Because it is catering for a wide range of intermediate to advanced Rubyists, it will feel like it’s moving a little too slowly for some. By the author’s own admission, this is in order to make it accessible to a wider audience and no doubt it will make it easier for developers of all levels to digest – your humble reviewer very much included! Ruby first-timers would be best off having some straight-to-the-point tutorials or entry-level text to hand in order to get some instant gratification – as part one of the book, by it’s very nature, is a little more abstract than a complete beginner would expect. But all in all, this book is a great way to learn just how Ruby crams so much expressiveness into such a simple clean framework. Whenever I read a book like this I keep a list of new things learned along the way. For The Well Grounded Rubyist it is a very long list! Well done to David A. Black and Manning for producing a book that fills those gaps in many Rubyists’ understanding of the language while at the same time delivering an absorbing readable book that would sit proudly on any Ruby programmer’s bookshelf.

Optimising Apache serving Ruby on Rails via Passenger

May 11th, 2009

An unusual blog post this in that I have such little value to add other than pointing you at two great links. The first is a wonderfully useful post on tweaking Phusion Passenger when running some Rails apps on a 256MB Slicehost VPS and the other link is a no-nonsense explanation of tweaking Apache config options to cut down on your swap memory usage. Thanks so much to these folks!

VirtualBox and Running a Virtual Ubuntu Image within an Ubuntu Host

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!

Blackout Ireland – Not Condoning Piracy but Criticizing Coporate Internet Censorship

March 9th, 2009

One of the key points of the Blackout Ireland campaign is that letting individual companies control the Internet is not acceptable. This article at OpenWriters.org says why.

Blackout Ireland Campaign Begins – No to Irish Internet Censorship

March 5th, 2009

The battle for control of the Internet has begun within Ireland. In the red corner, Eircom has sided with the Big Four record companies – Sony-BMG, Universal and Warner and EMI – who are seeking to control the Irish Internet using coporate censorship and civil law techniques. In the blue corner, the Blackout Ireland campaign is looking to highlight the dangers of this censorship and has used social networking tools such as Twitter and Facebook to build support to protest this decision. A similar campaign was succesful in New Zealand, will it work again here?

Read more on OpenWriters.org.

Phusion Passenger Configuration File Location – passenger.conf

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!

5 Apache Troubleshooting Tips for 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

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!