I recently learned the hard way that
brew update can break a PostgreSQL install. Googling around there seem to be a variety of problems and solutions to this scenario.
I was able to get back up and running by relinking my PostgreSQL installation. That seems too easy. I now live with the nagging doubt that something worse is waiting for me in my PostgreSQL install.
To quickly setup a backup process I use the command pg_dumpall in tandem with gzip. pg_dumpall creates a SQL file to recreate my databases and gzip compresses it.
In testing, a pg_dumpall produces a 937M file. Using it with gzip downsizes it to 137M.
Here is the command below. I’ve configured this in my cron jobs to happen every evening Monday through Friday.
pg_dumpall --clean | gzip -c > dev_db.psql.gz
Restoring from backup is just as easy.
psql -f dev_db.psql postgres
Poking through some Pull Requests I spotted syntax I’ve never seen before and found difficult to google:
The “&.” was introduced in Ruby 2.3.0 as the Lonely Operator. It prevents the error “NoMethod error on Nil”. If the object is nil it just returns nil. Otherwise it continues down the chain and gives the intended result.
This allows us to skip the heavy handed code of
person && person.job && person.job.company && person.job.company.id
Using the Lonely Operator looks better. It does have valid criticisms against it. First, it doesn’t address the original issue: having a null object when you weren’t expecting it. A reliable and recommended solution is the Null Object Pattern. An author by the name Franzejr has a clear Ruby implementation of the Null Object Pattern.
Second, this encourages us to violate the Law of Demeter. The problem of getting a persons company id is the tight coupling between those objects. This increases the cost of maintenance and chances for technical debt.
I’m curios to see where the Lonely Operator goes. I’m happy to have it in my tool belt. It simplifies chaining multiple methods. It accommodates legacy code where the Null Object Pattern may complicate a code base further.
While researching Ruby’s Lonely Operator I found the following articles helpful:
Let me know what you think in the comments. I’m curios how often you find the Lonely Operator in the wild and if you use it.
When starting Terminal you may notice a ‘You have mail’ message. You may even know of the mail command and how to traverse your mail.
This can be unexpected if you’ve never configured a script or service to send mail to your user. However, some services, like crontab, are configured to send STDOUT to your mail account by default.
The convenience of mailing logs, error reports, or statuses can be sullied by learning and tracking another system. As always, there is an easier way.
A .forward file or ‘dot forward file’ in your home directory will tell your system where that mail should go. Simply running the below will redirect that mail to your account.
echo "email@example.com > ~/.forward"
You can include multiple addresses and separate them by comma “firstname.lastname@example.org, email@example.com”.
This allows you to receive the notifications in the mail application of your choice.
The dot forward file is a part of dot-courier. It can be configured to send mail to a program or append to a file. I found Dr. Nikolai Bezroukov’s article to be helpful in understanding what the dot forward file can do.