Skip to content

Instantly share code, notes, and snippets.

Mike Schinkel mikeschinkel

Block or report user

Report or block mikeschinkel

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
@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.
View instrument-hooks.php
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if (isset($_GET['instrument']) && $_GET['instrument']=='hooks') {
@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 / !PhpPreloading.md
Last active Jan 13, 2020
Simple config class in PHP illustrating how a `preload` might work. In this example, the load() method uses the `preload` modifier on Line 38 of config.php
View !PhpPreloading.md

Since Config::load() is declared with preload (which should imply static) it would be run once and its return value would be converted to OpCode so when the following line of code runs during normal execution — such as on the web for each page load — it would execute extremely fast and would not open nor decode the config.json file, since that would have been done a OpCode generation time.

@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

@mikeschinkel
mikeschinkel / find-in-set.php
Last active Dec 27, 2019
Adds FIND_IN_SET support as a comparison operator for WordPress meta_query. Include this in a plugin, in the theme's functions.php file, or as a separate file that is loaded using require() or include() before your call to WP_Query. As @Otto42 points out, you might not want to use this in a plugin that you plan to distribute given the WordPress'…
View find-in-set.php
<?php
/**
* Class Add_Find_In_Set_Compare_To_Meta_Query
*/
class Add_Find_In_Set_Compare_To_Meta_Query {
/**
*
*/
function __construct() {
View solution.sql
SELECT name
FROM sqlite_master
where type = 'table'
# crime_scene_report
# drivers_license
# person
# facebook_event_checkin
# interview
# get_fit_now_member
@mikeschinkel
mikeschinkel / _readme.md
Last active Nov 19, 2019
Examples for how a __toArray() magic method could be useful in PHP.
View _readme.md

Examples for how a __toArray() magic method could be useful in PHP.

In a nutshell, __toArray() would not be as useful when you have full control over the entire codebase.

But where __toArray() would be extremely useful is in interfacing with existing code that expects arrays and wants those arrays to be a specific format. Using classes and type-hinted methods allow to encapsulate the intelligence into the class, and using __toArray() makes for a nature use-case.

You can’t perform that action at this time.