Page 2 of Software Development Articles

Setting an authorization header when using file_get_contents with PHP

Going through some of my old lists of blog post ideas this weekend. While it’s not something I’ve needed for a minute, it’s still something worth taking about. How to set an authorization header when using PHP’s wonderful file_get_contents() method. Similar to an old post of mine talking about specifying […]

Find unused npm dependencies

As much as I love to sling code, I love that we live in a world where you can stand on the shoulders of giants and easily leverage other people’s hard work by way of Open Source libraries. Simply referred to as “dependencies”, these little code gems can save a […]

Repeating Strings in JavaScript

While cleaning up some of my old notes today, specifically stuff I jotted down that would make for a good blog topic, I happened upon the topic of repeating strings in JavaScript. Things are really easy in ES6+, but if you happen to still support Internet Explorer for some crazy […]

Uninstalling dev dependencies with npm

While looking into some deployment issues recently, I ran into some logic that was in dire need of being refactored. The logic in the build process was installing all dependencies with npm, then removing the node_modules directory, just to install the production dependencies again. Yes, you read that right, the […]

Overengineering Challenge: Is Number Even or Odd in JavaScript

Code golfing is fun, and makes for great blog posts. The problem is, the world is flooded with posts attempting to show you how to write the best / most concise code imaginable. With that, I decided that it would be a fun challenge to attempt to take a simple […]

Recursively create directories with Node.js

Recently, while working on a new project, I needed to create a series of nested directories. From the command-line, it’s easy enough, just pass -p to mkdir and it will create all of the parent directories automatically. With modern versions of Node.js, specifically 10 and above, you can achieve the […]

Displaying an entire object with Node.js

For the most part, I do the majority of my debugging with Node.js / JavaScript’s console.log(). It’s quick and dirty but it gets me what I’m looking for. The exception being when I am working with larger objects, specifically any object that is nested three or more levels deep. Here’s […]

Juggling assertion syntax between PHPUnit versions

I’m no stranger to the nuances of testing against different version of PHP and PHPUnit, but my previous issues were related to the environment itself. Recently I ran into an issue with different syntax between versions of PHPUnit, specifically assertRegExp() being deprecated, which was throwing an error. Not only was […]

Passing a test without assertions with PHPUnit

While it may seem counter intuitive to have a test that doesn’t have any assertions, PHPUnit’s unique method of sharing data between tests can put you in a situation where you have a test that just doesn’t need to actually test anything, and simply returns some data. In those scenarios, […]

How to comment source code

One of the biggest offenses that I’ve seen over my entire software engineering career is a total disregard for code comments. I don’t subscribe to the idea that code should be self documenting. I do believe that human are inherently forgetful and code left undocumented is code that will bite […]

Allow dots in paths with webpack-dev-server

Generally speaking, I don’t use dots (periods, full stops, whatever else they may be called) in the URI for a website. That was, until I made the . an allowable character for user names on one of my projects. Allowing the character was a big deal at all with Express.js […]

How to get the first and last item from an array in MongoDB

One of the great features of MongoDB is the ability to store an array in a document. While I’m fully aware that there are issues with storing unbounded arrays in MongoDB, due to document size limitations, there are times when you may want to store data in an array that […]

How to set the background color of a Google Chart

As luck would have it a Google Chart I had created some time last year, which was looking great for a while, recently decided that the background color of the chart itself was going to switch from the color I had set to the default color, white. This was quite […]

Increase memory limit for Composer

Gone are the days of stitching together disparate services in an effort to create a solid continue integration and deployment pipeline. GitLab has had it’s Runners for a while and recently GitHub stepped into the mix with their Actions offering. Because of this, using external services like Travis CI or […]

How to escape curly brackets in Liquid templates

My blog is generated by Jekyll. Jekyll uses Liquid for it’s templates. I include a decent amount of source code in my articles and sometimes the syntax collides with Liquid’s own syntax. Then this happens: Liquid Warning: Liquid syntax error (line 34): Expected end_of_string but found comparison When that, happens, […]

Only run step for specific version with GitHub Actions

With my recent exploration of GitHub Actions, I’ve had to figure out things that I’ve already figured out with other systems like GitLab Runners and Travis CI. One such thing is conditionally running steps. For things like code coverage, I’m only interested in sending off the coverage report to the […]

Hiding scroll bars while maintaining scroll functionality in modern browsers

As I’ve been rebuilding my social network from the ground up recently, I’ve been extremely mindful of the fact that 60% of my users are experiencing the site on a mobile device, specifically phones. Because of this, I’ve been attempting to craft a user interface that functions nearly identical on […]

Moving from only syntax to rules syntax in GitLab CI/CD v13.x+

Saw a recent announcement from GitLab that the only and except syntax for GitLab CI/CD was going to be deprecated soon in the v13 release. Amendment: The only / except syntax isn’t actually being deprecated as pointed out by Jason Yavorska. It’s actually related to a template that is deprecating […]

Recursive functions in TypeScript

In working with the Slate framework for building rich text editors recently, I found myself faced with a scenario where I needed to loop through the editor’s value. The value that comes out the editor is an array of objects that is nestable, I assume infinitely, by way of the […]

Recursive types and interfaces in TypeScript

When writing out a type or interface in TypeScript for something that will be fed into a recursive function you could cop out and use any or you could properly define the structure. Fortunately, both type and interface allow you to be self referential in terms of defining properties. Let’s […]

Error: Cannot resolve a DOM point from Slate point

By way of recommendation (thanks Brewer), I’ve been messing around with Slate.js a ton. Such is life, I did have my fair share of issues, particularly in terms of getting it to function like a chat message input where hitting Enter will submit the form and reset it to it’s […]

Resetting a Slate.js editor to an empty state

I’ve been messing with Slate.js and happen to be using it in the context of having a persistent editor on the page that can be used post from. It’s sort of like a chat’s message input, it’s always there, and when you submit it, it resets back to it’s original […]

Resetting the undo/redo history of a Slate.js editor

Slate.js has some wonderful undo/redo history under the hood, by way of the React hook useMemo. Out of the box is works great, but if you want to reset your editor back to an empty state (in scenarios where the component is persistent on the page), the undo/redo history will […]

Submit on enter except when shift is pressed in JavaScript

Been working on something recently where I wanted to implement a submit handler when a user hits the enter key in an input. That’s not that big of a deal, sniff out the key being pressed, and if it’s the Enter key, go ahead and execute the submit handler. Since […]

Detecting modifier keys being pressed with JavaScript

Been hot on a new [old] project recently and I’ve not only been coding my ass off, but delving into some territory that I haven’t delved into as of late. The latest is in terms of determining if a modifier key has been pressed in conjunction with another key press. […]