This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFontSize(n) { | |
return parseInt(window.getComputedStyle(n, null).getPropertyValue('font-size')) | |
} | |
function renderNode(n) { | |
let output = [n.tagName] | |
n.id && output.push(`id="${n.id}"`) | |
n.className && output.push(`class="${n.className}"`) | |
return output.join(' ') | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function x(n) { | |
if(n.children.length > 60) { | |
console.log(n) | |
} | |
Array.from(n.children).forEach(x) | |
} | |
x(document.getElementsByTagName('html')[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Start a new pool named 'www'. | |
; the variable $pool can be used in any directive and will be replaced by the | |
; pool name ('www' here) | |
[www] | |
; Per pool prefix | |
; It only applies on the following directives: | |
; - 'access.log' | |
; - 'slowlog' | |
; - 'listen' (unixsocket) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Flatten a JavaScript array | |
* @param {Array} arr Array to flatten | |
* @param {number} depth Levels deep to flatten | |
* @return Array | |
*/ | |
export default function flatten(arr, depth = 1) { | |
if(depth === 0) return arr | |
let newArr = [] | |
arr.forEach((x) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Disable WP REST API JSON endpoints if user not logged in | |
*/ | |
function chuck_disable_rest_endpoints( $access ) { | |
if( ! is_user_logged_in() ) { | |
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) ); | |
} | |
return $access; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress template renderer that avoids using global variables | |
* @param string Name of a template to load | |
* @param array $args Template variables | |
* @return string|WP_Error rendered template or an error | |
* NOTE: Untested | |
*/ | |
function render_template( $template_name, array $args ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculate the reading time for a piece of content | |
* | |
* @param string $content | |
* @param integer $wpm Words Per Minute reading speed | |
* | |
* @return array minutes => integer, seconds => integer | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DaveRoss\FunctionalProgrammingUtils\Left as Left; | |
use DaveRoss\FunctionalProgrammingUtils\Right as Right; | |
/** | |
* @param string $json A JSON string | |
* @return Either | |
*/ | |
function parse_json_returning_either( $json ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DaveRoss\FunctionalProgrammingUtils\Maybe as Maybe; | |
$good = Maybe::of( json_decode( '{ "label": "This is valid JSON", "value": 5 }' ) ); | |
$bad = Maybe::of( json_decode( '{ "label": This is invalid JSON, "value": 5 }' ) ); | |
$good->map( function( $obj ) { echo $obj->value . "\n"; } ); | |
$bad->map( function( $obj ) { echo $obj->value . "\n"; } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$good = json_decode('{ "label": "This is valid JSON", "value": 5 }' ); | |
$bad = json_decode('{ "label": This is invalid JSON, "value": 5 }' ); | |
if( is_null( $good ) ) { | |
echo "Couldn't parse good JSON\n"; | |
} | |
else { | |
echo $good->value . "\n"; |
NewerOlder