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
/** | |
* Scroll window to an element | |
*/ | |
$('a[href^="#"]').not('a[href="#"]').click(function(e) { | |
e.preventDefault(); | |
$('html, body').animate({ | |
scrollTop: $($(this).attr('href')).offset().top | |
}, 500); | |
}); |
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 excerpt string from the first paragraph of the content. | |
* | |
* @param integer $id The id of the post | |
* @return string $excerpt The excerpt string | |
*/ | |
function wp_first_paragraph_excerpt( $id=null ) { | |
// Set $id to the current post by default | |
if( !$id ) { |
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); |
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 | |
/** | |
* 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
/** | |
* 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
/** | |
* 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
<?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
/** | |
* 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) { |