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.
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.
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.
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.
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.
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 depricated. 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.
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.
You can create a multi-line comment 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 is ignored.
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.
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.