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 »

Some Monday morning irony

In 1994 the Ku Klux Klan applied to sponsor a portion of United States Interstate 55 in St. Louis County and Jefferson County, Missouri, near St. Louis, for cleanup (which allowed them to have signs stating that this section of highway was maintained by the organization). Since the state could not refuse the KKK’s sponsorship, … Continued

Listen to this

Listen to this while coding/typing on the keyboard and tell me your fingers don’t start tapping with flare and pizazz. Ha! III. Rondo. Vivace

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

What is Currying?



"And realized that we need a simpler tutorial to understand currying, the logic behind it, the nuances and the usage. We will be using Haskell for this tutorial, but this can be extended to any functional programming language."

read full text »