Archive

Archive for the ‘Unix/Linux’ Category

Holy Wars, aka Vi vs Emacs

March 29th, 2010 No comments

As a long-time Windows user, there was always something which confused me when it came to learning my trade on Linux based systems – the sheer amount of choice in apps on offer to fulfill a single task. Which leads me on to the next thing – the nigh-on-religious wars which have erupted around these apps.

Case in point: text editors. When I first went to edit a file in a pure Linux text console, I thought I would try out vi. When I found my head spinning after just a few minutes of trying to edit one line of a config file, I gave up and tried emacs. When I got overwhelmed by the sheer amount of stuff bolted into the text editor, I thought that I would go for the Linux text mode equivalent of Notepad, nano. I edited the file and moved onto the next thing I had to do.

But it really got me thinking. There is always a place for an alternative application in a given area – vi and emacs both do the same thing (edit plain text) but offer 2 very different ways of doing this, and both are highly configurable and so on and so forth. But what this doesn’t explain is the vitriolic debate which springs up around the users of each.

You don’t see this on other platforms – Windows users typically have to put up with Notepad until they discover something like Notepad++ and OS X users have Textmate (which seems to be very popular on that platform). However, you don’t get the users of UltraEdit insulting the entire families of those who use Notepad++. You don’t get arguments which have raged for 20+ years. In short, its all a bit more civilized.

So I get to my point – out of all these text editors on Linux, which one do you use and why? Functionality? The way the app looks? The price (or lack of it)?

Categories: Unix/Linux Tags: , , , ,

Is HipHop really worth it?

March 9th, 2010 No comments

In case you missed the news, a few months ago Facebook announced on their developer blog that they were releasing a piece of software to the wider community. That piece of software is called ‘HipHop’ and is one of the many technologies Facebook run behind the scenes to keep one of the world’s most popular sites up and running.

But what does it do? In short, HipHop translates PHP code into C++ code, which can then be compiled into native machine code. This, in theory, should remove a bottleneck or two from PHP itself – namely the interpreter – as a good deal of slow, interpreted code can be compiled into uber-fast native code. Well, in theory.

While there is a performance increase (just Google for benchmarks, there are bound to be dozens by now) I think that it simply does not justify the end for most PHP driven sites. The added complexity of ensuring all your PHP code can be understood by HipHop would be enough to drive me mad, in particular. Adding to that is the number of issues I have seen people encountering whilst trying to compile HipHop on anything other than Facebook’s own platform of choice… Not pretty.

It isn’t just that though. I believe the only real increase in performance is in processing-limited scenarios which just aren’t that common in real life. Sure, Facebook need it, but they serve hundreds of millions of pageviews each day. For Joe Bloggs’ e-commerce store the benefit of having slightly faster C++ code would quickly evaporate when it came to any code changes needing to be first done in PHP, passed through HipHop before being compiled and then debugged for a second time as C++ code.

Stability isn’t really an issue due to the above reason (it has apparently been powering Facebook for a while) and apparently HipHop supports ‘most’ PHP code, but I really do not think you should consider it for your next project. Well, unless you’re re-coding MySpace…

Categories: PHP, Unix/Linux Tags: , , ,

Installing SVN With Web Access Through Apache On Ubuntu

April 1st, 2009 2 comments

Getting started with SVN on Ubuntu takes only a few minutes, and enabling web access to the repository is also very straightforward.

First (in order to actually serve the files) you need to install Apache, open up a terminal window and run the following command. This will ensure that Apache is installed if you unselected it for some reason during the install.

sudo apt-get install apache2

Note the use of the sudo command. This will run the command you give it as a super user as normal users will not generally have access to install software like this. When you use sudo you will be prompted for the super user password. Next, use the following command to install SVN.

sudo apt-get install subversion libapache2-svn

You can now create your subversion repository, it is best to keep all of our repositories under the same directory so that things don’t get confusing in the long run. To create the SVN directory run the following.

mkdir svn

The following will create the repository in the directory /svn/myproject.

sudo svnadmin create /svn/myproject

Now we will need to edit some of the settings in our Apache SVN module. Use the following command to edit the correct file.

sudo gedit /etc/apache2/mods-enabled/dav_svn.conf

When you first open this file it is all commented out. You first need to uncomment the Location. This is the directory where subversion will be available from on the Apache side. Here I am setting this to svn so that when I navigate to http://127.0.0.1/svn I will see the correct output.

<Location /svn>

Note that you must also uncomment the closing location tag at the bottom of the document!

Uncomment the DAV line to enable the repository, this enables the DAV module.

DAV svn

If you have a single repository then then enable the SVNPath setting. However, if you have multiple repositories then enable the SVNParentPath setting. this will point to the main directory where your repository (or repositories) is stored.

SVNParentPath /svn

That’s about it really, but as a further step lets enable some sort of authentication. You will need to uncomment the following lines (which are grouped together).

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

And the following line.

Require valid-user

Now, before we restart our Apache server and enable everything you have done we need to setup a username and password for the authentication to work. Use the following command to create a user and assign a password.

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd user

If this doesn’t work then try using htpasswd instead of htpasswd2. You should be prompted to enter your password twice and then receive a message telling you that the user has been created. Note that you should only use the -c option when you create a user for the first time because it creates the password file even if it is already there. If you use this option again in the future you will destroy any other users you have created. Instead, simply drop the -c and use -m on its own which causes the password to be MD5 encrypted, but will not recreate the file.

You can now restart the server by entering the following command.

sudo /etc/init.d/apache2 restart

You might initially try a short cut and do something like the following:

sudo apache2 restart

However, this will not work as the script in /etc/init.d/apache2 explicitly reads some environment variables that are important when starting the server.

You can now go to your subversion directory and see the following:

SVN Web Access

SVN Web Access

You will also see an authentication window appear, just use the username and password you set up before.

You now have a fully working subversion server with web access.

Categories: Apache, Unix/Linux Tags: , , , , , ,

DVD Backup With Linux

March 9th, 2009 1 comment

If you are part of a company the chances are that you have either set up or are aware of a backup policy for your data. However, even if you are not then you might have the need to backup certain items to a DVD drive.

DVD burning it accomplished in Linux by using the mkisofs and growisofs programs. This can be run in either a two stage or a single stage process. The mkisofs program is used to create an iso file that is then written to the DVD using the growisofs program. The following will take three files and create an iso called toburn.iso, this will then be used to write the data to the DVD.

mkisofs -J -R -pad -o toburn.iso text.txt accounts.csv secret.txt
growisofs -Z /dev/hdc=toburn.iso -speed=2

The growisofs program can act as a wrapper for mkisofs and so the mkisofs step can be left out, as long as the destination directory and files are given. The -Z and -speed parameters are only used in the growisofs program, every other parameter is passed onto mkisofs.

growisofs -J -R -Z /dev/hdc -speed=2 text.txt accounts.csv secret.txt

To write more than one directory to the DVD you need to define the directories like this.

growisofs -J -R -Z /dev/hdc -speed=2 -graft-points /directory1=/home/user/directory1 /directory2=/home/user/directory2

The DVD will now contain directory1 and directory2. If this is not done then the DVD would mix up any directories that have the same name.

You can also use the -dvd-compat parameter with growisofs to improve the compatibility of the media with other DVD drives. With DVD+R and DVD-R this results in a closed disk, with DVD+RW the lead-out section is explicitly burnt to the disk.

Of course, if you are writing a piece of software or creating a movie then you might want to burn a large number of DVDs in one go, if this is the case then you might be better off using some sort of DVD Replication solution. This saves you the time and effort of burning the DVDs and applying the labels.

Find And Replace On All Files In And Below A Directory

October 9th, 2008 No comments

The following shell command uses the find function to find all files in or below the current directory that have the extension php. It then passes each file found onto a sed command which then replaces all <? with the longer &lt?php version.

find . -name '*.php' -exec sed -ie 's#<?#<?php#' {} \;

The -name argument in find will look at the base of the file name, that is, the file without any directory path. The -exec command is used to pass each file found onto another command, in this case sed is used.

Categories: Unix/Linux Tags: , , , ,