Skip to content

Instantly share code, notes, and snippets.

View ralphschindler's full-sized avatar

Ralph Schindler ralphschindler

View GitHub Profile
@ralphschindler
ralphschindler / README.md
Last active May 1, 2024 19:14
Docker For Mac Host Address Alias To Enable PHP XDebug (10.254.254.254 Trick)

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 February 10, 2015 23:13
What happened when this was suggested many years ago?
<?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 December 26, 2014 14:38
CLI Colorization via HTML style tagging function. This solution is UNLICENSED, feel free to do whatever you want with it.
<?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 November 26, 2014 16:23
A Barebones OAuth2 PHP Client demonstrating the "Password Grant Type"
<?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 February 15, 2016 19:28
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>
<?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 September 19, 2014 14:59
Apply user functions to both keys and values while recursively walking an associative array
<?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)) {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ralphschindler
ralphschindler / workflow.md
Last active February 22, 2016 07:07
Breaking directories out of a repository into their own repository
git clone ./zf2 ZendServiceAmazon-library;
git clone ./zf2 ZendServiceAmazon-tests;
git init ZendServiceAmazon;
cd ZendServiceAmazon-library;
git filter-branch --subdirectory-filter library/Zend/Service/Amazon -- --all;
git filter-branch --index-filter 'git ls-files -s | sed "s--library/ZendService/Amazon/-g" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
cd ../;
<?php
copy(__DIR__ . '/music.db.original', __DIR__ . '/music.db');
include 'vendor/autoload.php';
return new Zend\Db\Adapter\Adapter(array(
// Sqlite Configuration
'driver' => 'Pdo',
'dsn' => 'sqlite:' . __DIR__ . '/music.db',
@ralphschindler
ralphschindler / node_mate.rb
Created October 6, 2013 01:31
Running unsaved JavaScript though Node.js with TextMate 2 Notes: It's basically 2 files, one created with the bundle editor (See the tmCommand), and the actual node runner. This also requires an environment variable to be setup pointing to the node command line utility: TM_NODE=/usr/local/bin/node for node installed via homebrew
require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
class NodeScript < UserScript
def lang; "JavaScript" end
def default_extension; ".js" end
def args
[]
end
def executable; @hashbang || ENV['TM_NODE'] || 'node' end
def version_string