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 | |
/** | |
* Check if an array is a multidimensional array. | |
* | |
* @param array $arr The array to check | |
* @return boolean Whether the the array is a multidimensional array or not | |
*/ | |
function is_multi_array( $x ) { | |
if( count( array_filter( $x,'is_array' ) ) > 0 ) 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 | |
/** | |
* Remove specified keys from an array. | |
* | |
* @param array &$array The reference to the array to be modified | |
* @param array $keys An array of keys to be removed | |
* @return void | |
*/ | |
function remove_array_keys( &$array, $keys ) { | |
foreach( $array as $key => &$value ) { |
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
/** | |
* Calculate the monthly payments for paying off a loan | |
* Source: http://www.1728.org/loanform.htm | |
* | |
* @param integer apr APR of the loan | |
* @param integer term Length of repaying the loan in months | |
* @param integer loanAmount Amount that is being borrowed | |
* @return integer The monthly payments amount | |
*/ | |
function calculateMonthlyPayments(apr, term, loanAmount) { |
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 difference between two dates. | |
* | |
* @param string $int The interval to calculate (y = years, m = months, d = days, h = hours, i = minutes, s = seconds) | |
* @param string $d1 The first date (YYYYMMDD) | |
* @param string $d2 The second date (YYYYMMDD) | |
* @param mixed $round Whether to return a decimal value, or round up or down | |
* @param boolean $absolute Whether the value should always be positive | |
* @return integer $results The calculated value |
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
/** | |
* Sort an array by a key value | |
* | |
* @param array array The array that needs to be sorted | |
* @param string key The value of the key to sort by | |
* @return array The sorted array | |
*/ | |
function sortArrayByKey(array, key) { | |
return array.sort(function(a, b) { | |
var x = a[key]; |
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
/** | |
* Convert an RGB color value to HSL | |
* | |
* @param Number r The red color value (0-255) | |
* @param Number g The green color value (0-255) | |
* @param Number b The blue color value (0-255) | |
* @return Array The HSL representation | |
*/ | |
function rgbToHsl(r, g, b){ | |
r /= 255, g /= 255, b /= 255; |
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 a custom length content string. | |
* | |
* @param integer post ID of the parent page | |
* @return void | |
*/ | |
function wp_password_protect_children( $post ){ | |
foreach( get_post_ancestors( $post ) as $parent ) { | |
if( post_password_required( $parent ) ) { |
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
/** | |
* Send an email using Mandrill's API | |
* | |
* @return {void} | |
*/ | |
var sendMandrillEmail = function() { | |
$.ajax({ | |
type: "POST", | |
url: "https://mandrillapp.com/api/1.0/messages/send.json", | |
data: { |
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 | |
/** | |
* Clean a string. | |
* | |
* @param string $string The string that needs to be cleaned | |
* @return string The string that has been cleaned | |
*/ | |
function clean( $string, $divider='-', $camelcase=false ) { | |
// Remove special characters | |
$string = preg_replace('/[^\w]+/', ' ', $string); |