Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
hopeseekr / README.md
Created June 13, 2019 07:18
DTOs in Action: The ColorSpeaker Project

ColorSpeaker was inspired by the article Tests and types [mirror] that was posted to /r/PHP two days ago.

Its aim is to be an easy-to-use converter for different types of color models (RGB, CSS hex codes, HSV, HSL, etc.). It is also meant to be a real-world example of the power of Data Transfer Objects (DTOs). I specifically created this for one of my apprentices whom I taught DTOs to the night before I read the above article, and thought this would be a perfect project for showcasing DTOs.

I developed it in three distinct iterations:

  1. [v0.25 tag]: A virtually literal implementation of the article's one color DTO (RGBSpeaker and RGBColor). This is a great place to start learning about DTOs and is meant to be used in conjunction with the article that inspired it.
  2. **[[v0.50](https://github.c
@hopeseekr
hopeseekr / fractal-20190611.txt
Created June 12, 2019 14:57
A beautiful ASCIII fractal
x x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x A A A A A A A x x x x x x x x x x x x
x x x x x x x x x x x x A A A A A A A A A A A A A A x x x x x x x x x x x
x x x x x x x x x x x v v A A A A A A A A A v v x x x x x x x x x x x
x x x x x x x x x x x v A A A A A A A A A A A A v x x x x x x x x x x
x x x x x x x x x x A A A A A A A A A A A A A A A x x x x x x x x x x
x x x x x x x x x x v v v v v A A A A A A v v v v v x x x x x x x x x
x x x x x x x x x v v v v A A A A A A A A A v v v v x x x x x x x x x
x x x x x x x x x v v v A A A A A A A A A A A A v v v x x x x x x x x
x x x x x x x x v v v v v v A A A A A A A A A v v v v v v x x x x x x x x
@hopeseekr
hopeseekr / gem.txt
Created May 29, 2019 12:32
A Hidden Gem
xgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgxgx
gxgoyxgoyxgoyxgoyxgxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxyogxg
xgoyxgoyxgoyxgoyxgoycccycccycccycccycccycccycccycccyogxyogxyogxyogxyx
goyxgoyxgoyxgoyxgoycccysgcysgcysgcysgcysgcysgcysgcccgxyogxyogxyogxyog
xyxgoyxgoyxgoyxgoycgsycccysgsycccysgsycccysgsycccysgcyogxyogxyogxyogx
gxgoyxgoyxgoyxgoycccycccysgsysgcysgsysgcysgsysgcccgcccgxyogxyogxyogxg
xgoyxgoyxgoyxgoycgsysgsycccycccysgsysgsycccycccysgsysgcyogxyogxyogxyx
goyxgoyxgoyxgoycccysgsycccysgcysgsysgsysgcysgcccgsysgcccgxyogxyogxyog
xyxgoyxgoyxgoycgsycgsycgsycccysgsysgsysgsycccysgcysgcysgcyogxyogxyogx
gxgoyxgoyxgoycccycccycccycccysgsysgsysgsysgcccgcccgcccgcccgxyogxyogxg
<?php
function asdf()
{
function asd() { echo "Hi\n"; }
asd();
}
asdf();
asd();
@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
@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 / 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 / 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 / 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 / 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