Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Vinny Fonseca VinnyFonseca

🏠
Working from home
View GitHub Profile
@VinnyFonseca
VinnyFonseca / addeventlistener-multiple-events.js
Last active Jul 10, 2020
addEventListener multiple events
View addeventlistener-multiple-events.js
["change", "keyup", "paste", "input", "propertychange", "..."].forEach(function(event) {
document.querySelectorAll('.element').addEventListener(event, function() {
// Your callback here
}, false);
});
View rename-git-stash.sh
#!/bin/bash
git stash list
echo "Enter stash number to rename"
read stash_number
echo "Enter new name"
read new_name
stash_name="stash@{${stash_number}}"
echo "$stash_name"
@VinnyFonseca
VinnyFonseca / email-hide-images.css
Last active Dec 28, 2019
Email: Hide images in all desktop clients
View email-hide-images.css
table[class="mob-show"],
tr[class="mob-show"],
td[class="mob-show"],
span[class="mob-show"],
a[class="mob-show"],
img[class="mob-show"] {
display: none !important;
font-size: 0 !important;
width: 0 !important;
height: 0 !important;
View active-touch-detection.js
const wasTouched = () => {
myFrameworkOfChoice.dispatchEvent('USER_HAS_TOUCHED', true);
window.removeEventListener('touchstart', wasTouched, false);
window.addEventListener('mousedown', wasClicked, false);
};
const wasClicked = () => {
myFrameworkOfChoice.dispatchEvent('USER_HAS_TOUCHED', false);
window.removeEventListener('mousedown', wasClicked, false);
window.addEventListener('touchstart', wasTouched, false);
@VinnyFonseca
VinnyFonseca / closest-element-behaviour.js
Last active Mar 15, 2018
Closest Element Behaviour
View closest-element-behaviour.js
document.body.addEventListener('click', function(event) {
if ( !event.target.closest("SELECTOR").length && document.querySelector("SELECTOR").hasClass("active") ) {
// Your function here
};
});
View empty-object-check.js
function isEmpty(obj) {
if (typeof obj == 'undefined' || obj === null || obj === '') return true;
if (typeof obj == 'number' && isNaN(obj)) return true;
if (obj instanceof Date && isNaN(Number(obj))) return true;
return false;
};
@VinnyFonseca
VinnyFonseca / ga.js
Last active Dec 7, 2017
Google Analytics Implementation
View ga.js
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@VinnyFonseca
VinnyFonseca / switch.js
Last active Dec 7, 2017
Switch Statement
View switch.js
switch(n) {
case 1: {
execute code block 1;
break;
}
case 2: {
execute code block 2;
break;
}
@VinnyFonseca
VinnyFonseca / fb-page-tab-like-gate.js
Last active Dec 7, 2017
Facebook Page Tab Like Gate
View fb-page-tab-like-gate.js
var appId = 'XXXXXXXXXXXXXXX';
// Taken from the App's configuration page
window.fbAsyncInit = function() {
FB.init({
appId: appId,
status: true,
cookie: true,
xfbml: true
});
View randomize.js
const rand = (min, max) => Math.floor(Math.random() * (max - min)) + min;
You can’t perform that action at this time.