ChatGPT might be a game changer for coding

So I’ve had on my to do list for a while a bit of coding to take an input text and add ‘rel=”nofollow”‘ to any links that don’t already have it set. In theory it’s a straightforward thing to do, either use a regex or something like DOMDocument to parse the text. But it’s a bit of a faff and I haven’t gotten round to it yet.

I have though having a play around with ChatGPT and chatting to a friend he said “have you used it for coding yet”. So I thought this one might be a good place to start checking it out and wow is it good.

ChatGPT coding

As you can see from the screenshot above in a matter of a minute or so I have my function. But looking at that I thought “I wonder if it’d be better with regex”. So why not ask?

It’s a simple as typing “rewrite the function using regex instead of DOMDocument” and here’s the new output.

function add_nofollow_to_links_regex($text) {

// Define the regex pattern to match tags and their attributes
$pattern = '/]*?\s+)?href=(["\'])(.*?)\1(?:[^>]*?\s+)?(.*?)?>/i';

// Replace all tags with modified versions that include rel="nofollow"
$modified_text = preg_replace_callback($pattern, function($match) {
$href = $match[2];
$attributes = $match[3];
$nofollow = 'rel="nofollow"';
// If the link already has a rel attribute, add nofollow to it
if (preg_match('/\brel=([\'"])/i', $attributes, $rel_match)) {
$rel_value = $rel_match[1] . $nofollow . ' ' . $rel_match[1];
$attributes = preg_replace('/\brel=([\'"]).*?\1/i', $rel_value, $attributes);
}
// If the link doesn't have a rel attribute, add it
else {
$attributes .= ' ' . $nofollow;
}
// Return the modified
tag
return '
';
}, $text);

return $modified_text;
}

// Example usage:
$input_text = "This is a
link to a website.";
$output_text = add_nofollow_to_links_regex($input_text);
echo $output_text;

I really think ChatGPT does have the power to be game changing here, there are a few caveats though, one being I think you need to have some idea of what you’re expecting back and I’d probably make sure to test what you’re getting quite thoroughly as well. But if you learn how to ask and refine your requests you can get some great stuff back.

There’s a great podcast from Drowned in Sound that whilst it approaches it from a musician perspective gives some great info about how to use these new AI tools

https://podcasts.apple.com/gb/podcast/dis005-how-music-can-embrace-the-power-of-ai/id1037405920?i=1000601175249

Check out David Boyle’s book prompt as well (he’s the one interviewed in the podcast)

https://prompt.mba/

Little Wing Dev – A rebrand and a few changes

So like everyone 2020 has been some year so far. One big thing for me is moving from full time to part time flying, a little earlier than planned and a little more part time than I had planned to. The upshot of which is I’m doing much more web development work and enjoying it!

Ahead of this I started a little bit of a rebrand, but managed to pick up work quite quickly and as with all good “internal” projects it gets pushed back. However I have finally launched my new site and essentially rebranded my dev side of work to https://littlewingdev.uk As you’ll see when you visit the site I’m not really keeping a full portfolio, mainly because of the fact I’m doing a lot of “white label” type work and joining clients as part of their in house teams to help clear backlogs and plug gaps in experience.

I’ll be keeping the site here as my blog slightly separate and hopefully start to post a few more web posts (I already have a few drafts started!)

Moving Hosts

I’ve also moved my hosting. I’ve hosted with Media Temple for over a decade but having found clients I work with often want a U.K. based service recommended I decided to switch over myself so I’m now with TSO Hosts and all is going well so far.

So why not check out the site at https://littlewingdev.uk and let me know what you think.

Taking out the trash – unset and wp_cache_flush to free up memory

I’ve been working on a third party API plugin for WordPress that requires a script that auto updates from the API. It consists of pulling a big list of items from the API and checking them against the local site entries, often adding new items or updating existing entries.
The problem was with a number of memory allocation errors with PHP as the script went on, often about half way through the execution. Memory exhausted and Fatal Allowed memory issues popping up. A memory limit change would fix the problem to a point, it would still leave issues though – to work through the full list of items would need a very high PHP memory limit and also what happens if the list gets bigger in future? When 64Mb stops being enough do we simply up it to 128Mb what about when that isn’t enough do we carry on upping it? That still leaves a period where errors are being thrown and updates are missed until it is picked up and the memory limit is upped.

I made sure I called wordpress without themes to reduce a little bit of load and a quick check through to make sure unset() was being used as it should be – I’ll admit my code discipline has been lax in the past with regards to this but as ever we are always learning and making sure that we can improve our techniques. Unsetting things properly to free up the memory is one of those things I now make sure I’m doing rather than just overwriting old variables.
So the script was unsetting as it should and with diligent debugging with php memory usage outputs it became apparent that it was around WordPress functions that the memory usage was going up and not being unset, gradually leading to the errors. Plenty of looking around and eventually I stumbled upon wp_cache_flush and it worked a treat – every time I went around a processing loop or finished a process I called the cache flush and it removed all the stuff WordPress had been storing. I’m sure this wouldn’t be the best fix all for every situation but it’s certainly something to be well aware of.

Adobe Fireworks – do not resuscitate

If you haven’t seen it already Adobe made an announcement yesterday about the future of their Fireworks software. Sadly for those fans of Fireworks it confirms the ever looming spectre that Fireworks is being put to bed and no longer developed.
It does surprise me a little that so many people seem to find this news unexpected, maybe they’ve been ignoring the inevitable? In the last iteration of updates most Adobe products got an updated darker interface, notably Fireworks didn’t, it’s not been looked at favourably for a while – it’s been on life support with Adobe and they’ve pretty much said it’s now do not resuscitate.
Continue reading

The web has made customer service so easy – stop messing it up

One of the great things about the web is the ease of communication, the ease of access it allows people to resources. Not just piles of data on Wikipedia but access to people and companies.
It has made customer service incredibly easy to do and yet so many organisations still do it badly. Some will complain that they are limited by budgetary constraints but customer service on the web is not just easy, it’s cheap.
I regularly take to twitter with my customer service issues and questions and its great when you get some dialogue and a question answered. It makes a huge difference to your perception of a brand and how much does it cost to set up a twitter account? Nothing. Ok admittedly you have to get someone to manage it but the setup cost is nothing.

But good customer service doesn’t start and end with twitter, so here are my major online customer service gripes and I’ll start with twitter.

Continue reading