RepRap Masterclass

I spent last weekend in lovely Bath, but I didn’t get to see much of it as I spent all three days building a RepRap, or Replicating Rapid Prototype. This is a 3D printer that can print plastic into any shape you can think of (and some that I definitely didn’t). The Masterclass was organised by EMakerShop and brought together a bunch of people with ties to the local area who are all active in the project itself.

Continue reading

Using Modelines in Vim

I’m working on a book at the moment, and there are strict guidelines on formatting. One thing which is tripping me up is that all code samples must use two spaces for indentation. I normally have my editor set to 4 spaces, so I was looking for a good way to keep just these files consistent in their layout. Enter vim’s modelines feature!

You may have seen this, a comment line at the start or end of a document which gives the settings for vim to use, something like this:

/* vim: set sw=2: */

This is a modeline in vim. I tried adding my own at the top of my sourcefiles, but vim seemed to ignore them. It turns out that modelines are disabled in vim by default (for security reasons) but you can easily turn them on in your .vimrc with:

:set modeline

The only change I want to make is the tab sizes which is why I use the line above. The vim modeline documentation is the best place to go if you want to add options of your own to this line

PHPMyAdmin Designer View

This week I’ve been using phpMyAdmin for what feels like the first time in years. I’m happier at the command line, but needed some graphical representation of information and easy ways to export example queries for the book I’m working on. I noticed that phpMyAdmin now has a Designer tab, which shows relationships between tables and allows you to define them.


Continue reading

The Worst Way To Find Women Speakers

I am a female speaker, and a software developer, which puts me in a fairly small minority at the events I usually attend (I’m a PHP consultant based in the UK, to give you an idea of what kind of events those are). Recently I’ve been asked my opinion more than once on the issue of women speakers being in a minority at technical events, and I’ve also been the “token” women speaker at a technical event.

The worst thing you can do is find some random, underqualified person who represents the demographic you want to include, and put them on the stage. Although gender is often the issue we hear most about, the same applies to anyone who isn’t a young, white male; it’s just that gender is easier to see and talk about than either age, ethnicity, sexual orientation, or anything else, and also since I’m a young, white female, it’s the only aspect I can comment on.Women are in such a minority that they are, almost by definition, representative (see http://xkcd.com/385). Anyone who sees your randomly-selected woman speak will simply go away thinking that women aren’t really good at speaking. Continue reading

Gearman Priorities And Persistent Storage

I have been writing a bit about Gearman lately, including installing it for PHP and Ubuntu, actually using it from PHP and also how I use persistent storage with Gearman. I’m moving on to look at adding jobs of different priorities.

I use Gearman entirely as a point to introduce asynchronous-ness in my application. There is a complicated and image-heavy PDF to generate and this happens on an automated schedule. To do this, I use the GearmanClient::doBackground method. This inserts a priority 1 job into my queue.

Using the doHighBackground() and the doLowBackground() methods insert jobs into the queue and checking out my persistent storage I see that the priorities work like this:

priority method
0 doHighBackground()
1 doBackground()
2 doLowBackground()

Gearman works out which task is the next highest priority and will hand it to the next available worker – which means that I can set my automated reporting lower priority than the reports requested by real live people wanting them now, and everyone is happy!

The Strpos Trap

This week I found myself again using strpos as an example of the difference between the == and === operators in PHP. The strpos function tells us where a string occurs within another string, by returning the character offset. If the string isn’t found, then the function returns false.

The problem arises because if we simply check that there’s a positive return value from the function, we’ll miss the case where the string appears at the start of the other string since the character offset will be zero:

$tagline = "PHP Made Easy";
if(strpos(strtolower($tagline), 'php')) {
    echo 'php tagline: ' . $tagline;
}

This code won’t find the “if” to be true, since strpos returns zero and PHP will type juggle that to be false (debates about dynamically typed languages can be saved for another day)

Correct Use of ===

This is a great example of where the === operator really helps, as it can tell the difference between false and zero:

$tagline = "PHP Made Easy";
if(false !== strpos(strtolower($tagline), 'php')) {
    echo 'php tagline: ' . $tagline;
}

This time, we’ll correctly get into the “if” even if the string appears at the start of the other string.

Not a particularly complex example but I think one that is simple enough to serve as a reminder as to what that extra = is for!

Apache on Ubuntu/Debian

Apache on Debian. Ubuntu

When I first started using Ubuntu, I was coming from a distro journey that started with FreeBSD and took in Mandrake and Gentoo along the way; I hadn’t worked with any Debian-based systems before and was new to the way that Apache is configured on those platforms.

Continue reading

PHP North West 2011

We might still be in the thick of the summer conference season, but there’s an event coming up this autumn which has me very excited: PHP North West 2011.

This is a regional PHP conference based in Manchester, UK, and I’ve been involved with it since it began (I’m surprised to find this is our fourth edition, it still feels like a shiny new adventure!). This year the dates are 8th and 9th of October and with an added tutorial day on the Friday, it is bigger (and of course better) than ever. In case you missed the announcements, here are the main things you need to know:

Continue reading

PHP|Tek and a Hackathon

A couple of weeks ago I had the pleasure of speaking at php|tek in Chicago. As usual there were a few great talks, a good crowd of new folk and a selection of established speakers all at the event and I had a great time. This year, there was one particular highlight that I wanted to share: the hackathon.

Continue reading

Marking up Tables in LaTeX

Recently I’ve been writing a LOT of LaTeX for slides (using powerdot) and I’m trying to collect some of what I’ve learned here so I can refer back to it later (and so it’ll be in words I can understand, some LaTeX documentation is slightly too academic for my tastes!)

I find the default formatting for table output in LaTeX can look a bit … squashed, so I always precede my tables with this:

\renewcommand{\arraystretch}{1.5}

To define a table, you use the tabular keyword and define your columns using l, r or c depending whether you want each one right, left or centre justified:

\begin{tabular}{l | l}

Continue reading