January 2021

Tools & services

Image hosting

Gears

  • Keychron K3 - World's First Hot-Swappable Low Profile Optical Wireless Mechanical Keyboard
  • A2+ Speakers - A2+ premium powered speakers with high-fidelity stereo sound
  • Gibbon AIR - active monitor system with Bluetooth
  • Neumann NDH-20 - premium quality studio headphones
  • Lagoon anc traveller - Wireless headphones with ANC from BeyerDynamic
  • Sony WH-1000XM4 - Wireless Noise-Canceling Headphones form Sony
  • Raspberry Pi Pico - Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040, a brand new microcontroller chip designed by Raspberry Pi

Comments

  • Guestbook - GitHub issue based Guestbook
  • Utteranc - A lightweight comments widget built on GitHub issues.
  • Octomments - Using GitHub issues as a comment plugin.
  • Commento - Embed comments without giving up your privacy.
  • Fast Comments - A comment service that will delight your users and developers.

Earl Grey

Webdesign

  • Primer - Design, build, and create with GitHub’s design system

#notes#2021

PHP code speed comparison

function versus(callable $first, callable $second, $repeat = 100000) {
    
    $f = microtime(true);
    foreach (range(0, $repeat) as $r) call_user_func($first);
    $firstTimer = microtime(true) - $f;
    
    $s = microtime(true);
    foreach (range(0, $repeat) as $r) call_user_func($second);
    $secondTimer = microtime(true) - $s;

    printf(
        '%s function is %.2f%% faster (%f vs %f)',
        $firstTimer < $secondTimer ? 'First' : 'Second',
        abs((($firstTimer - $secondTimer) / $firstTimer) * 100),
        $firstTimer, $secondTimer
    );
}

Example

versus(
    function () {
        $str = '!loremipsum';
        return substr($str, 0, 1) === '!';
    },
    function () {
        $str = '!loremipsum';
        return $str[0] === '!';
    }
);

Will print:

Second function is 36.72% faster (0.142766 vs 0.090349)

#PHP#Snippets#2020

Debug WordPress 404 page

Insert following code to functions.php for debuging 404 page:

ini_set('error_reporting', -1);
ini_set('display_errors', 'On');

add_action(
    'parse_request',
    function (&$wp) {
        global $wp_rewrite;

        printf('<h2>rewrite rules</h2><pre>%s</pre>', var_export($wp_rewrite->wp_rewrite_rules(), true));
        printf('<h2>permalink structure</h2><pre>%s</pre>', var_export($wp_rewrite->permalink_structure, true));
        printf('<h2>page permastruct</h2><pre>%s</pre>', var_export($wp_rewrite->get_page_permastruct(), true));
        printf('<h2>matched rule and query</h2><pre>%s</pre>', var_export($wp->matched_rule, true));
        printf('<h2>matched query</h2><pre>%s</pre>', var_export($wp->matched_query, true));
        printf('<h2>request</h2><pre>%s</pre>', var_export($wp->request, true));

        global $wp_the_query;
        printf('<h2>the query</h2><pre>%s</pre>', var_export($wp_the_query, true));
    }
);

add_action(
    'template_redirect',
    function () {
        global $wp_filter;
        printf(
            '<h2>template redirect filters</h2><pre>%s</pre>',
            var_export($wp_filter[current_filter()], true)
        );
    }, 99999
);

add_filter(
    'template_include',
    function ($template) {

        printf(
            '<h2>template file selected</h2><pre>%s</pre>',
            var_export($template, true)
        );
        exit();
    }
);

#Wordpress#PHP#2020