Skip to content

Instantly share code, notes, and snippets.

View alvarezmauro's full-sized avatar
👾

Mauro Alvarez alvarezmauro

👾
View GitHub Profile
@alvarezmauro
alvarezmauro / css-font-face.css
Last active October 21, 2016 04:12
CSS - @font-face (Custom fonts)
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
@alvarezmauro
alvarezmauro / js-getRootUrl.js
Last active October 21, 2016 04:10
JS - Get The Current Root URL
// Retrieve root URL
var rootUrl = location.protocol + '//' + location.host;
@alvarezmauro
alvarezmauro / js-getHashParameter
Last active October 21, 2016 04:12
JS - Get A URL Hash Parameter
// Get # parameter
var param = document.URL.split('#')[1];
@alvarezmauro
alvarezmauro / debounce.js
Last active May 8, 2018 02:45
JS - Debounce
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@alvarezmauro
alvarezmauro / getAbsoluteUrl.js
Last active May 8, 2018 02:45
JS - Get absolute URL using a string variable.
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
@alvarezmauro
alvarezmauro / border-box.css
Last active May 8, 2018 00:27
CSS - Boder Box
/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
@alvarezmauro
alvarezmauro / module-designPattern.js
Last active May 8, 2018 02:46
JS Design Pattern - Module
(function() {
// declare private variables and/or functions
return {
// declare public variables and/or functions
}
})();
@alvarezmauro
alvarezmauro / singleton-desingPattern.js
Last active May 8, 2018 02:46
JS Design Pattern - Singleton
var singleton = (function () {
var singletonInstance;
function create () {
var singletonPrivateVariable = 'Private variable'
function singletonMethod() {
// Method
}
@alvarezmauro
alvarezmauro / inheritance-designPatterns.js
Last active May 8, 2018 02:46
JS Design patterns - Inheritance - Explicit prototype declaration, Object.create, method factory
var Animal = {
create(type){
var animal = Object.create(Animal.prototype);
animal.type = type;
return animal;
},
isAnimal(obj, type){
if(!Animal.prototype.isPrototypeOf(obj)){
return false;
}
@alvarezmauro
alvarezmauro / js-DOM-addClass.js
Last active May 8, 2018 02:43
JS - Add a Class to HTML elements
/******************************************************************************************************
* @function addClass
* @desc Add a Class to HTML elements
* @param (elements) - String selector (eg: '#iddiv' or '.classdiv')
* or DOM elements (eg: document.querySelectorAll('.classdiv') )
* @param (myClass) - String calss name you whant to add (eg: 'newClass')
******************************************************************************************************/
function addClass(elements, myClass) {
// if there are no elements, we're done
if (!elements) {