I found graphviz frustrating at times but on the whole it draws clean, symmetrical graphs far beyond anything else I can manage, even if I do use a mouse or tablet. Since I’m not able to use a pointing device on a regular basis, and I’m marking up my presentations in text also, it turned out to be a really good fit. I thought I’d share how I got on with it and some of my own graphs – as much to remind me next time conference season comes around as anything.
PHP Returning Numeric Values in JSON
It’s just a standard problem of PHP REST services. When I try to access it with java I have to convert it over and over again to ints.
I did have a quick look at the PHP manual page for json_encode but I didn’t see anything mentioning this. A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.
It turns out, this constant does exactly what I need. Here’s a simple use case:
echo json_encode(array('event_id' => '603'));
echo json_encode(array('event_id' => '603'), JSON_NUMERIC_CHECK);
and the output:
{"event_id":"603"}
{"event_id":603}
There are probably some situations in which you don’t want all your looks-like-a-number data to be returned as a number, but for now it seems to be a good fit for api.joind.in.
RepRap Masterclass
Using Modelines in Vim
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
The Worst Way To Find Women Speakers
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 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
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
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.
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: