Import Environics demographics data into a SQL database via Laravel CLI command

Environics Analytics provides incredibly useful demographics, psychographics and segmentation data for Canada, but the raw data is challenging if the goal is to use it in a general SQL query: The raw data is in one file, the meanings of the columns are in a ‘metadata’ file, and the data provided doesn’t necessarily just list postal codes but other geographic areas as well.

Linked below is a Laravel CLI command that outputs a .SQL file that will handle the creation and insertion of data and definitions for you. The CLI command is invoked as follows:

php artisan environics_demographics:import {csv_demographics_definitions} {csv_demographics_data} {year_demographics_data} {dir_output_data}

Find the full script on GitHub Gist, or below:

Merge a PHP array without duplicates (array_merge_recursive_distinct)

Often enough in PHP, you’ll grab objects from a variety of sources and want to merge them into a single array of results. To merge without duplicates, add the following function to your codebase and make use of array_merge_recursive_distinct the same way you would array_merge_recursive:

// From:
if (! function_exists('array_merge_recursive_distinct')) {
     * @param array<int|string, mixed> $array1
     * @param array<int|string, mixed> $array2
     * @return array<int|string, mixed>
    function array_merge_recursive_distinct(array &$array1, array &$array2): array
        $merged = $array1;
        foreach ($array2 as $key => &$value) {
            if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
                $merged[$key] = array_merge_recursive_distinct($merged[$key], $value);
            } else {
                $merged[$key] = $value;

        return $merged;


Upgrade a deprecated AWS Elastic Beanstalk environment in place using the CLI

When a major PHP version change (eg. 5.7 to 7.0, or 7.0 to 8.0) occurs, Amazon AWS Elastic Beanstalk typically does not allow for automated platform version updates but instead requires the cloning of an interface and a CNAME switch. For less available environments, use the following steps to upgrade-in-place using the AWS command line interface:

  1. Take a look at the list of currently supported PHP platforms on Elastic Beanstalk; you’ll want to decide which Solution Stack Name (eg. “64bit Amazon Linux 2 v3.4.1 running PHP 8.1”) corresponds to the platform you wish to upgrade to.
  2. In the Elastic Beanstalk web configuration page, get the environment ID for the environment you wish to upgrade (eg. “e-jwfjvy57r3”).
  3. Run the aws command to upgrade the environment in place:
    aws elasticbeanstalk update-environment --solution-stack-name "64bit Amazon Linux 2 v3.4.1 running PHP 8.1" --environment-id "e-2iuwivbgzc" --region "ca-central-1"


Regular expressions: Find instances when the string does not equal a certain value

Another typical regex scenario: You’re looking through some data (like a JSON object) and are looking for when a value is actually being set. Let’s say our string contains:

"puttLength": null, 

Typically, you’d write a regular expression to capture the <em> tag by writing this:</em>

"puttLength": ((?!null).)*$

The use of ?! is the instruction to make a negative lookahead match, ensuring null does not exist before the line can be returned as a match. A terrific example / tool to test in your browser exists at .

Measure current IOPS usage on a Linux server

This is most easily measured by installing the sysstat package:

sudo yum install sysstat -y

And running the sar command, looking at the value of tps:

sar -d 1

Getting a recursive list of files sorted by last modified date in Linux

Here’s a quick way to get a recursive list of files, sorted in descending order by the last modified date, from any folder in *nix:

find . -type f -printf "%T@ %p\0" | sort -zk1nr | xargs -0 printf "%s\n"

Alpha males and females are the most empathetic… and the most stressed

A few months ago I was struck by the mention of a study of chimpanzee society that found that the leader tended to demonstrate deep caring and empathy for members of their pack; empathy ultimately being a necessary aspect of their personality that benefited their ability to rise and maintain a leadership position. Below, Leo Widrich has a terrific summary of the phenomenon:

Leo Widrich – The surprising science of alpha males & females: The most empathetic member of the group

One of the things that completely baffled me, but upon closer inspection, makes a lot of sense, was his finding that any alpha in a group of chimpanzees always happens to be the most empathetic member. He analyzed this by studying empathic behavior like consoling, hugging and other indicating moves. Although generally females in any group tend to offer more empathetic behavior to the members of the group, when it comes to the alpha, they show a level of empathy that is way off the charts compared to the rest.

A second insight that I took from de Waal’s research, was that the stress level of the highest-ranking members of a group, as he studied it in chimpanzees and bonobos were also the most stressed members of the group.

Permutations and combinations: What they are, and the formula to determine them


A selection of objects in which the order of the objects matters.

nPk = n! / (n - k)!

Example: If we wanted to get the number of permutations in which 6 people could be seated into 4 chairs, we’d find that it would be 360 permutations in total:

6P4 = 6! / (6 - 4)! = 720 / 2 = 360


The number of possible combination of r objects from a set on n objects.

nCk = n! / ( k! * (n - k)! )

Example: Let’s say instead we want to get the number of combinations in which 6 people could be seated into 4 chairs; we’d find that it would be 15 combinations in total:

6C4 = 6! / ( 4! * (6 - 4)! ) = 720 / ( 24 * 2 ) = 720 / 48 = 15


How to hold effective, creative meetings

As a people manager, I’ve always been aware of the tendency of subordinates to want to agree with you – or at least to avoid having to voice a conflicting opinion.  At my most clear-headed, I’m careful to keep my opinions to myself until later in a discussion. Below are some excellent suggestions for getting a good, creative discussion going before you start to narrow your options. – Your Meetings Are Killing Employees’ Best Ideas. It Isn’t Your Fault. Here’s How to Fix Them

So what happens when a group gets together to discuss an important issue? Members show their affinity to the group by restating and confirming what other group members, and especially group leaders, have already said. Even those with important and pertinent information to share tend to forget that information or dismiss it as not really relevant in their eagerness to show their solidarity with the group and its views. They also set aside their own insights and focus on how to assist in the group’s chosen course of action. This is such a profound human instinct that most of us do it without realizing it.

All of this is great for having harmonious meetings that seem highly efficient, but it’s not so great for finding innovative solutions to problems or recognizing new threats or opportunities. Fortunately, although you can’t eliminate shared information bias, there are things you can do to lessen its effects and increase the chances that employees will share more of the good ideas and relevant information they have. For your next team meeting, follow these simple rules:

Have people bring notes.

Make sure each team member arrives at the meeting with a list of a few important points he or she plans to share. That way, if shared information bias causes them to forget or dismiss whatever they planned to say, they can refer to their notes and be reminded that they consider these points important.

Specifically ask for dissenting opinions.

As a group consensus emerges, pause the proceedings and say something like this: “It sounds like a lot of us agree. But right now, I would like to hear from anyone who has a different view.” If team members have other viewpoints but have hesitated to voice them, this invitation may bring those other viewpoints forward.

Go around the table.

You can follow up your request for dissenting opinions by going around the room and asking each team member to say what he or she thinks. I learned the power of this approach years ago when I taught a class and made it a practice to ask each class participant in turn to speak. One man who was somewhat shy and would never have volunteered to say anything consistently offered some of the most insightful comments of the whole group. If you’re not hearing from every person at a team meeting, you are likely missing valuable information.

If you’re the leader, speak last.

The leader or leaders of the team should make sure to gather everyone else’s input before offering their own. In most groups, members are highly attuned to leaders’ opinions and are especially eager to go along with them. If you speak up too early–even making it clear that yours is just one view and you want to hear others–team members will tend to look for ways to agree with what you’ve said rather than take the conversation in a different direction with insights or opinions of their own. By keeping your thoughts to yourself at least through the early part of the meeting, you’ll give them a chance to shine. And you’ll gain the benefit of hearing their best ideas.

When is a good time to re-brand?

Saw an interesting post in my e-mail today (care of the generally excellent CB Kickstart newsletter): When indeed is a good time to execute a rebrand for your organization? What should the purpose of a rebrand be? What should you look out for to make sure you’re not executing one for the wrong reasons? It all depends on your organization’s particular situation, but the Johnson Banks piece below is a nice little writeup on the topic.

Johnson Banks – Why brands change

When is a good time to re-brand?

One of the most powerful and legitimate reasons to change is a fundamental change in business circumstances – a merger, or a takeover, for example. Recently two London based property companies, Development Securities and Cathedral Group merged, and rather than subsume one into the other they created a new brand, U+I (United and Industrious). When Singapore airlines sold their majority stake in Virgin Atlantic, there was a point at which the Delta board would have looked at the Virgin brand and had to decide – do we keep it, or do we ‘fold’ it into our brand? Thus far, they have established clear links between the brands without formally merging them.

Sometimes an organisation’s core market changes. This might mean that a brand that was created to ‘fit’ with one product or market no longer works. So Shelter’s previous symbol used a piece of typewritten, ‘angry’ type, which matched their original mission to concentrate on the homeless. But a gradual switch in focus to bad housing meant that needed to be reflected in their rebrand.

When is a bad time to rebrand?

When the original commissioning team moves on, branding’s biggest biggest problems arrive. The first issue is boredom. After about three years, an internal team, their agencies, their advisors – everyone – has had enough, and people start to tinker. Yet, paradoxically, about two-to-three years in is precisely when a new brand has just started to seep into the public consciousness, and arguably that’s exactly when a brand should become more consistent, not less.

The next big problem is ‘not invented here’ syndrome. New teams, often new directors arrive, and the human desire to ‘make a mark’ kicks in. Someone lets the internal team tinker, and slowly things unravel. Every new business manager for every major branding company in the world keeps an eye out for changes at the top of major organisations – because this is when existing branding schemes are at their most vulnerable, new brooms are brought in, and the sweeping starts.

With some recent rebrands there’s also a sense of if in doubt blame the brand. At launch in 2007, the previous Southbank design scheme seemed like a powerful and flexible idea that could flex and modulate across the institution’s communications, but within five years had been relegated to just the ‘logo at the bottom of the poster’.