Plaintext Is Not So Plain

One of the bane’s of my current existence is having to deal with text encodings. I have a good friend that uses a few antique Windows programs that puke out Windows-1252 encoded characters as though it were going out of style. Much to my suprise when I opened up a csv file, made a few changes, and saved it, I ended up with a bunch of unicode replacement characters: “�” or otherwise known as \U+FFFD.

Read More

What is the Meaning of `this` — Javascript Function Invocation and `this`

Anyone who has worked extensively with a strong OO language before writing their first line of Javascript is going to find out very quickly that they are not in Kansas anymore. For starters, without using some of ES2015’s goodness (ES6 previously) Javascript does not have block scope—it has function scope. Before the days of let, this means that variables cascade down the function chain.

Read More

MySql Integer Sequence Generation

Generating integer sequences (e.g. all numbers between 20 and 100) in MySql is much harder than it needs to be. Other DBMS products have had such support for quite awhile.

Read More

Fizz Buzz in MySql Using a Stored Procedure and a Temporary Table

As a fun mental exercise I whipped this up. Is this really useful? Probably not. It is really a “code kata” if nothing else. I wouldn’t recommend using stored procedures in most situations since it is generally considered good practice to keep your logic in your code and not in the database layer.

Read More

Laravel seeding using a yield generator

I was needing to improve the performance of a pivot table seeder recently and decided to use a generator to do it. Interestingly, one of the easiest to implement iterators is the yield syntax introduced in PHP 5.5. It allows for good abstraction between the data that is to be iterated and the source of said data. That can lead to significant performance increases as well since it might, depending on the use case, reduce database calls or the amount of data being stored in memory among other things.

Basically what the yield syntax does is it returns an instance of the Generator class for that sequence in the loop.
When next() is called on the Generator class (which yield is) PHP then resumes with the state from when the yield statement was called. It continues on until there is nothing left to yield.

could be:

Read More

Up and Running with PHP 7 — Installation for Testing

With the release of PHP 7 just around the corner, a quick start guide seems to be in order. This guide was written with Linux in mind but it should work ok with Mac OS X. If you are on Windows, you should switch to Linux (or maybe Mac) :). Let’s get a testing environment set up.

Read More

SOLID PHP: The Single Responsibility Principle

The first of the SOLID principles is unfortunately violated quite often even though it is easy to understand why you want to maintain a separation of concerns. It is similar to the SQL injection vulnerabilities that show up on StackOverflow and other places even though the internet is flooded with warnings about how to avoid being pwnd by the easily escapable beast.

Read More

Lenovo T440s Linux Trackpad Settings

I would give the Lenovo T440s a 5 out of 5 if it were not for the trackpad. The rest of the computer is rock solid and really a great setup. The keyboard is my favorite because of the feel of the keys, the sound the keys make, and the keys’ apparent ruggedness. With the tweaks below, it makes the trackpad bearable though it still could use improvement.

Read More