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
// http://stackoverflow.com/a/8211012 | |
var array1 = ["test1", "test2", "test3", "test4"]; | |
var array2 = ["test1", "test2", "test3", "test4", "test5", "test6"]; | |
var _array = new Array(); | |
_array = jQuery.grep(array2, function(item) { | |
return jQuery.inArray(item, array1) < 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
// http://www.paulirish.com/2009/random-hex-color-code-snippets/ | |
(function(m, s, c) { | |
return (c ? arguments.callee(m, s, c - 1) : '#') + s[m.floor(m.random() * s.length)] | |
})(Math, '0123456789ABCDEF', 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
// http://devs.forumvi.com/t571-gist-shuffle-array-dao-ngau-nhien-doi-tuong-trong-mang | |
var arr = [1, 2, 3, 4, 5]; | |
/** | |
* Shuffling (randomizing) the order of an array | |
* http://www.javascriptkit.com/javatutors/arraysort.shtml | |
*/ | |
arr.sort(function () { | |
return .5 - Math.random(); | |
}); |
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
// New version, timezone support, modern browsers | |
(function (dt) { | |
return new Date(dt) | |
.toLocaleString('vi-VN', { | |
year: 'numeric', | |
month: '2-digit', | |
day: '2-digit', | |
hour: '2-digit', | |
minute: '2-digit', | |
second: '2-digit', |
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
/* http://www.jacklmoore.com/notes/rounding-in-javascript/ */ | |
function round(value, decimals) { | |
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); | |
} | |
/* http://stackoverflow.com/a/11832950 */ | |
Math.round(num * 100) / 100; | |
/* http://stackoverflow.com/a/12830454 */ | |
parseFloat("123.456").toFixed(2); |
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
// http://stackoverflow.com/a/8260383 | |
function youtube_parser(url){ | |
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; | |
var match = url.match(regExp); | |
if (match&&match[7].length==11){ | |
return match[7]; | |
} else { | |
alert("Url incorrecta"); | |
} | |
} |
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
// http://www.midnight-coding.com/2014/05/convert-string-to-binary-to-string.html | |
function stringToBinary(stringValue) { | |
return stringValue.replace(/.{1}/g, function (matchedString) { | |
var binString = matchedString.charCodeAt(0).toString(2); | |
return '00000000'.substring(0, 8 - binString.length) + binString; | |
}); | |
} |
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
// http://www.midnight-coding.com/2014/05/convert-string-to-binary-to-string.html | |
function binaryToString(binValue) { | |
return binValue.replace(/[01]{8}/g, function (matchedString) { | |
return String.fromCharCode(parseInt(matchedString, 2)); | |
}); | |
} |
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
// http://stackoverflow.com/a/4550514 | |
var rand = myArray[Math.floor(Math.random() * myArray.length)]; |
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
// Tiny jQuery Plugin | |
// by Chris Goodchild | |
$.fn.exists = function(callback) { | |
var args = [].slice.call(arguments, 1); | |
if (this.length) { | |
callback.call(this, args); | |
} | |
return this; |
OlderNewer