Script for Database Patching at Deploy Time

I’ve written before about a simple way of patching database versions and there’s a much more comprehensive article from Harrie on TechPortal as well. I often find though that projects with patching strategies are missing the scripts to apply these automatically when the code is deployed, so I thought I’d share mine.

My current project (BiteStats, a simple report of your google analytics data) uses a basic system where there are numbered patches, and a patch_history table with a row for every patch that was run, showing the version number and a timestamp. When I deploy the code to production, I have a script that runs automatically to apply the patches.

Continue reading

Invalid Protected Resource URL in Pecl_Oauth

I had a funny (funny weird, not funny haha) problem the other day when working with pecl_oauth in PHP to talk to a service. I’d gone through all the handshaking steps, got the acces token and was ready to start talking to the service itself. However when I tried to call OAuth::fetch, I got an error message:

Fatal error: Uncaught exception 'OAuthException' with message 'Invalid protected resource url, unable to generate signature base string'

There are two things to notice about this. The first one is that I should be catching exceptions thrown by this code :) The second is that I could see nothing wrong with my url, http://api.local. It turned out, after some experimentation, that what is missing here is a trailing slash, and if I supply http://api.local/, everything works perfectly nicely! I’m unclear if this is intended functionality or not, but if you see this error message and you’re requesting a URL with no path info, make sure you have a trailing slash.

PDF Presenter

Recently I’ve switched how I prepare and deliver presentations, using LaTeX to mark up the content and producing PDF slides from that. Which is great but I miss having some of the during-presentation functionality of LibreOffice such as a timer and being able to see what’s on the next slide. Happily for me, there’s a PDF Presenter Console on github and it does what I need!

Getting the thing installed was a bit of a puzzle as it has many dependencies (and that’s just the compiler) but I now have it working like a dream on both my laptop and my netbook. I discovered that it didn’t work with my presenter mouse but with a bit of help from a friend, I have a patch for that and now when I’m presenting I see something like this:

You can set which screen show this, and which shows just the main slide, and you can also set what duration the countdown timer should start from. One really key feature is that the timer doesn’t start counting until you advance from the first slide … unlike in open office where I usually put up the title slide during the break before my talk, then have to stop and start the presentation to reset the clock so I’ve got some vague idea of my running time!

So in true open source form, there’s a tool out there already (thanks Jakob, and thanks for responding to my emails!), and I was able to adapt it to my use case, or rather Kevin was able to! I would love to have the presenter console packaged so I could recommend it for more users, but for now I have a great open source solution enabling me to do what I’m good at – delivering content.

Downgrading a PECL Module

Recently I saw some weirdness in an existing application when I upgraded a PECL module that the application depended on. To figure out if that really was the problem, I wanted to downgrade the module to its previous version. There is no opposite command to “upgrade” but you can instruct pecl to install a specific version of a module, using the -f switch to force pecl to overwrite newer modules.

Downgrading Pecl_OAuth

For me the problems were caused in the switch between default functionality in pecl_oauth 1.1.0 (this isn’t a bug, but is correct behaviour according to the OAuth 1 spec, I just had code that expected the old functionality), so I wanted to put my version back to 1.0.0

pecl install -f oauth-1.0.0

It was easy once I stopped looking for an option called “downgrade” or something like that :) In fact you can use this trick to install all kinds of pecl versions, simply refer to the package as [package name]-[version]. By default pecl won’t let you install packages that aren’t marked “stable”, but you can install beta packages by putting “beta” in place of [version].

Hopefully now I’ve written this I’ll remember next time how to do it!

Slide Markup with LaTeX: First Steps

Since starting to create (a large number of) presentations using LaTeX, I’ve been impressed at how easy this is to pick up and also how quick it is to work with marked up content rather than dragging objects around in Impress or equivalent. With that in mind, I thought I’d outline the very basics of the markup (with probably more snippets to follow as I discover them).

Start at the very beginning

First of all, LaTeX templates are fussy things, start with someone else’s outline (for example the one Dave posted, which I use), or one you made earlier. There is some preamble and then the main contents of the presentation go between the \begin{document} and \end{document} bits.

Continue reading

Summer PHP Conferences

Conference season approaches and in May I’m on a trip to take in two of the most high-profile events in the PHP conference calendar: DPC in Amsterdam (19-21 May) and php|tek in Chicago (24-27 May). The two events have historically been a few weeks apart and I’ve always complained at having all the fun for the year in such a short space of time – but this year the events are literally back-to-back, there are a small number of speakers attending both and we’re pretty much all on the same flight from Amsterdam to Chicago!

Continue reading

Creating Presentations with LaTeX

This spring/summer, I’m giving quite a few talks at conferences, and I have a number of my own clients that I’m writing new training materials for. That’s a lot of content in total and so, inspired by Dave’s article about LaTeX and powerdot (and with some help from Dave himself!), I’ve started to write my own presentations this way too.

Getting started was a struggle, I’ve never really used anything like it before and if there’s one thing LaTeX doesn’t do well, it’s error messages! The blog post I linked above has a sample presentation in it and I used that as my starting point. The source code goes in a file with a “.tex” suffix, e.g. presentation.tex. I then installed the texlive-latex-extra, latexmk, vim-latexsuite, latex-fonts-recommended and texlive-fonts-extra packages from aptitude, and generated a PDF by running:

latexmk -f -pdfps presentation.tex

Continue reading

Basement Tanking Project

At one time I wrote a lot on this blog about houses, and this house in particular once we bought it 4 years ago. One major feature is that the basement kitchen floods fairly regularly, maybe 4 times a year? This is obviously not ideal however the structural work required to put it right was around 20% of the value of the house, and shortly after we bought the house the bottom dropped out of the UK property market so we couldn’t borrow against the house.

Fast forward 4 years of cooking in wellies once in a while, and running down the stairs to check the basement every time it rains a lot (in Northern England, you can imagine this gets really old really fast). Actually even when it wasn’t underwater, it was a pretty nasty kitchen, always damp and it had no heating so in winter it was whatever temperature it was outdoors. This sums it up: my mother’s old dresser, standing on bricks to keep it out of the water
Kitchen Dresser on Four Bricks

Continue reading

Getting Dates From Week Numbers in PHP

Recently I’ve been building a little project that pulls data from Google Analytics and shows your web statistics in a simple form. One thing I wanted to do was show the data for a quarter, but graphing by day is too chaotic and graphing by month only gives three points, so I wanted to graph by week. This was fine but the data returned by Analytics only gives me the week numbers, and since this project is aimed at demystifying web stats for normal people, it really needs normal dates on it!

Using DateTime::setISODate

I found that the DateTime extension has a method setISODate() which accepts the year and week number, and makes a date you can then use as normal.

$week_start = new DateTime();
$week_start->setISODate($year,$week_no);
echo $week_start->format('d-M-Y');

You can also do this the other way around; if you have a date in PHP, there’s the ‘W’ flag for date() which will return you the week number – very handy!