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
var array = ['A1', 'B12', 'C3', 11, 10, 1111, 22, 1, 4, 3, 5, 2, 0.23, 0]; | |
function sortArray(input) { | |
var output = input.sort(function(a, b) { | |
if (a === b) { | |
return 0; | |
} | |
if (typeof a === typeof b) { | |
return a < b ? -1 : 1; | |
} |
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
var array = [11, 10, 1111, 22, 1, 1, 1, 2, 2, 3, 4, 4, 5, 5, 5]; | |
function sortArray(input) { | |
var output = input.sort(function(a, b) { | |
return a - b; | |
}); | |
return output; | |
} | |
$("#output").text(sortArray(array)); // 1,1,1,2,2,3,4,4,5,5,5,10,11,22,1111 |
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
var array = ['1', '1', '1', '2', '2', '3', '4', '4', '5', '5', '5']; | |
function removeDuplicatesFromArray(input) { | |
var output = input.filter(function(elem, pos, arr) { | |
return arr.indexOf(elem) == pos; | |
}); | |
return output; | |
} | |
$("#output").text(removeDuplicatesFromArray(array)); // outputs: 1,2,3,4,5 |
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
.center-margin {margin:0 auto;} | |
.center-flex {display:flex; align-items:center; justify-content:center;} | |
.center-flex-hor {display:flex; justify-content:center;} | |
.center-flex-vert {display:flex; align-items:center;} | |
.center-transform {position:absolute; top:50%; left:50%; transform:translate(-50%, -50%);} | |
.center-transform-hor {position:absolute; left:50%; transform:translateX(-50%);} | |
.center-transform-vert {position:absolute; top:50%; transform:translateY(-50%);} |
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
// code from Stack Overflow, made into a function | |
// https://stackoverflow.com/a/10735151 | |
function injectJSFile(fileURL) { | |
var script = document.createElement('script'); | |
script.src=fileURL; | |
script.type='text/javascript'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
injectJSFile('../assets/js/local-file.js'); // USAGE |
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
Array.prototype.keySort = function(key, sort){ | |
this.sort(function(a, b) { | |
if (sort == 'desc') { | |
var result = (a[key] < b[key]); | |
} else if (sort == 'asc') { | |
var result = (a[key] > b[key]); | |
} | |
return result ? 1 : -1; | |
}); | |
return this; |
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
//source: https://stackoverflow.com/a/5158301 | |
function getUrlParam(name) { | |
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.href); | |
return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); | |
} | |
//USAGE | |
//assumed url: http://example.com?page=3&sort=asc&perPage=20 | |
getUrlParam('page'); | |
getUrlParam('sort'); |
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
get_category($category_id)->count //items in category | |
//just posts in category | |
$query = new WP_Query( array('posts_per_page' => -1, 'category__in' => $category) ); | |
$count = $query->post_count; | |
echo 'count: ' . $count; | |
INSIDE 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
print("<pre>" . print_r($array, true) . "</pre>"); | |
//https://stackoverflow.com/questions/4414623/loop-through-an-array-php | |
//Using foreach loop without key | |
foreach($array as $item) { | |
echo $item['filename']; | |
echo $item['filepath']; | |
// to know what's in $item | |
echo '<pre>'; var_dump($item); |
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 cutUrl(str, num) { | |
var matched = str.match("([^/]*\/){" + num + "}"); | |
return matched ? matched[0] : str; /* or null */ | |
} | |
//usage | |
//var url = location.pathname; | |
var url = "http://domain.com.com/page/subpage/fsdf/dsfg/dgff/gsd/fsdfsg/sddfsdf/gds/fsdf/"; | |
console.log( cutUrl(url, 4) ); |