programming

As a programmer by hobby and by job, I stumble across a lot of resources for programming, from websites to gaming competitions.

Bash script to find most common 404

Mar
04
2010

Following Kevin Hankens post on why you shouldn't ignore Drupal 404 errors, I decided to go through yesterdays error_log on our live apache server (the one which hosts www.pponline.co.uk, www.sportbusiness.com and www.mychild.co.uk alongside around 40 other dupral sites).

Drupal Autocomplete in Vim

Aug
18
2009
Tagged in , &
Vim Logo

I recently stumbled across a handy tutorial on configuring a Drupal dictionary in Vim for autocomplete. I also remembered helping a friend out with a similar problem, Drupal syntax highlighting for Nano. I then combined the two and have a simple to follow tutorial for generating your own drupal 6 dictionary for vim autocomplete!

Vim Tips: Replace 0px with 0

Jun
23
2009
Tagged in , , &

I like little wins. I was just looking through the CSS file for this site and noticed that - for some reason - I'd used 0px instead of   a LOT of times. Most values need numbers (10em, 10px, 10% and 10pt are all very difference sizes) however 0 is one of the few valeus which is the same in all cases (0px, 0pt, 0% and 0 are all zero!). This adds up to wasted data and bandwidth; admitedly not a lot, but still Every Little Helps!

So I fired up Vim. Initially, I just did:

PHP's display_error, not always a good thing!

May
19
2009
Tagged in , &

I just hit an interesting issue while trying to upgrade a Drupal 5.18 site to Drupal 6.12. I went to the update.php page and noticed an error at the top implying the url_alias table was having issues due to Drupal 6 expecting a language column which wasn't present in Drupal 5. "No problem" I thought, "That'll get fixed during the update!". This was the beginning of a long learning curve through the new <a href="http://api.drupal.org/api/group/batch/6">Batch API</a> system!

How to import users into Drupal using Devel

Jan
15
2009
Tagged in , , &

The first test is a valid email address test. The second test is if an account exists for that email address. The third is if the username, generated by the "user" part of the email address, exists. If there are any issues, the "error" is logged into and array and printed at the end.

As the function goes along, a user is saves with the user part of the email address as their name, a random 6 character password and the email address as the contact address. In this example, it also give the user role number 3, which was our "subscriber" role.

Neat commenting in Vim

Jan
12
2009
Tagged in , , &

I am a bit of a "neat geek" when it comes to coding. Things should be indented neatly and should have well laid out comments! Why? Well… It's easy to do and in 6 months time when you look at your code you will appreciate it! It will also me even more appreciated by another developer in less than 6 months time ;-)

SVN + NFS = svn nfs cant get exclusive lock

Nov
25
2008
Tagged in , , , &

Last night I was trying to configure SVN on a server. The setup was that the SVN Repo was on "srv2" and the frontend and code I wanted to import was on "srv1".

I created an NFS share on srv2 and mounted it on srv1 in /mnt/svnroot. The mount worked perfectly and I could touch and remove files from srv1.

So I tried to create a "sites" folder where I wanted to import a site I wanted to version control. This is where I started to have problems… The sollution was to add "nolock,bg" to the mount options on the client. Read on for more details!

Relevant Content gets some love

Sep
25
2008
Drupal Icon

I while ago (almost a year!) I released a module called Relevant Content to the community. This module executes a relatively lightweight SQL query which pulls up other nodes and sorts them by how many terms they have in common with the current node you're looking at. This provides a rudimentary method of suggesting other content to visitors to the page. It also provides a way of teaching search engines about other potentially relevant content.

Vim and Drupal Modules

Aug
18
2008

I just finished upgrading a server to Ubuntu 8.04 which came with Vim 7.1 rather than 6.3 on the older server. It seems 7.1 does things slightly differently to 6.3.

In 6.3 I could create ~/.vim/filetype.vim and in there define a line as follows:

au BufRead,BufNewFile *.module,*.install,*.theme setf php

However in 7.1, it looks like a line similar to this has to go into ~/.vimrc instead…

Generate random string in MySQL

Jul
10
2008

Have you ever wanted to generate a random string in MySQL, say for assigning a random password to a list of users? Well here is a useful tip!

Global Redirect Update

Jul
03
2008
Tagged in , , &

One of my most popular Drupal modules - Global Redirect - has just had an update from 1.2 to 1.3. This update includes several fixes for the following:

Page Title 2 for Drupal 6

May
02
2008
Tagged in , &

I've just released Page Title 2 for Drupal 6. Page Title 2 is still marked as Alpha (as a project) however its in use on a number of my sites and appears to work.

I'd appeciate people's feedback regarding this module. Its a GREAT way to improve your websites SEO!

Node Quick Find

Apr
06
2008
Node Quick Find

I've just committed another module - Node Quick Find. That brings my projects to a nice round 10!

This module is a pretty basic one though. It simply provides a block which has an autocomplete field. This field is linked to the Node Title field. You start typing the Node Title and it will start suggesting possible nodes you might be interested in - sort of like a primitive search box.

It features primitive configuration, allowing an administrator to easil configure the title of the prompt, the size and the types of nodes returned in the autocomplete list (eg, you may want to limit the list to blogs only).

Accessing the Fragment from PHP - is it possible?

Mar
22
2008
Tagged in , &

peashoter has raised a good point in an issue report for GlobalRedirect. What happens to a URL which has a fragment in it - such as:

http://www.example.com/node/100#comments

I have done a google and cant find any answer to this. It appears that the fragment is not passed to PHP. This makes it a LOT harder to fix!

Call to arms (for Windows Drupal Developers)!

Jan
01
2008
Global Redirect Logo

It has come to my attention, thanks to Hass, that GlobalRedirect apears to have issues when running under Windows web server, IIS. Unfortunately, I do not use IIS but I am aware that a few members of the community do.

How much memory am I using?

Nov
08
2007

Following on from my previous post about how to check how many apache processes are running - I recently wanted to find out exactly how much memory my applications where using… So I did a little research and found a few new and useful commands!

The price of sucess - too many users!

Oct
25
2007

Recently at work we had been having issues with spiking server load. One of the potential suspects was the Apache configuration as it was allowing 256 MaxClients. Combine that with Drupal eating RAM for breakfast (say a minimum of 12Mb per page) and you have a recipe for disaster - too many visitors cause a RAM shortage, lots of swapping and eventually a server meltdown. After speaking the Rackspace Technical Support Team, one of the guys there (Daniel) wrote a VERY useful script for us to run on the server to monitor Apache usage.

Hidden Drupal development functions

Oct
02
2007
Tagged in &

I was browsing around the Devel Module the other day and I noticed a few functions that are not mentioned in any documentation that I've seen but make life even easier, as if Devel doesn't make it easy enough! Almost everyone that's used Devel will be familiar with <strong>dprint</strong>_r (A debug version of the popular print_r function in PHP). Well who has used these ones?

How to weigh terms alphabetically

Aug
07
2007
MySQL and Drupal

Following on from my Numbering Rows in MySQL article, today I needed to populate the weight column of the term_data table for about a hundred terms so that they incremented in alphabetical order. This was, on the face of it, a very tedious task; click edit, select weight from drop-down, submit, 'goto 1'.

As I said in my Numbering Rows in MySQL article, I don't like tedious - but I do like over-complicated methods which actually make my life more interesting and less tedious... Enter a nifty MySQL script!

Force a PDF to download

Aug
06
2007
Apache Logo

I recently needed to force a PDF to download using Apache. The default behaviour for most browsers is to try to open the PDF inside the browser itself. This is fine for a small PDF or for powerful machines - but a large PDF on even a modest machine can often lock the browser up. This needed fixing!

After 20 minutes of perusing the Apache documents, I happened across the FilesMatch option which takes Regular Expressions. Regular Expressions are cool things which pattern match; you give it a rather complicated (yet logical) pattern and it matches it for you. Initially I used something like this...

Follow Me