Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / go.mod
Last active Feb 25, 2021
Simple GoLang App to demonstrate Mountebank's inability to support HTTP CONNECT method.
View go.mod
module proxy-client
go 1.15
require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93
)
@mikeschinkel
mikeschinkel / 1.attributes-with-use.php
Last active Aug 18, 2020
Hypothetical example of using use statement for attributes
View 1.attributes-with-use.php
<?php
namespace MyNamespace;
// namespace use
use WpAttributes\PrimaryKey;
use WpAttributes\PostType;
use WpAttributes\TemplateVariable;
use PHP\VirtualReadonly;
@mikeschinkel
mikeschinkel / 0.readme.md
Last active May 17, 2020
Refactoring Pantheon_Sessions::initialize_session_override() using do{...}while(false);
View 0.readme.md

Example use of do {...} while(false)

See this gist for background.

This example comes from my work here when looking for a solution for this issue related to this WordPress plugin.

I recognized I could make it clearer using the do {...} while(false) pattern so I wanted to document here.

Note:

@mikeschinkel
mikeschinkel / Apis.php
Last active May 14, 2020
PHP Examples that could benefit from Try...Break (method excerpts from real production code)
View Apis.php
<?php
class Apis {
static function JsonGET( string $api_url, array $args = array() ) {
do {
$wp_error = null;
$args = wp_parse_args( $args, array(
'response_type' => ARRAY_A,
) );
@mikeschinkel
mikeschinkel / form1.php
Last active May 6, 2020
Examples showing a huge array literal vs. many small array literals
View form1.php
<?php
class MembershipForm {
static function form() {
return array(
array(
'type' => 'textfield',
'heading' => __( 'License Type ID' ),
'param_name' => 'license_type',
'description' => esc_attr__( 'Enter License Type ID', 'wds-vc-elements' ),
@mikeschinkel
mikeschinkel / module.audio.mp3.php
Created Mar 16, 2020
module.audio.mp3.php from WordPress where decodeMPEGaudioHeader() is partially refactored from over 600 lines to ~200 lines.
View module.audio.mp3.php
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at https://github.com/JamesHeinrich/getID3 //
// or https://www.getid3.org //
// or http://getid3.sourceforge.net //
// see readme.txt for more details //
/////////////////////////////////////////////////////////////////
// //
@mikeschinkel
mikeschinkel / ArraySorter.php
Last active Mar 8, 2020
A hypothetical approach for creating an object-based approach to sorting arrays in PHP
View ArraySorter.php
<?php
/**
* One option is to create `PHP` as a reserved namespace for extensions
* that do not have to be backward compatible from the initial creation
* backwards, except of course for those who may have previously created
* their own PHP namespace.
*
* I've tried to implement warnings and errors, but they are not exhaustive
* and some more could be added if this had a real chance to make it into
* PHP core.
@mikeschinkel
mikeschinkel / meta.php
Created Feb 13, 2020
A hypothetical ::meta for PHP symbols and variables that would provided a streamlined reflect
View meta.php
<?php
namespace Acme;
class Foo {
private const XYZ = 123;
public $bar = 'hello';
function baz():int { return 0; }
}
echo Foo::meta->type->name; // object
@mikeschinkel
mikeschinkel / import.sh
Last active Jan 22, 2020
Import script for Pantheon DB from mysite1.live to mysite2.live (does this work?)
View import.sh
#!/usr/bin/env bash
db_file="$(terminus backup:list mysite1.live | grep -m1 database.sql.gz | awk '{print $1}')"
db_url="$(terminus backup:get mckissock.live --element=db --file="${db_file}")"
terminus import:db --yes mysite2.live "${db_url}"
@mikeschinkel
mikeschinkel / !PhpProjection.md
Last active Jan 13, 2020
Brainstorming on a concept for PHP I am calling "Projection" here.
View !PhpProjection.md

Brainstorming on a concept for PHP I am calling "Projection" here. This could be a new API for PHP or just extensions to Reflection.

The examples below are far from complete and I am sure there are missing aspects in some of these interfaces as this is just an exploration of concept and not something fully tested.

Note that I used leading underscores on file names to order which files are displayed by Gist above the other files, except for _Class, _Interface and _Trait which have leading underscores to