After more than 20 years as a professional developer, I published my first dirty Open Source project
Tags: php, opensource, programming, showdev
Published: 2023-10-25 17:31:52

I've been a professional developer for more than half of my life, and an Open Source advocate since GitHub came to be.

When people ask me "But Jérôme, I'd be embarrassed if anyone saw my code. They would think I'm a bad developer", to which I'd answer that _somebody_ will find useful, practice is progress, and they might get valuable feedback.

However, I never followed my own advice. When I publish an Open Source project, it has to be "serious", I'm a professional developer and that has to show.

A few years (three at the time of this post) ago, [I reported an issue I had](https://github.com/samuelclay/NewsBlur/issues/1387) in the (Open Source) RSS Feedreader of my choice, [NewsBlur](https://www.newsblur.com/).

The categories of RSS feeds from my bookmarks service, [Pinboard](https://pinboard.in), were all concatenated to a single string instead of being displayed separately.

I'm subscribed to the [Pinboard Popular](https://pinboard.in/popular/) Feed. It provides posts that have been bookmarked by other Pinboard users and allows me to learn about topics I would otherwise not be aware of. 

As categories, among other criteria, are used to filter articles in NewsBlur (my favorite feature), this made it difficult to train Pinboard feeds to not show the ones that don't interest me.

Last week, I had a little bit of time and decided I would finally tackle this.

I first tried it the "professional" way: I wanted to create a PHP Pinboard SDK and then use it to parse the RSS feed and fix the categories.

As it turned out, parsing RDF XML feeds is not an easy task. The native way of doing it in PHP is cumbersome, and the libraries I tried  were throwing errors.

I then remembered my advice from above and did what I never did before: I made it quick and dirty.

* Instead of using an HTTP client, I used `file_get_contents()`
* Instead of parsing XML, I used regular expressions. ([You shouldn't do this](https://stackoverflow.com/a/1732454/284325)
* Instead of using OOP, I didn't

And guess what, it worked, and the code fits into one screen on my mobile phone.

![Screenshot of the code on my iPhone 14 Plus](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlnngvrsy9slcxho22k1.png)

I added a GitHub workflow that runs the script and publishes the fixed feed to GitHub pages, and subscribed to that one in NewsBlur.

Done!

I'm sharing this here to prove my point, because it could be useful to someone with the same problem (as unlikely as it is), and because I'm actually proud that the code is dirty.

If you're interested, have a look at it, and fork the repo if you want to adapt the script to your feed needs. 

{%embed https://github.com/jeromegamez/pinboard-for-newsblur %}

And if you want to subscribe to my, always super-interesting haha, bookmarks, you can find them at https://pinboard.in/u:jeromegamez

Happy dirty coding!

PS: This post follows the same principle: I wrote it on my phone, it has probably some typos and semantic errors, but I can revisit it later - or keep it as it is, because it already transports what I want to say.

PPS: Point in case, I had a typo in the title and that typo will be in the post URL for all eternity 🤷🏼‍♂️.

PPPS: I'm on a Mastodon, too!

{% embed https://phpc.social/@jay/111296868388229467 %}