Skip to content

Instantly share code, notes, and snippets.

Ralph Schindler ralphschindler

Block or report user

Report or block ralphschindler

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ralphschindler
ralphschindler / SnapshotCommand.php
Created Jul 11, 2019
An example Laravel app command to create and load database snapshots using S3
View SnapshotCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class SnapshotCommand extends Command
{
@ralphschindler
ralphschindler / AuthServiceProvider.php
Last active Apr 5, 2019
Laravel 5.8 Policy Guesser For Using "Models" Directory
View AuthServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
@ralphschindler
ralphschindler / StringIsLengthRule.php
Last active Nov 2, 2017
Custom Dynamic Validation Rules for Laravel 5.5+
View StringIsLengthRule.php
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class StringIsLengthRule implements Rule
{
protected $length;
protected $message = 'The string must be greater than the length';
@ralphschindler
ralphschindler / database-column-ordering.md
Last active Nov 2, 2017
Ralph's Database Column Organization
View database-column-ordering.md

Ralph's Database Column Organization

TLDR:

  1. primary key columns (e.g. id)
  2. foreign key columns (e.g. other_id)
  3. row qualifying columns (e.g. status)
  4. entity identification columns (e.g. name, title, slug, base_url)
  5. non-string-based entity attribute columns (e.g. rating, is_admin)
  6. string-based entity attribute columns (e.g. short_description, description, notes)
@ralphschindler
ralphschindler / README.md
Last active Nov 26, 2019
Docker For Mac Host Address Alias To Enable PHP XDebug (10.254.254.254 Trick)
View README.md

Docker (Mac) De-facto Standard Host Address Alias

This launchd script will ensure that your Docker environment on your Mac will have 10.254.254.254 as an alias on your loopback device (127.0.0.1). The command being run is ifconfig lo0 alias 10.254.254.254.

Once your machine has a well known IP address, your PHP container will then be able to connect to it, specifically XDebug can connect to it at the configured xdebug.remote_host.

Installation Of IP Alias (This survives reboot)

Copy/Paste the following in terminal with sudo (must be root as the target directory is owned by root)...

@ralphschindler
ralphschindler / scalar-type-signatures.php
Created Feb 10, 2015
What happened when this was suggested many years ago?
View scalar-type-signatures.php
<?php
// coercive types, as per PersonFactory author's specification
class ElePHPant {
public $name, $age, $cuteness, $evil;
public function __construct(~string $name, ~int $age, ~float $cuteness, ~bool $evil) {
$this->name = $name;
$this->age = $age;
$this->cuteness = $cuteness;
$this->evil = $evil;
@ralphschindler
ralphschindler / colorize.php
Created Dec 26, 2014
CLI Colorization via HTML style tagging function. This solution is UNLICENSED, feel free to do whatever you want with it.
View colorize.php
<?php
/** @license http://unlicense.org/UNLICENSE */
function colorize($string, $useAnsi = null)
{
if (is_null($useAnsi)) {
$useAnsi = function_exists('posix_isatty');
}
@ralphschindler
ralphschindler / SampleOAuth2Client.php
Created Nov 26, 2014
A Barebones OAuth2 PHP Client demonstrating the "Password Grant Type"
View SampleOAuth2Client.php
<?php
namespace SampleOauth2Client;
class Client
{
protected $configuration = [
'token_file' => null, // path to a file to store token information
'api_authorization_token' => null, // authorization to talk to token service
'api_token_url' => null, // url to post to
@ralphschindler
ralphschindler / entity-mapper-via-dynamic-proxy-object.php
Last active Feb 15, 2016
The "No-framework ORM tool for generating proxies capable of strategically mapping data into clean POPO entities without bleeding concerns or doesn't require a tool to write generated code to disk in under 100 lines of code" prototype. </runon-and-exhale>
View entity-mapper-via-dynamic-proxy-object.php
<?php
namespace EntityMapperFramework {
class EntityMapper {
public function __construct() {
stream_wrapper_register('dynamicproxygenerator', __NAMESPACE__ . '\DynamicProxyGeneratorStream');
}
public function createProxy($entity) {
$class = get_class($entity);
@ralphschindler
ralphschindler / array_walk_recursive_key.php
Created Sep 19, 2014
Apply user functions to both keys and values while recursively walking an associative array
View array_walk_recursive_key.php
<?php
function array_walk_recursive_key(array $array, callable $valueCallback, callable $keyCallback = null) {
foreach ($array as $n => &$v) {
$n2 = ($keyCallback) ? $keyCallback($n) : $n;
if ($n != $n2) {
$array[$n2] = &$array[$n];
unset($array[$n]);
}
if (is_array($v)) {
You can’t perform that action at this time.