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 createMatrix(shape, fill = null) { | |
| const isFunc = typeof fill === 'function'; | |
| function build(dims, parentIndex) { | |
| if (dims.length === 0) { | |
| return isFunc ? fill(parentIndex) : fill; | |
| } | |
| const [currentSize, ...restDims] = dims; |
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
| const getPreviousMatch = (el, target) => { | |
| // Get the next matching element | |
| let match = el.previousElementSibling; | |
| // If there's no selector, return the first element | |
| if (!target) return match; | |
| // If the element matches our selector, use it | |
| // If not, jump to the next element and continue the loop |
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 | |
| function array_key_exists_r($array, $keySearch) { | |
| if (is_array($array)) { | |
| foreach ($array as $key => $item) { | |
| return ($key == $keySearch) ? true : (array_key_exists_r($item, $keySearch)) ? true : false; | |
| } | |
| } | |
| return false; | |
| } |
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
| const testGeolocation = function() { | |
| if ('permissions' in navigator) { | |
| navigator.permissions.query({name:'geolocation'}).then(function(response) { | |
| if (response.state == 'prompt') { | |
| // do stuff for permission request | |
| } else if (response.state == 'denied') { | |
| // do stuff for permission denied | |
| } else { | |
| // do stuff for permission granted | |
| } |
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
| const paramExists = function(name) { | |
| let params = window.location.search; | |
| if (params.indexOf('?'+name) > -1 || params.indexOf('&'+name) > -1) { | |
| return true; | |
| } | |
| return false; | |
| }; |
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 | |
| // Create pseudo-random order numbers while retaining | |
| // the uniqueness of Woo's order number system | |
| function change_woocommerce_order_number($order_id) { | |
| // The prefix is prepended to the actual order number | |
| // It consists of the month number (without leading zeros) followed by a hyphen | |
| // and then followed by the current minutes (minus leading zeros) | |
| $prefix = date('n').'-'.ltrim(date('i'), 0); // This is prepended to the order number |
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 | |
| # Recursive replacement for in_array() function | |
| function array_search_recursive($needle, $haystack) { | |
| # Validate data types | |
| if (is_array($needle) || !is_array($haystack)) { | |
| return null; | |
| } |
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 | |
| class Request { | |
| /** | |
| * do_post | |
| * POST request | |
| * | |
| * @access public | |
| * @param string $url - url |
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
| const rgb2hex = function(r, g, b) { | |
| return hexify(r).hexify(g).hexify(b); | |
| }; | |
| const hexify = function(num) { | |
| let hex = num.toString(16); | |
| return hex.length == 1 ? "0" + hex : hex; | |
| }; |
NewerOlder