All Posts & Books

Working with Remote and Overseas Teams

This particular project was a growing and learning experience in many ways. During this project, I worked remotely with an overseas team. While working with a remote team can be an enjoyable experience, it does present a few challenges. Those challenges are compounded when the remote team is also overseas. This project was no exception. There were many things that we could have done better. However, there were many things that we did well.

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.

Rome Wasn't Built in a Day

Many of us have been on a project where everything starts out great and the client remains happy for a few months until suddenly they change their mind and are no longer happy. This project was certainly the case. However, there was quite a bit that we did right on the project. The code was clean and well architected. We used a transformation layer in the code to allow the API payloads to be detached from the database.

Computing Eloquent Model Deltas

Computing the differences or deltas between Eloquent models is a common task in many data oriented apps. The easiest way that I have found out how to do so is below: // This is assumed to be in \App\YourModel /** * @param \App\YourModel $model * * @return array */ public function delta(\App\YourModel $model) { // array_diff() is an easy way to produce deltas $baseline = $model->attributesToArray(); $possiblyChanged = $this->attributesToArray(); /* * $baseline = ['test' => 500, 'not_changed' => 5] * $possiblyChanged = ['test' => 700, 'not_changed' => 5] */ /* * $delta == ['test' => 700] */ $delta = array_diff($possiblyChanged, $baseline); // Here I unset possible changes that I don't care about unset($delta['id']); unset($delta['created_at']); unset($delta['updated_at']); return $delta; }

Eloquent Model JSON Serialization and Deserialization

Awhile back I needed to save an Eloquent model to the DB so that I might compute a delta later on. Json serves this purpose nicely since the json data type is now natively supported in many languages. One could do this manually but, fortunately, Laravel makes this easy on us. We can utilize model mutators to dynamically convert the input and output of a specific database column. For example, say we want to save a passed in model as json and that the column that we want to save to is called json:

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. For instance, if we declare a variable outside of any function or without specifying var before instantiating a variable (aka implicit declaration) for the first time, that variable is global.

How To Get 35 Records FROM 1 — Or Why You Must Declare Your JOIN Type

The FROM clause in MySql is completed first and it provides the table from which other operations will be run. Even with that essential description, some constructions of the FROM can be difficult to understand and provide you with wildly unexpected results. Those unexpected results come from the fact that the tables in the FROM clause are combined into one table for querying whether you specify the type of JOIN or not.

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. In PostgresSql, you can do something like so: SELECT * FROM generate_series(1, 6) number That will generate a table of numbers from 1 to 6. Seems like basic functionality right? Not in glorious MySql. You have several options but they are either hacky or require a fair amount of work.

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. Rules The standard rules for Fizz Buzz are: Write a program that prints the numbers from 1 to 100.

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.