Workaday Reading

mishoo/UglifyJS2



"UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit. First make sure you have installed the latest version of node.js (You may need to restart your computer after this step)."

read »

Workaday Reading

Javascript call() & apply() vs bind()?



"I already know that apply and call are similar functions which setthis (context of a function). The difference is with the way we send the arguments (manual vs array) Question: But when should I use the bind() method ? var obj = { x: 81, getX: function() { return this.x; } }; alert(obj.getX."

read »

Workaday Reading

Element.closest()



"This is an experimental technology Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers."

read »

Workaday Reading

Pointer Lock API



"The Pointer Lock API (formerly called Mouse Lock API) provides input methods based on the movement of the mouse over time (i.e., deltas), not just the absolute position of the mouse cursor in the viewport."

read »

Workaday Reading

A Sage 9 + ACF debugging technique



"Thought I would share a debugging technique that’s working out well for me at the moment. I’ve never had any successes getting Xdebug and VS Code to play nicely but this technique also covers Advanced Custom Fields too."

read »

Workaday Reading

removeEventListener and this

"Have you ever tried to call removeEventListener on a previously attached element and couldn't remove it? Did you maybe try to pass a function to addEventListener that is bound to another context? The context of the callback that we are passing to addEventListener is the same as the event." read »

Add Special Chars to WordPress TinyMCE Char Map

Had an issue where a clients blog post had one of these in the post and it wasn’t being displayed right. The real issue was changing the ‘post_content’ field of the wp_posts table to UTF-8 Unicode (utf8mb4) from cp1252 West European, but (!) along the way I tried this. Put this in a plugin or functions.php and … Continued

Bash Current Directory Path

Gives you the full directory name of the script no matter where it is being called from. https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within Github Gist
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
 

Add browser and device name to WordPress body class

Github Gist
<?php
// Add Browser-Detection
function mv_browser_body_class($classes) {
    global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
    
    if($is_lynx) $classes[] = 'lynx';
    elseif($is_gecko) $classes[] = 'gecko';
    elseif($is_opera) $classes[] = 'opera';
    elseif($is_NS4) $classes[] = 'ns4';
    elseif($is_safari) $classes[] = 'safari';
    elseif($is_chrome) $classes[] = 'chrome';
    elseif($is_IE) {
            $classes[] = 'ie';
            if(preg_match('/MSIE ([0-9]+)([a-zA-Z0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $browser_version))
            $classes[] = 'ie'.$browser_version[1];
    } else $classes[] = 'unknown';
    if($is_iphone) $classes[] = 'iphone';
    if ( stristr( $_SERVER['HTTP_USER_AGENT'],"mac") ) {
             $classes[] = 'osx';
       } elseif ( stristr( $_SERVER['HTTP_USER_AGENT'],"linux") ) {
             $classes[] = 'linux';
       } elseif ( stristr( $_SERVER['HTTP_USER_AGENT'],"windows") ) {
             $classes[] = 'windows';
       }
    return $classes;
}
add_filter('body_class','mv_browser_body_class');
 

Recursively List Video Files URL’s

This will recursively list video files (currently filtered by a ‘.mp4’ preg_match) links when put at the root of a url. Rough and not pretty but it’s functional. Github Gist <?php function readDirs($path){ $dirHandle = opendir($path); while($item = readdir($dirHandle)) { $newPath = $path."/".$item; if(is_dir($newPath) && $item != '.' && $item != '..') { readDirs($newPath); } … Continued

Reading Today

Neural Networks in JavaScript with deeplearn.js

"A couple of my recent articles gave an introduction into a subfield of artificial intelligence by implementing foundational machine learning algorithms in JavaScript (e.g. linear regression with gradient descent, linear regression with normal equation or logistic regression with gradient descent)." read full text »