Skip to content

Instantly share code, notes, and snippets.

View VinnyFonseca's full-sized avatar
🏠
Working from home

Vinny Fonseca VinnyFonseca

🏠
Working from home
View GitHub Profile
@VinnyFonseca
VinnyFonseca / addeventlistener-multiple-events.js
Last active January 12, 2023 16:08
addEventListener multiple events
['change', 'keyup', 'paste', 'input', 'propertychange', 'every_other_event_you_want'].forEach(eventType => {
[...document.querySelectorAll('SELECTOR')].forEach(element => {
element.addEventListener(eventType, (event) => {
console.log(event);
// Your callback here
}, false);
});
});
@VinnyFonseca
VinnyFonseca / popup.js
Last active October 25, 2021 09:51
New Popup Window
const popup = function (url, title, w = 640, h = 320) {
let l = (screen.width / 2) - (w / 2);
let t = (screen.height / 2) - (h / 2);
return window.open(url, title, `
toolbar=no,
location=no,
directories=no,
status=no,
menubar=no,
@VinnyFonseca
VinnyFonseca / empty-object-check.js
Last active September 28, 2021 21:50
Empty Object Check
function isEmpty(obj) {
return (
(typeof obj == 'undefined' || obj === null || obj === '')
|| (typeof obj == 'number' && isNaN(obj))
|| (obj instanceof Date && isNaN(Number(obj)))
);
};
#!/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 December 28, 2019 17:58
Email: Hide images in all desktop clients
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;
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 March 15, 2018 13:54
Closest Element Behaviour
document.body.addEventListener('click', function(event) {
if ( !event.target.closest("SELECTOR").length && document.querySelector("SELECTOR").hasClass("active") ) {
// Your function here
};
});
@VinnyFonseca
VinnyFonseca / ga.js
Last active December 7, 2017 12:40
Google Analytics Implementation
<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 / fb-page-tab-like-gate.js
Last active December 7, 2017 12:38
Facebook Page Tab Like Gate
var appId = 'XXXXXXXXXXXXXXX';
// Taken from the App's configuration page
window.fbAsyncInit = function() {
FB.init({
appId: appId,
status: true,
cookie: true,
xfbml: true
});
@VinnyFonseca
VinnyFonseca / randomize.js
Last active December 7, 2017 12:35
Randomize
const rand = (min, max) => Math.floor(Math.random() * (max - min)) + min;