Skip to content

Instantly share code, notes, and snippets.

View GianlucaGuarini's full-sized avatar
🎸
Rocking the world with few lines of code

Gianluca Guarini GianlucaGuarini

🎸
Rocking the world with few lines of code
View GitHub Profile
Handlebars.getTemplate = function(name) {
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) {
$.ajax({
url : 'templatesfolder/' + name + '.handlebars',
success : function(data) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
Handlebars.templates[name] = Handlebars.compile(data);
},
@GianlucaGuarini
GianlucaGuarini / Backbone_Class_Inheritance.js
Last active December 18, 2015 15:59
Easy example to show how to extend an existing Backbone class inheriting its properties to the new children classes
/*
*
* Parent class containing some methods and properties that must be inherited
*
*/
var ParentClass = Backbone.Model.extend({
initialize: function() {
this.set('name','Dear');
},
say_hello: function ( ) {
Object.getOwnPropertyNames(window.Math).forEach(function (method) {
window[method] = Math[method];
});
/**
*
* Here we will could extend lodash with some custom useful methods
*
*/
(function (_) {
'use strict';
/**
* Initialize a new array having a custom length and a custom default value
* @param { Number | Object | String } defaultValue: any valid javascript element
@GianlucaGuarini
GianlucaGuarini / svgcheckbx_cleaned.js
Last active July 22, 2022 02:21
Cleaned version of the svgcheckbx.js file used in this demo http://tympanus.net/Development/AnimatedCheckboxes/
;(function(document, window, undefined) {
// wrap always your modules to avoid the namespace pollution
// use always the strict statement
'use strict';
// you do not need to wrap all your code in an if statement...
if (!document.createElement('svg').getAttributeNS) return;
// shortcut to select any DOM element
var $ = document.querySelectorAll.bind(document),
// create an array with all the inputs to uste
// BTW I am sure that this solution is neither correct but it comes from the original code logic
@GianlucaGuarini
GianlucaGuarini / rivets.Backbone.conf.js
Last active December 25, 2015 18:19
Backbone + Rivets.js configuration and helpers
rivets.configure({
templateDelimiters: ['{{', '}}']
});
@GianlucaGuarini
GianlucaGuarini / Model.js
Last active December 29, 2015 23:59
Simple Model class inspired to the Backbone models.
/**
* Simple Model class to listen all its status changes
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
@GianlucaGuarini
GianlucaGuarini / post-merge
Last active August 22, 2023 20:54 — forked from sindresorhus/post-merge
Git hook that gets triggered after any 'git pull' whenever one of the files specified has changed. Useful to update any web application dependency using bower npm or composer
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep -E --quiet "$1" && eval "$2"
}
@GianlucaGuarini
GianlucaGuarini / iPad-IOS7-landscape-fullscreen-hack.js
Last active April 7, 2017 21:18
Hack to solve the annoying iPad iOS7 landscape extra height issue on the fullscreen web applications http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
/*!
*
* Author: Gianluca Guarini
* Contact: gianluca.guarini@gmail.com
* Website: http://www.gianlucaguarini.com/
* Twitter: @gianlucaguarini
*
*
**/
if (navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i)) {
@GianlucaGuarini
GianlucaGuarini / theme.css
Created September 20, 2014 16:00
Colorsublime css theme template
.%cssClass% .ace_gutter {
background: #e8e8e8;
color: #333;
}
.%cssClass% .ace_print-margin {
width: 1px;
background: %printMargin%;
}