Skip to content

Instantly share code, notes, and snippets.

View genesisneo's full-sized avatar
👽

Neo Genesis genesisneo

👽
View GitHub Profile
@genesisneo
genesisneo / checkClass.js
Last active October 18, 2015 07:10
JavaScript | hasClass, addClass, removeClass
// Pure JavaScript hasClass, addClass, and removeClass.
// Source: http://www.avoid.org/?p=78
function hasClass(el, name) {
return new RegExp('(\\s|^)'+name+'(\\s|$)').test(el.className);
}
function addClass(el, name) {
if (!hasClass(el, name)) { el.className += (el.className ? ' ' : '') +name; }
}
function removeClass(el, name) {
if (hasClass(el, name)) {
@genesisneo
genesisneo / smoothScroll.js
Last active November 7, 2015 06:10
jQuery | Page smooth scroll
// jQuery scroll page smoothly depends on the link target ID and
// prevent #ID on the URL. Windows Phone has a built-in smooth-scroll
$('a[href^="#"]').click(function () {
$('html, body').animate({ scrollTop:$(this.hash).offset().top },500);
return false;
});
@genesisneo
genesisneo / preventRedirection.js
Last active October 18, 2015 07:13
JavaScript | Prevent page from redirecting
// Prevent or stop page from redirecting to the next page
window.onbeforeunload = function() {
return 'Are you sure you want to leave?';
};
@genesisneo
genesisneo / countDownTimer.js
Created May 2, 2016 05:41
JavaScript | Countdown Timer
// Countdown timer script, after 25secs it will add class on the body class="stop-animations"
// and clear the intervar. Timer value (60 * 1 = 1 minute)
function startTimer(duration, display, isRunning) {
if (!!isRunning) {
var timer = duration, minutes, seconds;
var interval = setInterval(function () {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
@genesisneo
genesisneo / removeComments.js
Last active May 30, 2017 06:57
JavaScript | Remove all comments in HTML
// Remove all comments in HTML
$('body').contents().filter(function() {
return this.nodeType == 8;
}).remove();
@genesisneo
genesisneo / vscode-extension.sh
Last active June 14, 2023 14:51
Prefered settings for Visual Studio Code https://code.visualstudio.com/
// required
code --install-extension emmanuelbeziat.vscode-great-icons
code --install-extension oderwat.indent-rainbow
code --install-extension dbaeumer.vscode-eslint
code --install-extension stylelint.vscode-stylelint
code --install-extension esbenp.prettier-vscode
code --install-extension visualstudioexptteam.vscodeintellicode
code --install-extension VisualStudioExptTeam.intellicode-api-usage-examples
code --install-extension eamodio.gitlens
code --install-extension waderyan.gitblame
@genesisneo
genesisneo / sublime-settings.json
Last active November 23, 2017 08:32
Prefered settings for Sublime Text https://www.sublimetext.com/
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_white_space": "all",
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"translate_tabs_to_spaces": true,
"word_wrap": "false"
@genesisneo
genesisneo / formattedCounter.js
Created March 30, 2017 11:05
JavaScript | Formatted Counter
// A simple counter and the numbers will be
// formatted to xxx,xxx,xxx
function formatNum(num) {
var parts = String( num ).replace(/[^\d.]-/g,'').split('.');
var str = parts[0].split('').reverse().join('');
var retVal = '';
while( retVal != (str = str.replace(/(\d{3})(\d{1,3})/,'$1,$2')) ) {
retVal = str;
}
if( parts[1] ) {
@genesisneo
genesisneo / aeTimeControl.txt
Created April 3, 2017 07:49
After Effects | Time Control
function timeControl(n){
if (n < 10) return "0" + n else return "" + n;
}
t = Math.floor(effect("Slider Control")("Slider"));
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
/* hours */
@genesisneo
genesisneo / addMultipleEventListener.js
Created May 30, 2017 06:55
JavaScript | Multiple Event Listener
// Add multiple event listener to element
// Usage: addMutiEventListener(element, 'click touchstart', function() {});
function addMutiEventListener(el, s, fn) {
s.split(' ').forEach(function (e) {
return el.addEventListener(e, fn, false);
});
}