#! code Logo

LAMP And Beyond: A Review

3rd July 2012 - 4 minutes read time

Saturday 30th June saw a one off event organised by the PHPNW community called LAMP and Beyond. The idea was that it would bring together people of differing abilities with the aim of sharing skills and experience with servers, programming, source control, or whatever happened to be of interest at the time.

With 30 or so people signed up to the event we filled the top floor of MadLab in Manchester and got started (after a bit of coffee first). Taking some post-it notes we wrote down what we wanted to know about and what we could teach about onto a board and then broke off into groups where people's interest matched.

Linux Logo

Find The Size Of Files And Directories In Linux With The du Command

29th June 2012 - 6 minutes read time

The du (or 'disk usage') command is a Linux command that can print a list of the files within a directory including their sizes and even summarize this information. It is useful if you want to see how large a group of files is and provides more information about directories than the ls command does.

Using du within a directory will show you the size (in bytes) of all files and directories under that directory, including the size of the current directory. To make du produce more readable results just use the -h flag to make the file sizes into a human readable format. You can also use the -c flag to produce a grand total of all of the sizes found, and the -s flag to display only a total. The -a flag can be used to display all files as well as directories, leave this out to just display directories.

Linux Logo

Remove SVN Files From Source In Linux

26th June 2012 - 1 minute read time

There might be a couple of reasons why you would want to do this. Perhaps the repository has been checked out instead of exported, or maybe the repository doesn't exist any more. A couple of strategies exist remove all SVN files from a set of directories in Linux. You can either use the rm command directly and pass in a find command using grave accent quotes (key to left of '1').

rm -rf `find . -type d -name .svn`

Or you can pass the output of the find command to the xargs command, which calls the rm command.

find . -type d -iname ".svn" -print0 | xargs -0 rm -rf

You can even use the -exec flag of the find command to run the rm command.

find . -type d -iname ".svn" -exec rm -rf {} \;
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).

// Load in the current user's group entity ID's
$groups = og_get_entity_groups();

Or you can load a user and pass this object to the function.