Date Published: 31 March, 2019

Catching Mail with MailCatcher

MailCatcher

[MailCatcher] is a powerful and easy to use Ruby gem that acts as an SMTP server that allows you to inspect emails that your application is sending out in your dev environment.

Installation

Installation is pretty simple, these are the commands that I used on my Fedora 29 install to get it up and running. If Ruby is already installed on your machine, or if you've already installed other Ruby gems, you may not need the first few lines.

Read More
Date Published: 23 March, 2019

Uses

Inspired years ago by [Scott Hanselman's tool list] and more recently by [Wes Bos' uses] and prodded into action so I could make a pull request to the [awesome-uses] repo by Wes Bos, here is a list of the tools that I use on a daily basis:

Operating System

  • [Fedora] - currently using version 29. I've been using different flavors of Linux off and on since 2009, but after switching to Fedora (26?) in November of 2017 from Win10 both at work and at home, I haven't looked back since...

IDE's/Code Editors

Read More
Date Published: 17 March, 2019

Automating Conventional Commit Messages - Globally

I am constantly on the lookout for ways to better myself as a developer. This includes not only getting better at the actual art of coding but also improving the processes of coding and finding ways to streamline and/or automate these processes. One of the areas that I had already (mostly) improved on is writing useful commit messages, so my git log doesn't end up looking like this XKCD comic:

One bad habit that is easy to fall into as a solo developer (especially under a time constraint) is to rationalize ignoring or delaying proper documentation since you're the only one working in the codebase it is easy to think that documentation is unimportant. And it is. Until it isn't - and then it is really important.

So that is one area that I am constantly trying to improve in. A git commit message is an oft-overlooked and undervalued form of documentation, so how can we improve here? I had already been, for the most part, following [The seven rules of a great Git commit message]. They made sense and were easy enough to implement, and almost got me to where I wanted to be as far as git commit messages were concerned.

Read More
Date Published: 9 March, 2019

php logo

Unit Testing Dates and Times with Carbon

One area of my codebase at work that I had problems sufficiently testing were instances in my code base that had time based logic to them. Since I work in the manufacturing sector, lots of logic relies on knowing what the current, last, or next shift is. There are lots of edge cases that need tested around shift change, especially third shift, which starts before midnight, but for all the reporting and other facets of my software it is technically tomorrow.

So these time-dependant functions for the most part did not have useful, functional unit tests, until recently. In the past I would write my logic, cross my fingers and wait for the bug reports to come rolling in. I'm so thankful that I discovered this testing aid built in to the [Carbon] PHP library. (If you haven't used Carbon, stop reading and go check it out, I'll forgive you. It makes working with dates and times in PHP a walk in the park, it is one of the most useful libraries I use!)

So now you are wondering, "What is this wonderful function that will let me test my date/time based logic easier?" I'm glad you asked. It is the setTestNow() function built in to the [Carbon] api. Basically, this allows you to determine when now() is.

Read More
Date Published: 3 March, 2019

Creating an RSS Feed for a Symfony Blog

Introduction

One of the features I've wanted to add to this blog for a while now, but kept putting off, until now, is an RSS feed. I recently created an account on [connect.symfony.com] and there was a spot to add an RSS feed to one's profile, which was the only thing stopping me from getting my profile to 100% and earning the "Profile completed" badge. Nothing like a little gamification to make me stop putting off this task.

Since I'm never one to re-invent the wheel, without justification, I of course looked to see if there were any Symfony bundles that would allow me to easily add an RSS feed to my blog. "Easily" being the keyword in that sentence. I did find several of bundles, but all of them seemed to have convoluted configuration, with a learning curve much steeper than rolling my own.

Oh, yea, you can see it in action here: https://eidson.info/rss

Read More
Date Published: 23 February, 2019

Override a trait in PHP

php logo

I encountered a situation recently in which I wanted to change the method signature for a method that was injected into a class via a trait, namely changing the default parameter. I wanted to do this so I didn't have to pass in the new default parameter every place that I called this method on this particular class.

Overriding the method, was easy enough. As soon as a new method is declared in a class with the same name, the trait method is overridden. The tricky part was calling the 'parent' method from the 'child' method, so I didn't have to duplicate the logic inside my new method. I tried parent::methodName() and TraitName::methodName() before running off to the google machine to learn the proper way to do this.

It turns out that it is as easy as creating an alias for the trait method name in the "Use" statement, which made perfect sense after I saw it.

So, if this is the trait that you want to use and override:

Read More
Date Published: 17 February, 2019

Global Hooks with Git

Introduction

Recently I began to wonder if there was a way to have a collection of [git hooks] that could run on all of my git projects to save me the trouble of creating/editing hooks in each of my projects. Yes, it is possible to do this for new projects, via the git config --global init.templatedir command, but I have a lot of pre-existing git projects that I wanted to add a pre-push hook to, and I wanted to be able to make alterations to this hook after the fact that would affect all my projects. Apparently, I'm not the only person who needed this feature, because it was added in git release 2.9.

Details

Adding the global hooks was easy enough, thanks to this [stackoverflow] answer, but I did run into a couple of caveats after I had the global hooks path set.

Read More
Date Published: 10 February, 2019

Version Bump for git using Fish Shell

Intro

One feature that I really like from npm is the version command which handles bumping either patch, minor, or major version number following the [Semantic Versioning] standards. This sets the version attribute in your package.json file and creates a [git tag] using the new version number.

For example you can run the npm version minor command from the root of an npm project and it will change the version from 1.2.12 to 1.3.0 write this out to your package.json file and create a git tag for the new version.

Since the vast majority of my projects are php projects and not npm, I don't get a chance to use this feature nearly as much as I would like, so I found myself wishing there was a way to do this directly from git.

Read More
Date Published: 10 December, 2017

Alphabetize your Way to More Readable Code

Super short and simple post this time, because it's explaining a simple concept. The concept is so simple, that I'm slightly embarrassed, almost shocked, that it took me almost 7 years of professional programming, and 3 and a half years of college to see and use this pattern.

The tip? Any time you are writing code and the order of the lines is irrelevant, such as declaring class variables, creating a JSON object, populating an associative array, adding dependencies, configuring your configuration, ad infinitum, use alphabetical order.

Instead of:

Read More
Date Published: 4 December, 2017

filter_var() is Your Friend

Intro

I was recently reading a blog post by Aaron Saray called In PHP, False is Sometimes True. This is an issue that I've encountered in the past and I'd already considered blogging about the solution, which is something Aaron left out of his blog post.

Read More
Date Published: 30 November, 2017

Create a File Watcher for php-cs-fixer in PhpStorm

File Watcher Settings for Linux

Intro

This is a quick an easy guide to setting up a file watcher on PhpStorm so that every time a php file is saved, php-cs-fixer is ran on the file. More than just a linter, php-cs-fixer will update your code to match coding standards such as the official PSR-1 and PSR-2, as well as community standards such as the Symfony one. It will also do some

Read More
Date Published: 26 November, 2017

php 7.3 - Flexible heredoc & nowdoc Syntax

php logo

Although we've still got a while to go before we see php 7.3, since we're still 4 days away from the release of php 7.2, I've already seen one new feature that looks like it will make its way into 7.3 that I am excited about. This feature is more flexible syntax for heredoc and nowdoc statements. Here is the official rfc if you'd like to read it.

What are heredocs and nowdocs?

Read More
Date Published: 24 November, 2017

The Joy of Rotating Logs in Symfony

logs

Switching from my hand-made, hodgepodge, cobbled together collection of libraries that was trying to act more and more like a "framework" every day to a full-blown real, properly developed, properly tested framework like Symfony continues to be the best decision I've made in my programming career thus far. I've learned so much about clean code, design patterns, SOLID principles and many other programming best practices from working within Symfony's MVC (Model View Controller) pattern and reading its documentation and code when I need to extend it to bow to my every whim.

Read More
Date Published: 19 November, 2017

Editing Shared Libraries in PhpStorm with Composer and git

Composer logo

The "Old" Workflow

When I started my current position way back in the winter of 2013 as the sole Application Developer in a corporate/enterprise environment, I was tasked with maintaining existing web applications, porting Visual Basic apps into a web environment, as well as creating new applications. Each of the php applications that I had inherited had several shared dependencies that were maintained independently in their separate project directories. Any bug that was found and fixed in one of these 'libraries' had to be copied manually to the other projects

Read More
Date Published: 12 November, 2017

PHP_EOL is Broken (Sometimes)

php logo

What is PHP_EOL?

Introduced in version 5.0.2 of php, PHP_EOL is a string constant that represents the correct end of line symbol for the platform that you are running php on. So on Windows this should be set to "\r\n" (carriage return and line feed) and on a *nix system it should be set to "\n" (only line feed).

Read More
Date Published: 22 October, 2017

Code Highlighting in HTML

alt text

I've been wanting to start blogging for quite some time now, and I figured there is no time like the present. I am familiar with both WordPress and Drupal, but I wanted to "roll my own" both for flexibility and as a learning experience. Since this blog is going to be code heavy, one thing that was really important to me was code highlighting in the display. I really like the code highlighting on the Symfony documentation pages, and I've used that in some of my own documentation pages, however, that is using Sphinx and .rst files, which requires a compilation step. I was looking for a way to have markdown files parsed by a real-time HTML converter to give me syntax highlighted code in HTML. That's how I discovered highlightjs.

Read More

About Todd

Full stack application developer. Life-long learner. Pragmatic programmer. Believer in clean coding. Proponent for extensible and reusable code. Hobbies include (very) amateur photography, collecting old jazz records and going to live music performances.

North Central Ohio, US
toddeidson[dot]info

Obligatory Disclaimer

All opinions are my own, probably wrong, and subject to change without notice.

© 2017-2019 Todd Eidson. All content is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

Hosted on linode