Git Logo

Find The Number Of Commits In A Git Repository

25th June 2012 - 1 minute read time

Use the following command to find out how many commits there have been in a git repository. Not really useful in itself, but an interesting figure to see how active a project has been over it's lifetime.

git log --oneline --all | wc -l

The following git log flags are in use here:

--oneline - Removes some of the information from the log entries and displays each on a single line.

--all - Shows all commits across all branches.

The -l (lower case L) flag is supplied to the wc command so that it counts the number of lines in the given input.

Git Logo

How To Ignore Mode Changes In Git

25th June 2012 - 2 minutes read time

Git will track changes to files and directories, including any changes to permissions done via chmod. In most development environments I tend to have a different set of permissions to those on the live site so I am usually not interested in tracking permissions changes. To prevent git from looking at the difference between the permissions of a file you need to set the core.filemode configuration option to false.

git config core.filemode false

Here is the entry from the git-config(1) manual page.

Linux Logo

Using xclip To Copy Output From The Command Line In Linux

21st June 2012 - 3 minutes read time

When copying the standard output from within a terminal I often push it to a file using the "command > file" syntax. The trouble is that I then end up with a file that I have to open in order to get the output, and I often forget to delete the file once finished. This is especially annoying when I just want to paste some debug output into a help topic or similar. The solution to this is to use xclip to store the output in the xclipboard instead of a file. This is essentially the function of xclip, it allows access to a clipboard that you can store anything in.

A good example of this in use is when pasting the output of php -i into the amazing xdebug tailored instillation instructions. When you print this to the terminal you get pages of output. To push this into xclip instead just pipe it like this.

Testing Multi Step Forms In Drupal 7

14th June 2012 - 2 minutes read time

I am currently using SimpleTest to test a complex multi-step form implementation in Drupal 7. It made sense to do it this way as there are a lot of factors involved that all need to be accounted for and automating what form elements appeared on what page was the most robust solution. In order to test how the form worked I needed to submit to the form once (using a $this->drupalPost() method) and then submit the form again using the same method. The tricky bit here was that when calling the drupalPost() method with a URL it first called drupalGet() on the URL before posting to the form. This basically meant that the form was initiated twice and never got past the second page.

Drupal Logo

Altering A File Form Field Element In Drupal 7

31st May 2012 - 4 minutes read time

Altering text in Drupal 7 is quite simple thanks to things like string overrides that allow you to replace all instances of a string throughout a site. If you want to change a single element on a single form then string overrides don't quite work, but using hook_form_alter() or hook_form_form-id_alter() allows you to manipulate any form in a Drupal site.

#! code Logo

User Group Meetups Are More Than The Talks

28th May 2012 - 4 minutes read time

The good thing about working in a city like Manchester is that there is an active digital community. This means that there are quite a few digital events as well as a number of communities and user groups. I have been going to (and even organising) local user groups for a while now and I always learn something or help someone out, but the groups are more than that.

I recently encountered an attitude (from more than one person) that made me think that the point of usergroup meetups was slightly lost on them. Essentially, I saw that people were taking one look at the agenda for a meetup and saying "oh, there is nothing on the agenda that interests me, so I won't be going".

Drupal Logo

Loading A User's Groups In Drupal 7

22nd May 2012 - 4 minutes read time

Whilst working with Organic Groups today I had the need to load a list of the nodes that a user is connected to. After a bit of looking around in the source code I couldn't find a good solution on how to do this. So after looking around on Google for a bit I just sat down and wrote one.

Getting the group nodes that a user is a member of is quite easy as it turns out, but must be done in a number of steps. The first step is to grab a list of the group entity ID's that the user is connected through using the og_get_entity_groups() function. This can be used with no parameters (which assumes the current user).

PHP Logo

UK PostCode Validation Function In PHP

21st May 2012 - 5 minutes read time

Creating a function to validate UK postcodes would seem like a simple task, but there is a little more to it than checking the number of characters. In fact there are several different variants of UK postal codes, especially if you include BFPO and overseas addresses. The official postcode specification details the structure of the postcode, and there is also a list of BFPO numbers from mod.uk.

PHP Logo

PHP fgetcsv() Gotcha

19th May 2012 - 2 minutes read time

I quite often find myself with the need to pull the data from a CSV file into a system. This might be to fill out essential data like postcodes or to update a site with new content. What system I happen to be using dictates how I pull in the CSV file, but writing a quick parser is quite easy in PHP via the use of the fgetcsv() function.

Unfortunately, when using this function it is quite easy to miss something quite important and creates a quite useless piece of code. Take the following example. It appears to be fine at first glance, but the output of the code is always to run once and stop.

An Introduction To OpenLayers

19th May 2012 - 6 minutes read time

OpenLayers is a powerful and open source mapping solution written in JavaScript that can display mutliple different mapping services on web pages. What this means is that you can create a mapping tool using Google Maps and swap it to use Bing Maps at a later date without having to totally rewrite your code. OpenLayers works by building up a series of layers that fit together to form mapping, tools, information and even utilities like KML parsing and AJAX. Vectors and markers can also be used to add layers of information onto the map.

A map in OpenLayers (and most other mapping services) is essentially a set of images called "tiles". When you load a map all you are doing is loading in a bunch of map tiles which OpenLayers then places in the correct place. As you move around a map or change the zoom factor then other map tiles are loaded in to build the new view of the map.