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: https://blog.jetbrains.com/phpstorm/2017/03/phpstorm-2017-1-is-now-released/

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: https://mothereff.in/js-variables . 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!

A little fun with gource

Every year my employer has a holiday party. This past year I rendered out all the projects we had worked on and put them in a loop on the big screen. The video renderer we used is called gource. Here is the gourcing of the current project.

 

Edit: So youtube is being…well Youtube and keeps deleting the video. Guess I’ll try again later :S. Still have it here so maybe twitch or something else.

 

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 <me@davidjeddy.com>>
 * @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 http://stackoverflow.com/questions/4278106/how-to-check-if-a-string-is-base64-valid-in-php
    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?

`Cert Mode`

So I heard an interesting phrase from a networking engineering buddy of mine: ‘Cert Mode’. You can typically tell when someone is in ‘Cert Mode’ when you do not see them for a month or two then suddenly call you up out of the blue super excited about the cert they just got and want to celebrate.

While I do not agree that one has to go off the radar for months at a time to be in Cert Mode I can personally get behind the mentality of wanting to better oneself, to reach for more, and absorb knowledge in the pursuit of being more useful, knowledgeable, and generally sharp minded.

To everyone out there striving for more I salute you and wish you the best.

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.

AWS Lambda, S3, and VPC

Found this awesome bit of information floating around the internet: https://aws.amazon.com/blogs/aws/new-access-resources-in-a-vpc-from-your-lambda-functions/

When removing an orphans is bad…

So Docker creates containers, when you stop these containers the container still exists it is simply stopped.

And then we create more containers…and more containers…and more containers…until we look at docker ps -a and see dozens. As such I recently began using the --remove-orphan flag of docker-compose. 

As the project progressed it got to the point where we were ready to integration out micro-services. So I started up the API server, then the user frontend…and the server exited with a code 137. Hua? Checked ports: ok, checked logs: nothing, check Google / GitHub / Stack Overflow; not much stated explaining why one service would cause another to exit with a SIGTERM command.

Come to find out when you start a stack based on a docker-compose.yml docker uses the directory name as the project name. Since we try not to clutter the root of projects both/all projects have a structure of ./{app root}/docker/{service name}. Soooo --remove-orphan was removing the services not attached to the YML file of the application. Essentially termination everything not itself.

Well, I thought, we can name containers we should be able to name the project right? Nope. As of 1.13, networks, containers, and swarm can be name (iirc) in the docker-compose.yml configuration. But to name a  projects it can only be done on the CLI during container run.

:S there went 3 hours of my life under the assumption of consistency from a tool.

TL;DR: Never assume your toolset operates consistently, always verify.