Skip to content

Instantly share code, notes, and snippets.

View hopeseekr's full-sized avatar

Theodore R. Smith hopeseekr

View GitHub Profile
@hopeseekr
hopeseekr / interpolateQuery.php
Last active June 27, 2018 12:38
Interpolate PDO queries
<?php
function interpolateQuery($query, $params)
{
$keys = array();
$values = $params;
# build a regular expression for each parameter
foreach ($params as $key => $value) {
@hopeseekr
hopeseekr / UuidModel.php
Created April 16, 2018 18:47
A drop-dead simple UUID base model class for Laravel 5
<?php
namespace App\Models;
use Ramsey\Uuid\Uuid;
/**
* App\Models\UuidModel.
*
* @mixin \Eloquent
@hopeseekr
hopeseekr / strict_type_bug_hunter.md
Created May 9, 2018 14:34
Elusive Bug caught via declare(strict_type=true)

Here's a VERY HARD to find bug that declare(strict_types=1) found:

The Problem: Some note attachments were getting lost in the system. We could see them on GCS, but the API was returning 404s. We couldn't figure out why this was the case for a couple of weeks and the problem was only sporadically reported (not part of the main workflow).

As soon as I turned on strict typing, the problem manifested itself:

class NoteAttachmentHelper
@hopeseekr
hopeseekr / adv_sql-mat_view_regex.md
Last active May 23, 2018 22:30
Advanced SQL: Materialized View with Many-To-Many Squashing and Regexp

So say you have a table with a many-many relationship to another, and you want to create a caching table (aka a materialized view):

CREATE TABLE orders_cache (
customer_id int primary_key, 
payment_type varchar(10000),
INDEX(payment_type(255))
) CHARSET=utf8;

@hopeseekr
hopeseekr / 911s_a_lie.md
Created June 27, 2018 13:40
9/11's a Lie! Lyrics

Lyrics to Deek Jackson's "9/11's a Lie!"

If you think 9/11 was an inside job
You're probably right, but who gives a fuck?
The world moved on and the truth don't count.
If you don't believe me, Take a look about:
At the tyranny in China, for a billion souls;
Economic crisis, adding to our woes!
The economic lies are there to fool the masses,

While they bend us over, and fuck us in our asses!

@hopeseekr
hopeseekr / strategy_pattern_tutorial.php
Created March 13, 2019 21:42
Strategy Pattern Educational Code
<?php
interface RESTAuthDriver
{
public function setApiClient(RESTSpeaker $apiClient);
public function generateGuzzleAuthOptions(): array;
}
interface Foo2
{
@hopeseekr
hopeseekr / README.md
Created March 14, 2019 17:13
Real-World Continuous Integration

Real-World Continuous Integration

What is Continuous Integration (CI)?

Continuous Integration (CI) is the process of automating the build and testing of code every time a team member commits changes to version control. 

Here are the basic parts of a modern CI system:

  1. Automated Tests:
@hopeseekr
hopeseekr / howto_git_submodules.sh
Created March 19, 2019 17:04
HOWTO Split Huge Subdirectories into Git Submodules
# First, split the huge directory into its own standalone branch.
git subtree split -P v1/fpdf/assets/img -b api_fpdf_asset_images
# Second, push the huge directory into its own repository.
pushd ..
mkdir api_fpdf_asset_images
pushd api_fpdf_asset_images
git init
git pull ../api.filtered api_fpdf_asset_images
<?php
function asdf()
{
function asd() { echo "Hi\n"; }
asd();
}
asdf();
asd();
@hopeseekr
hopeseekr / gem.txt
Created May 29, 2019 12:32
A Hidden Gem
xgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgx
gxgoyxgoyxgoyxgoyxgxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxg
xgoyxgoyxgoyxgoyxgoycccycccycccycccycccycccycccycccyogxyogxyogxyogxyx
goyxgoyxgoyxgoyxgoycccysgcysgcysgcysgcysgcysgcysgcccgxyogxyogxyogxyog
xyxgoyxgoyxgoyxgoycgsycccysgsycccysgsycccysgsycccysgcyogxyogxyogxyogx
gxgoyxgoyxgoyxgoycccycccysgsysgcysgsysgcysgsysgcccgcccgxyogxyogxyogxg
xgoyxgoyxgoyxgoycgsysgsycccycccysgsysgsycccycccysgsysgcyogxyogxyogxyx
goyxgoyxgoyxgoycccysgsycccysgcysgsysgsysgcysgcccgsysgcccgxyogxyogxyog
xyxgoyxgoyxgoycgsycgsycgsycccysgsysgsysgsycccysgcysgcysgcyogxyogxyogx
gxgoyxgoyxgoycccycccycccycccysgsysgsysgsysgcccgcccgcccgcccgxyogxyogxg