Skip to content

Instantly share code, notes, and snippets.

@ppscvalentin
ppscvalentin / checkCallback.js
Created April 24, 2019 14:12
Check if there is a callback passed as an argument before trying to execute
if (callback && typeof(callback) === "function") {
callback();
}
@ppscvalentin
ppscvalentin / Component.Vue
Created January 9, 2019 15:32
Vue EventBus to couple components loosely
import EventBus from 'Events.js'
export default {
...
mounted() {
EventBus.$emit('eventName', payload);
}
...
}
@ppscvalentin
ppscvalentin / .gitignore
Last active January 2, 2019 13:10
nuxt.js config for static website
# Created by https://www.gitignore.io/api/vue,node,nuxt,macos,visualstudiocode
# Edit at https://www.gitignore.io/?templates=vue,node,nuxt,macos,visualstudiocode
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
@ppscvalentin
ppscvalentin / font-rendering.css
Created November 19, 2018 09:27
Fix thick font rendering
/* https://stackoverflow.com/questions/28217486/font-renders-thicker-in-browsers */
body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
}
@ppscvalentin
ppscvalentin / visibility.css
Created November 2, 2018 09:52
Visibility classes
/* visibility */
.hidden {
display: none!important;
}
@media (max-width: 599px) {
.hidden-p { display: none!important; }
}
@media (min-width: 600px) and (max-width: 899px) {
.hidden-tp { display: none!important; }
}
@ppscvalentin
ppscvalentin / attributes.js
Created December 12, 2017 08:54
attributes.js
// https://davidwalsh.name/javascript-attributes
Array.prototype.slice.call(document.getElementById("myId").attributes).forEach(function(item) {
console.log(item.name + ': '+ item.value);
});
@ppscvalentin
ppscvalentin / meta.html
Created August 24, 2017 08:53
meta.html
<!doctype html>
<html lang="en" prefix="og: http://ogp.me/ns/website#">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<meta name="description" content="Description">
<!-- og -->
@ppscvalentin
ppscvalentin / debounce.js
Created August 22, 2017 08:15
debounce, throttle
// https://davidwalsh.name/function-debounce
debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
var events = (function(){
var topics = {};
var hOP = topics.hasOwnProperty;
return {
subscribe: function(topic, listener) {
// Create the topic's object if not yet created
if(!hOP.call(topics, topic)) topics[topic] = [];
// Add the listener to queue
@ppscvalentin
ppscvalentin / queryString.js
Created July 26, 2017 19:53
queryString.js
function encodeQueryData(data) {
var ret = [];
for (let d in data)
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d]));
return ret.join('&');
}