Drupal Logo

EU Cookie Law Talk

15th May 2012 - 2 minutes read time

A couple of months ago I gave a talk at the North West Drupal User Group in Manchester where I talked about the EU Cookie Law and about cookies in PHP and Drupal. The EU law has been in practice in the EU for the last year and is due to be implemented in the UK on May 26th 2012.

People have been asking me to provide them with the slides so I thought I would create a quick blog post and put them on #! code.

Cookies and the EU Law.

Drupal Logo

Getting Started With Drush Make

12th May 2012 - 13 minutes read time

Drush is a command line tool that allows interaction with a Drupal site. The tool itself is incredibily useful and provides mechanisms to download modules, backup databases and most other things that can be done with Drupal. Drush Make was a plugin for Drush which has now become part of the Drush core and allows Drupal sites to be created via a make file. What Drush Make does is to use the make file to download the modules, themes and libraries needed for a Drupal site ready for the site to be installed. This means you can give this make file to another developer who can then build their own Drupal site.

JQuery Logo

Easy QR Code Generation With Google Charts API

26th April 2012 - 4 minutes read time

When I found about the ability to create QR codes using the Google Charts API I decided to sit down and create a little tool that would generate QR codes for me. I've had this tool for a while and I recently noticed that the QR code mechanism has become deprecated. The API will still work for a couple of years so I thought it was worth posting this. Creating a static QR code using Google Charts is quite easy, all you need to do is create an image. For instance, to create a QR code for the #! code address I would do the following.

<img src="https://chart.googleapis.com/chart?chs=177x177&cht=qr&chl=http://www.hashbangcode.com/&choe=UTF-8" />

Which creates the following image.

Python Logo

Multi-line Comments In Python

13th April 2012 - 2 minutes read time

Python doesn't officially support multi-line comments, but there is a way of implementing the same functionality using an existing language construct. Single line comments in Python are written like this:

# This is a single line comment.

Multi-line comments are not officially supported in Python. That said, you can create the same effect in Python by using a multi-line string. Unless it is part of a docstring at the start of a class, function or module then it parsed into a string variable, but nothing is done with it.

Python Logo

Stopping Code Execution In Python

13th April 2012 - 2 minutes read time

I am currently in the process of learning Python, so I thought I would start a series of mini blog posts detailing different things that I have found useful whilst learning how to use the language.

To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program running. It is the most reliable, cross-platform way of stopping code execution. Here is a simple example.

Drupal Logo

Tip On Adding Code To Drupal Forms

7th April 2012 - 2 minutes read time

There are various different forms and modules in Drupal that allow for PHP code to be embedded into them. I have even talked about adding PHP code to forms in a previous post. These form elements can have their uses, modules like Views allow for PHP code to be run when collecting arguments which can allow for some advanced funcationality.

However, it can lead to problems. The code in the form is essentially outside of source control which means that anyone can mess about with the code and there is no way to revert changes or get back the code if the form save action failed for whatever reason.

Phing Logo

Using Phing To Create Apache Virtual Hosts

6th April 2012 - 10 minutes read time

Phing is an awesome tool for automating things and I use it more and more for automating all kinds of different tasks. One of the tasks that I don't tend to do all that much is setting up a new local virtual host for Apache on my development machines. I know how to do it, but there is always something I forget to do, or a convention that I don't follow which means that I have to repeat myself at a later date to fix something I have missed.

So to make my life a little easier I decided to create a Phing build file to automatically create a virtual host and the everything associated with it in one go. Essentially, I would need to do the following tasks:

Phing Logo

Adding A Context Menu Item For Phing On Windows

21st March 2012 - 2 minutes read time

To make things a bit quicker when using Phing on Windows use the following registry entry to create a right click option that integrates with Phing.

PHP Logo

Getting Started With PHP DocBlox

20th March 2012 - 6 minutes read time

DocBlox is the new defacto PHP class documentation generator. It was developed as an alternative to PHPDocumentor, but it looks as though it will replace it and become the new PHPDocumentor2. As a result I thought I would put together a quick tutorial on getting started.

This post assumes that you know what PHPDoc comments are and that you have a project that you want to generate API documentation for. To get started on PHPDoc take a look at the Wikipedia page on PHPDoc.

Whereas PHPDocumentor would scan and generate all of the code in one go, DocBlox will scan the source code and generate a series of XML files based on the code it finds. It will then use these files to generate the API documentation in a number of different formats, although HTML is probably the most common.

JavaScript Logo

Local And Global Variables In JavaScript

18th March 2012 - 4 minutes read time

I have seen a lot of this sort of thing, so though I would put together a quick lesson in JavaScript variable scope. There are some important differences between local and global variables in JavaScript that will cause grey hairs if you don't know what's going on.

Scope is something that dictates what variables can be seen by code. If a variable is created inside a function then it can be said to be local as only the locally running code can see it. A variable that can be accessed by any part of the code is said to be global. This is special in JavaScript, which I will come onto later.

This scope concept is important as if a variable is outside the current scope then the code can't see it. Everything in JavaScript is a variable so understanding how and when variables can be accessed is important.

To create a local variable in JavaScript do this: