The Stack Structure

What is the Stack data structure? Why and when to use it? What is a stack data structure? A data structure is a way to model code. An the functionality needed from this certain piece of code is to push and pop “things” from a stack. I need this stack to be locked down so that i can only grab the item at the top, and to add pushed items onto the bottom.
Read more

Weighted Returns With PHP

Getting Started I was researching into the idea of randomly selecting array elements based on varying weights, i was looking for something like; <?php $arr = ['RED' => 50, 'BLUE' => 25, 'GREEN' => 25]; return_me_a_true_random($arr); From this I would expect red to be returned around 50% of the time, blue around a quarter, and green around a quarter also. I came across this on stack overflow and wanted to test how true the outcome is.
Read more

Binary Search Algorithm

Binary search in a method of searching an array using the divide and conquer technique. It only works on an array that was been sorted ascendingly and works by splitting the array into two down the middle, calculating whether the middle value of the array is greater or less then the key, it then picks the correct side of the split and the process is done again until the middle value equals the searched for value.
Read more

Cannot Download, $GOPATH not set

What is wrong here? This error occurs when you have not set your go home location, because you are downloading an external package go will need to save the file somewhere and you need to tell it where you are working. On the commandline; echo $GOPATH To confirm that that is in fact the problem. If it isn’t I can’t help you :( Then on the command line type;
Read more

Fixing 504 Request Timeout Errors on Nginx

I came across this problem the other day and thought I would write down my findings. In short a 504 request means that the script has taken too long to execute and the server or browser has given up waiting for it. There are two possible reasons why this could occur; PHP is tired of waiting for you! The script is taking longer to execute than what is allowed in the PHP max_execution_time and max_input_time variables.
Read more

Javascript Chaining Methods

What is chaining? Below is an example of chaining methods, in terms of javascript this may look familiar to jQuery var myTemplateString = myTemplate.addH1('Every page should have a h1 tag.').addH2('a h2 tag is also important').addP('and finally a p tag….').render(); The example above is of a template builder, what this is doing is building up a html string and rendering it. The advantages of chaining is that you can write all your logic in one expression, instead of creating a lot of variables to save the steps of the process.
Read more

Liskov Substitution Principle - SOLID

A Brief Explanation The Leskov Principle states that all the methods from classes than inherit from the same Interface must return the same type. Put another way if i have an interface that states that all classes that implement this interface must have a method called get(). For each one of these get() methods the same type must be returned. If it is an array for one, it must be an array for all.
Read more

My Must Have Chrome Extensions

Chrome is my browser of choice, its development tools are far ahead of any other browser that i have come across, (I am willing to have my mind changed). The stack that I work with most in Vue, Laravel, Nginx, and these are my most used ad beloved chrome plugins. As a sidenote; Plugins are good and greatly increase browser functionality and can save you a shed load of time.
Read more

PHP Call Magic Method

What is does? If defined this method is will be ran if a method that does not exist is called. Why would you use it? You would use it to gracefully catch calling an undefined function call, Laravel uses this very well with its getting and setting on attributes and relationships. To see more about this please read here. Example class User { public function __call($method, $args) { echo "unknown method " .
Read more

PHP Construct Magic Method

What does it do? The most common of the magic functions, this one is called whenever a class is created, Why would you use it? When you are setting up a class and need to do something as soon as the object is created. For example create a user class and set some properties on that user. class User { protected $firstName; protected $lastName; public function __construct($firstName, $lastName){ $this->firstName = $firstName; $this->lastName = $lastName; } } $user = new User('John', 'Mackenzie'); These properties will now be set and accessible.
Read more