How I Learned To Stop Using strtotime() And Love PHP DateTime

1st March 2013

The DateTime classes in PHP have been available since version 5.2, but I have largely ignored them until recently. This was partly due to the fact that I was working in PHP 5.1 environments a lot (don't ask) but mostly because I was just used to using the standard date functions that have always been a part of PHP (well, since version 4). I wanted to explain why I will be using the new DateTime classes more from now on and why you shouldn't be hesitant to use them.

Using a combination of strtotime() and date() can handle most things and is a good method to quickly grab a date.

Bookmarklet To Run XDebug Profiler
XDebug is a great PHP debugging tool, but it also comes with a very useful profiler that can tell you all sorts of information about your PHP application. This includes things like memory footprint and CPU load but will also have detailed information about the entire callstack of the code that was run. To enable the profiler part of XDebug you just need to set up a few rules in your xdebug.ini file.
philipnorton42 Tue, 02/05/2013 - 16:24

Turning Off Drupal CSS and JavaScript Aggregation With Drush

4th February 2013

I often find that after recreating a Drupal site locally to do some testing that I have left CSS and JS aggregation turned on. This can be turned off easily enough via the performance page, but this often breaks the flow of what I am doing. As an alternative I use Drush to reset the values via the command line.

The Drush command variable-set can be used to alter any value in the variable table. The two values needed for CSS and JavaScript aggregation are preprocess_css and preprocess_js. To turn these values of we just set them to 0 like this.

Uzing Tar To Compress And Uncompress Files

The tar command can be used to compress or extract one or more files in Linux. A tar file isn't actually a compressed format, instead it is a collection of files within a single file. The tar command can take one or more files, convert them into a tar file and then compress it into a gzip file format. The file created will have the extension tar.gz.

There are a large number of flags that can be used but the main ones for everyday use are.

philipnorton42 Sun, 02/03/2013 - 21:13
Checking If An Element Exists In jQuery

To verify that an element exists in the DOM you just need to use the .length property of a jQuery lookup. If the element is there then the number of elements found will be greater than 0.

philipnorton42 Sun, 02/03/2013 - 17:32

Creating Custom User Admin Actions In Drupal 7 Organic Groups

26th January 2013

Organic Groups (OG) in Drupal 7 has a role based permission system that works on a group by group basis. This permissions system works separately to the main Drupal permission system, which can cause a couple of issues. For example, if you want to give a group role access to give other users roles then you'll need to give them the 'Administer groups' permission. The downside of this is that it overrides Drupal's core permissions to do with node deletion and allows the role to delete the group.

Load Drupal Organic Group Role By Name

23rd January 2013

I have been developing a site with the Drupal 7 Organic Groups (OG) module today and I found the need to grab a bunch of users from a group depending on their group role. The first parameter here is the group GID (not the node ID) and the second is an array of role ID's to use.

Force Update Of Git Repository

22nd January 2013

If you have changed or updated a git repository and want to throw away your changes then a good way of forcing the lastest changes to run a combination of two commands. The first command is git fetch --all, which tells git to download the latest updates from the remote without trying to merge or rebase anything. This is followed by git reset --hard origin/master where git resets the master branch (assuming you were on the master branch) to become the version of the master branch you just fetched. Here is the two commands in full:

SSH Bad Owner Or Permissions Error

After a recent update on Ubuntu I found that I was unable to use ssh due to a strange permissions error to do with the ssh config file. This was quite a problem as I wasn't able to push changes to my git server. The error was as follows:

philipnorton42 Mon, 01/21/2013 - 22:29
Xdebug Debugging On A Remote Server

I have started to use virtual machines to develop sites rather than installing a local web server. This allows me to replicate the exact setup of the server I will be deploying to with ease. For each virtual machine I set up a shared folder which allows me to store the files locally whilst being able to run the code on the virtual machine. One thing I missed was the ability to use xdebug to debug the sites through Netbeans, so I set about trying to set up the virtual hosts to allow me to use xdebug remotely.

philipnorton42 Sun, 01/20/2013 - 22:55