Watch out for #python dict-based string interpolation examples which look like this:

'Hello, %(name)s' % {'name': 'Otter'}

That s after the brackets isn’t pluralising one adorable aquatic mammal into a whole bunch of them, it’s actually part of the interpolation placeholder — the equivalent of

'Hello, %s' % 'Otter'

Note also that for some reason, python lets you put spaces between the closing bracket and the type signifying character. This can cause extremely weird bugs when the string being interpolated is also being translated. For example:

_('%(customer) shared a thing') % {'customer': 'Mr. Bean'}

If not translated, this will produce this confusing but fairly easy to debug output

'Mr. Beanhared a thing'

But if 'shared' is translated into a word beginning with, for example, d, you’ll just get an exception like TypeError: A float is required

If you’re working with undocumented lat/long coordinate data and, when plotted, everything’s coming out sort of in the right place but a little way off, check to see whether or not what looks like decimal lat long data is actually traditional DMS data.

For example, I recently had to parse and plot a bunch of coordinates which looked like this: 6359550-2154605. I initially thought it was decimal lat/long data missing decimal points for some reason, so I plotted it as 63.59550, -21.54605. All of the coordinates were in the right place relative to each other, but about 1/3rd of a degree off. Turns out the data actually needed to be plotted as 63˚ 59' 55.0", -21˚ 54' 60.5".

Here’s the python I wrote to clumsily convert the strange original form into decimal:

Note that the Kindle downloaded the PNG despite having pretty good SVG support. Tests carried out locally by watching the Django request logs.

At first, this looked perfect — browsers which supported SVG only downloaded the SVG (apart from IE 10), and other browsers just got the PNG. However, it seems that SVG image elements can’t be sized with percentages, meaning our flexible layouts were never going to work. I tried to fix it using the dreaded viewBox and user units (as I have previously to compensate for percentage-based units not being allowed in SVG paths), but that just led to everything being completely the wrong size.

So, (unless someone can show me how to fix this), whilst we think this is a great hack, it’s not going to work out for our product due to the weirdness of SVG sizing limitations.

I just faked having a task queue for #taproot#indieweb note posting tasks using Symfony HttpKernel::terminate() and it was the easiest thing ever.

Instances or subclasses of HttpKernel have a terminate($request, $response) method which, if called in the front controller after $response->send(); triggers a kernel.terminate event on the app’s event dispatcher. Listeners attached to this event carry out their work after the content has been sent to the client, making it the perfect place to put time-consuming things like POSSE and webmention sending.

Once you’ve created your new content and it’s ready to be sent to the client, create a new closure which carries out all the the time consuming stuff and attach it as a listener to your event dispatcher, like this:

Then, provided you’re calling $kernel->terminate($req, $res); in index.php, your callback will get executed after the response has been sent to the client.

If you’re not using HttpKernel and HttpFoundation, the exact same behaviour can of course be carried out in pure PHP — just let the client know you’ve finished sending content and execute code after that. Check out these resources to learn more about how to do this:

Further ideas: if the time consuming tasks alter the content which will be shown in any way, set a header or something to let the client side know that async stuff is happening. It could then re-fetch the content after a few seconds and update it.

Sure, this isn’t as elegant as a message queue. But as I showed, it’s super easy and portable, requiring the addition of three or four lines of code.