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 / _about.md
Last active Jan 9, 2019
PHP module for use in WordPress to display Bibblio v3.9 related posts element.
View _about.md

The code in feature-bibblio-related-posts.php does not work and I think there is a bug in Bibblio's JS file.

prepareModuleOptions() calls getCustomUniqueIdentifierFromUrl() but does not pass it the options argument.

Note: feature-bibblio-related-posts.php is using a very thin framework called RPLib that I wrote. It auto-loads "modules" where different type modules have different traits available.

@mikeschinkel
mikeschinkel / reading-time.php
Last active Nov 9, 2018
Number of seconds to read an image, per Medium's algorithm: https://blog.medium.com/read-time-and-you-bc2048ab620c
View reading-time.php
<?php
function image_reading_seconds( $count ) {
// Every image start with 3 seconds
$reading_seconds = $count * 3;
// The first 9 images also add the cumulative
// amount of seconds calculated by 10 seconds
// minus the image count for each image.
$reading_seconds += 9 >= $count
@mikeschinkel
mikeschinkel / forms_model.php
Created Oct 27, 2018
Proposal for GravityForms to add a 'gform_custom_field_name_clauses' filter.
View forms_model.php
<?php
class GFFormsModel {
public static function get_custom_field_names() {
global $wpdb;
$clauses = apply_filters( 'gform_custom_field_name_clauses', array(
'found_rows' => '',
'distinct' => 'DISTINCT',
'fields' => 'meta_key',
@mikeschinkel
mikeschinkel / fix-gravity-forms.php
Created Oct 27, 2018
Fix GravityForms GFFormsModel::get_custom_field_names() for large numbers of posts and post meta by limiting to post_type='page'
View fix-gravity-forms.php
<?php
/**
* Class Fix_Gravity_Forms
*/
class Fix_Gravity_Forms {
const POST_TYPE = 'page';
const SQL_MARKER = "WHERE meta_key NOT BETWEEN '_' AND '_z'";
@mikeschinkel
mikeschinkel / pimple-example.php
Created Oct 18, 2018
The Problems with Pimple - What's wrong with this picture?
View pimple-example.php
<?php
$container = new Pimple();
$container['auth'] = function($c) {
return new OAuth();
};
$container['db'] = function($c) {
return new DB();
};
$container['tweet_service'] = function($c) {
$twService = new TwitterService();
@mikeschinkel
mikeschinkel / args-example.php
Created Oct 17, 2018
Example passing optional $args
View args-example.php
<?php
/**
* @param array $args
*
* @return string
*/
function get_banner_image_html( $size = 'medium', $args = array() ){
$args = array_merge( array(
'before' => '<figure class="show__banner-image">',
'after' => '</figure>',
@mikeschinkel
mikeschinkel / Example\Query.php
Last active Oct 18, 2018
Rough First Draft of Proposal for DI Container built into PHP
View Example\Query.php
<?php
namespace Example
class Query {
/**
* @var string
*/
public $name;
@mikeschinkel
mikeschinkel / alt-generics.md
Created Sep 29, 2018
An Alternate to Generics in GoLang
View alt-generics.md

An Alternate to Generics in GoLang

@mikeschinkel
mikeschinkel / IntOrString.class.php
Last active Sep 28, 2018
Potential Union Types in PHP
View IntOrString.class.php
<?php
class intOrString {
public $value;
function __construct( $value ) {
$this->value = $value;
}
function toInt(): int {
@mikeschinkel
mikeschinkel / __typeerror.php
Created Sep 27, 2018
Proposed __typeError() magic method
View __typeerror.php
<?php
declare(strict_types=1);
class Product {
public bool $archived;
function __typeError(TypeError $te) {
if ( 'archived' === $te->getVar() ) {
$message = 'TypeError: Line %d in file %s assigns type %s to the `archived` property which should only be assigned a `bool`.';
$message = sprintf( $message, $te->getLine(), $te->getFile(), gettype($te->getValue()));
error_log( $message );
You can’t perform that action at this time.