Hacking about with Node.JS

Posted: March 28th, 2010 | Author: Rob Searles | Filed under: JavaScript | Tags: | Comments

Update: If you are looking for a NodeJS tutorial, visit this post: NodeJS Tutorial with CouchDB and Haml.

After proclaiming that Node.JS is exciting stuff, today was the first time I’ve actually had the time to play around with it properly. I’ve been thinking about writing a custom FTP server for a project that we’re working on at the moment, and instead of starting from scratch, I thought I’d see if anyone else has tried to do the same. Fortunately I found Andrew Johnston started an FTP server only a few months ago: NodeFTPd on GitHub. I quickly created a clone and tried it out. It didn’t work! Node.JS is such a fast moving target that a lot of the API has been changed in the 3 months since Andrew initially released nodeftpd.

Perfect! This meant that I could play around with Node!

I’ve been hacking about on it for 4 hours or so, you can see my results at GitHub.

So what have my 4 hours of hacking around taught me about Node? Well, it’s not just exciting, it also bloody good fun!


My Perfect Desktop Day 1 – The Base System

Posted: March 18th, 2010 | Author: Rob Searles | Filed under: Linux, Tutorials | Comments

arch-linux-logoSo today is the day I start building my perfect system. Before getting going,  I had a good think about which distro to use for the base install. I’ve been using Ubuntu for about 2 years now and love the ease of package management with apt and aptitude. I had a bit of a play around with Ubuntu Karmic yesterday and I must say it looks fantastic, and with Lucid Lynx only a few weeks away it might come as a bit of a surprise to discover that my choice is a distro I’ve never used before: Arch.

Why Arch?

There are three main reasons I’ve picked Arch over Ubuntu, or even Debian.

  1. I really like the idea of Arch’s rolling release system. My laptop is currently running Jaunty and in order to get the latest packages I would have to upgrade to Karmic. With Arch this is less of an issue.
  2. As mentioned in my initial post, the base system should be small, quick and light. With Arch you can pick and choose exactly what you want at installation time, keeping it bloat free.
  3. Finally, Arch will be something new to play with!

After downloading and burning a Net Install ISO I followed the excellent installation guide in the Arch Wiki.

Installation was relatively painless, the only two slight issues being:

I chose Auto prepare for partitioning, but I didn’t really know what filesystem to choose. Eventually I opted for Ext4, with so far, no ill effects.

During Boot Device Selection, again I wasn’t really sure what to do, but after some Googling I found this page, whose advice I followed, but just pressing enter.

I restarted and was greeted with a shell prompt. I quickly pinged Google and my network was still up and running through the ethernet on DHCP.

The next step up a non-root user and X. Again, the Arch documentation is excellent.

Setting up X was relatively simple. I originally decided to not opt for hotplugging, which was a mistake because I only have a USB keyboard and mouse, neither of which I could use in X (muppet of the day award goes to me). After turning off the machine and setting up hotplugging, all was fine!

I have been using the Awesome window manager for about a month now. Awesome is a tiling window manager which is heavily geared towards being keyboard friendly, and as it’s name suggests, it is pretty awesome.

Unlike Jaunty, installing the latest stable version of Awesome was a breeze, I simply ran:

# pacman -S awesome

and edited my ~/.xinitrc file adding:

exec awesome

at the bottom. When I started X again, Awesome was there without any problem.

Sound was equally as simple to install, which was a nice surprise.

So my base system is now setup, with my window manager of choice in place and sound ready and waiting for my music collection. And all this running under 100MB of RAM!

After my first foray into the world of Arch I’m pretty impressed. Pacman is very straight forward to use, after a bit of tweaking here and there it has just worked.

Next time, file management tools.


Installing PHP5.3 on Ubuntu Karmic

Posted: March 17th, 2010 | Author: Rob Searles | Filed under: Linux, PHP, Tutorials | Comments

Following my previous post about installing PHP5.3 on Jaunty, I have had a few requests about installing it on Karmic. I’ve never used Karmic before so I thought it would be a fun excuse to have a poke about whilst also keeping my blog (sort of) up-to-date.

After freshly installing Karmic (the desktop version looks very nice btw) on a new VirtualBox image and then updating with the latest, er, updates I was ready to begin.

The entire installation procedure is very simple, once all dependencies are met.

Firstly you must edit your sources list to include the DotDeb package repository and the old Jaunty security packages to meet dependencies.

$ sudo nano /etc/apt/sources.list
# php5.3
deb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all
deb http://security.ubuntu.com/ubuntu jaunty-security main

Now update and upgrade Ubuntu

$ sudo apt-get update
$ sudo apt-get upgrade

You may find that you get the following warning:

WARNING: The following packages cannot be authenticated!
libevent-1.4-2
Install these packages without verification [y/N]?

I just answered Y and continued as normal

Once successfully upgraded then you can install Apache, MySQL and PHP as normal, feel free to cater the installation line to your tastes.

$ sudo aptitude install libicu38 apache2 apache2-mpm-prefork mysql-client-5.1 mysql-server-5.1 php5 php5-cli php5-mysql libapache2-mod-php5

You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in “yes” and carried on.

Robmorin commented in my Jaunty post that he had issues when installing PHP MCrypt. The answer can be found within the DotDeb comments

After you have installed everything you need to, test it out, either command line:

$ php -v
PHP 5.3.2-0.dotdeb.1 with Suhosin-Patch (cli) (built: Mar  9 2010 10:14:53)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH

Or by using phpinfo() page within your Apache installation:

$ sudo nano /var/www/info.php

<?PHP
phpinfo();
?>

then fire up http://localhost/info.php and at the top of the page you should see something along the lines of
PHP Version 5.3.2-0.dotdeb.1

Note: if your browser asks if you want to download info.php, simply restart Apache and try again:

$ sudo /etc/init.d/apache2 restart

All done. Not quite as simple as on Jaunty, but still better than compiling the source!

Post Script: Before starting this post, I did a quick search looking for tutorials to see if the work had already been done, but couldn’t find anything on installing PHP5.3 on Karmic. As there wasn’t anything I decided to continue with my tutorial and I ended up struggling for an hour or so with the dependency issues. Typically, after I had figured it out for myself, whilst searching for another dependency issue I found this post on the JMOZ blog about installing PH5.3 on Karmic Koala.  No idea why it’s not in Google, but either way, damn, I could have saved myself an hour or so!


My Perfect Desktop – Day 0

Posted: March 16th, 2010 | Author: Rob Searles | Filed under: General, Linux, Open Source | Comments

Today is an exciting day. I have in my possession a brand new custom built computer to use exclusively at the office. I currently use the laptop for both home and office work, but since the laptop is getting a bit old and computer components are so cheap these days I decided to build a work station just for me to use at the office. The best thing is that as it is custom built I can put whatever I damn well want on it – no pre-installed Windows or anything else. I can make it absolutely perfect for me.

I’ll be documenting here in my blog exactly the steps needed to take it from a tabula rasa to my perfect desktop system.  Apart from the system being obviously Linux based, there will be a number of things to consider before I get started. If I want it to be perfect, I need to think about what it is that I really need and want from a work only system. So, after a brainstorm this is the breakdown of what I require:

  1. Keyboard Friendly

    I am becoming less interested in using the mouse. This is for a number of reasons, firstly it is quicker to keep your hands on the keyboard rather than always having to find the mouse and point and click. Secondly, using the mouse greatly exacerbates RSI and all that jazz. As such a system designed for maximum keyboard usage is important.

  2. Great Web Development Tools

    As a web developer this is a no brainer. I need to be able to have the tools for developing websites, testing (at code, server and client level) deployment and client side version control.

  3. Base system should be small, quick and light

    Due to point 2, I can see the need for being able to have virtualised instances of Windows running, each running a different version of IE. As such, the base system should be as small, quick and light as possible so it doesn’t get bogged down when I have one (or more) windows running for testing purposes.

  4. Communications

    I have to be able to email, chat, and talk with people via my computer

  5. Music and sound

    I need to listen to music at work!

  6. Must get on with others

    Some strange people out there still use propriety software. My system needs to be able to read Word and Powerpoint and all that stuff.

  7. Not be rude

    This is a strange request, but over the weekend I had a friend staying who is an IT administrator for a large international company. He had to do some work on their Windows based infrastructure, so he powered up Vista on my laptop (which I never use*) to log into their systems via the Remote Desktop. Half way through he had to make a couple of calls. When he came back Vista had rebooted and he had lost everything. We narrowed it down to the fact that Vista had updates, installed them and rebooted without even asking for permission. IMO, that is really fucking rude.

  8. Stable

    Last, but by no means least, the system has to be solid. I can’t have it crashing on me every hour.

And that is pretty much it. Follow me over the next week or so whilst I sort out my ideal perfect work station.

* I just had to make that point

Building My Perfect Desktop


IE 7 indexOf() Replacement

Posted: March 11th, 2010 | Author: Rob Searles | Filed under: JavaScript | Tags: | Comments

Everyday I hate IE a little bit more, and by the same token, everyday I love jQuery that little bit more.

The reason for my hate/love feelings today was due to a bug caused by IE 7 not supporting the indexOf() method. I have no idea why IE doesn’t support this method, but it is annoying never-the-less. However, there is an easy fix if you are using jQuery – the inArray() function.

The inArray() function is pretty simple to use.

Instead of having:

haystack_array.indexOf("needle")

You should use:

jQuery.inArray("needle", haystack_array)

For those of you crazy nutters that aren’t using jQuery, there is a good post on this blog that will help you out.


Converting from Mac to Unix line endings

Posted: March 10th, 2010 | Author: Rob Searles | Filed under: Linux, Tutorials | Tags: | Comments

This is more a post for me than anyone else, but I thought I’d share anyway.

In our team we have a mixture of Linux and Mac users, and we are constantly editing the same files. One of the most irritating things is when a file is saved with Mac line endings instead of Unix line endings (displaying as ^M in Emacs). This happens very rarely, but on the occasion it does I can quickly convert back using the following commands on my Linux box:

$ tr '\r' '\n' < file-in-question.txt > tmp.file
$ mv tmp.file file-in-question.txt

Works perfectly

If you want to find more about the tr (Translate) program, visit the man page.


Site was Cracked

Posted: March 1st, 2010 | Author: Rob Searles | Filed under: General | Comments

Some of you may have noticed I’ve been gone for a few months. More on that later. However, whilst I was away I found out that this site was cracked!

My apologies to any of you who were affected by this. I have taken steps to ensure this won’t happen again.

I’ll be back soon with more writing on PHP, JavaScript, Ubuntu and other Linux Distros and the fantastic Awesome Windows manager, I promise!