Category: Software Development
-
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…