Refactoring array index magic number with class constant.

During a code review my peer Michal Mazur turned me onto the follow example; I have to say I am really digging it: Array Index as constant .

In my specific case here is the usage:

if (!empty($paramData[19]) && is_string($paramData[19])) {
    $paramData = $paramData[19];
} elseif (empty($paramData[19]) && !empty(isset($paramData[17])) && isset($paramData[17])) {
    $paramData = $paramData[17];

…and the refactored logic:

if (!empty($rowData[$this::FULL_SOURCE]) && is_string($rowData[$this::FULL_SOURCE])) {
    $imageSource = $rowData[$this::FULL_SOURCE];
} elseif (empty($rowData[$this::FULL_SOURCE]) && !empty(isset($rowData[$this::SQUARE_SOURCE])) &&
) {
    $imageSource = $rowData[$this::SQUARE_SOURCE];

While a bit more verbose the logic is much easier to read using the contextually named constants.

PHP and large CSV’s…

After looking around a bit I have yet to find a way to read a specified line from a file without doing one of the following:

  1. fopen()
  2. looping every line until reaching the desired line

Desired functionality:

  1. fopen($file)
  2. imaginary function call `fgetcsvline($lineNumber)` would returns the contents of line $lineNumber


Anyone know a solution for this?


Update: Derp, how could I forget about ‘The League’?

PHPStorm 2017.1 released…

I’m sure many of you know this already by JetBrains has released PHPStorm version 2017.1. The improvement list looks nise and Im eager to try ’em out.
Get he full details over at the office release page:

Of special interest is the Codecetpion and PHPUnit 6 as I am a big personal supporter of automated testing process.

Quick little thing.

Was sad to see Yii2’s getOldAttributes() did not have to ability to limit based on a provided array; whereas getAttributes() does take an array to limit the returned attributes. So I whipped this up right quick:

 * @param array $array
 * @return array
public function getOldAttributes($array = [])
    $returnData = parent::getOldAttributes();

    if (!empty($array)) {
        $returnData = array_intersect($array, $returnData);

    return $returnData;

Simple little thing but super handy.

emoji as variable names…

…during a short discussion today with a peer we found this little tool: . I was all like AHA! I have an idea! Sadly though it turns out `(╯°□°)╯︵ ┻━┻` is not of the Unicode 8 character set.
:sad-face:. Then we got on the it would cool conversation of having emoji as variable names.

Imagine opening PHPStorm, etc and see in birthday cake var names! So I mocked something up real quick to pass around the office, enjoy!

PHP str_word_count’s and validating base64 strings…

Recently I had to validate a string that is was indeed a base64 string and it was indeed an encoded allowable image type. Between str_word_count’s second parameter (returning the string as an array based on the words) and a quick Stack Overflow search this is neat little piece of logic IMO:

 * Validate a base64 string is indeed of an allowable MIME type
 * @author David J Eddy <>>
 * @version 0.8.0
 * @param $paramData
 * @return bool
public function validate($paramData)
    $returnData = true;
    // explode the string into an array ignoring everything but words
    $wordArray = str_word_count(substr($paramData, 0 , 23), 1);

    // is the string a valid base64 object?
    // @source
    if (base64_encode(base64_decode($paramData, true)) !== $paramData) {
        $returnData = false;

    // does the string contain 'data', 'image', 'base'?
    if (
        in_array('data', $wordArray) === false ||
        in_array('image', $wordArray) === false ||
        in_array('base', $wordArray) === false ||
        $returnData === false
    ) {
        $returnData = false;

    // does the string contain an allowed MIME type?
    if (in_array('data', $this->allowableMimeType) === false || $returnData === false) {
        $returnData = false;

    return $returnData;

What do you think? Have an often forgotten php function or parameter that helps you greatly?

Local user groups: get out more than you put in.

Here in the Tampa bay area we have user groups. Some are small, some are large, some are new, some are long running. But no matter what size, or type, or subject matter; you will almost always get more out of a group than you put in. While this topic could, should, and likely will be discussed at length later the Tl;DR is: more heads the better.

Knowledge:  No one person knows everything, but everyone knows something they can share.

Connections: Looking for a new position? Want to meet people who do what you do ’cause all your friends are network engineers? Goto a group meet.

Openness: Everyone is at the group to be there, no one is (typically_ forces to attend. Thus you see the people that WANT to participate in the community at large.


IMO, for the money, local groups are an absolute win.

The pain with AWS Lambda…

…I realize I am a bit new the AWS platform and some things are just impossible, but here is the desired work flow:

  • POST/PUT image to S3
  • Run node.js app in a container that emulates an EC2 machine (thus a Lambda environment)
  • See logs of service as if it was running in a Lambda ENV.

In reality my current workflow is:

  • Update logic
  • Run package script to build nodeJs app, uploads to Lambda
  • POST/PUT data on S3
  • Goto CloudWatch and press refresh until the logs populate with related request ID

Anyone know how to make this more effective? Average turn around is 3 to 5 minutes per change :S.

How I got linux SSH to work on windows 10…

So one of the biggest issues I personally have had with windows is the in-ability to emulate a decent Linux terminal. Sure I could dual boot, run a VM or any Os virtualization. But for me, it all seemed very…detached. Well, herein is a solution I have found to be very congruent to my goal:

Step 1 Follow the directions

Provided by to get bash on Windows 10 (they have images as well).

However if you like me and just want the TL;DR:

  • Settings -> Update & Security -> Enable Developer Mode, Click Yes
  • Control Panel -> Program Features -> Turn Windows Feature ON -> Enable ‘Windows Subsystem for Linux’
  • Restart

After restart completes:

  • open a CMD prompt
  • run the command bash
  • provide a username for the linux system -> press enter
  • You should now be back on the CMD promtp -> close window
  • Open a new cmd -> type bash

Gaze in amazement as you now have linux terminal running on windows without the use of a VM.

Now that we are 1/2 way to our goal of SSHing into a remote linux machine, lets move onto the magic part!

Step 2: The fancy footwork

These instruction will not cover how to make a SSH keypair (that is covered at length elsewhere). For this example I had to log into an AWS EC2 instance.  Ensure an instance is running, we have access to the public IP, and a copy of the *.pem key saves on the windows machine somewhere.


  • Copy the AWS *.pem file from windows into ~/.ssh:  cp /mnt/c/me/Documents/pem/example.pem ~/.ssh/example.pem
  • chmod 0600 ~/.ssh/example.pem
  • ls -la`-r-x------ 1 root root 1692 Feb  8 21:09 example.pem to ensure the permission did infact change
  • ec2-user@ -i ~/.ssh/example.pem

If all went well you should be greeted with a welcome message from the remote machine.


Overall not that complicated once the steps are sorted out, but ugg, sorting out all the step on two different platforms. Remindes me of the time we go *AMP running on WindowsXP alongside IIS/.NET/SQL back in my college days. #donotwant

On productive days and how to have one.

Try working at an airport terminal …

Over the course of the better part of the last decade I have worked in start ups, corporate office parks, small but good profit businesses, even a non-profit helping the needy. With each environment come different obstacles

to getting ‘in the zone’. Be it the noise level, the constant interruption the crapped work area, the rhythmic but distract noise of commercial airliners taking off and landing.

Of all the reasons to have for not ‘getting in the zone’ I have found the best thing you can do get a quite area, no distracts, and envelope yourself in the task at hand. If that means wearing ear plugs, so be it. If that means leaving the office floor and working in the quite lobby, by all means. And if so lucky, working from home on the couch (no TV!).

Do what needs to be done to have an environment conducive to being effective.