Skip to content

Instantly share code, notes, and snippets.

View amatiasq's full-sized avatar

A. Matías Quezada amatiasq

View GitHub Profile
@amatiasq
amatiasq / template.js
Created April 5, 2013 10:41
Multiplatform adapter (require, dojo, node.js and vanilla browser)
(function(factory) {
if (typeof define !== 'undefined' && define.amd)
return define(factory);
if (typeof module !== 'undefined' && module.exports === exports)
return module.exports = factory();
window.LIB_NAME = factory();
// Defines a module that works in Node and AMD.
// This version can be used as common boilerplate for a library module
// that you only want to expose to Node and AMD loaders. It will not work
// well for defining browser globals.
// If you need a version of this file that works CommonJS-like environments
// that do not support module.exports or if you want to define a module
// with a circular dependency, see commonjsAdapter.js
@amatiasq
amatiasq / grid.less
Last active February 15, 2021 22:18
A mixin to create a N * N css classes grid.
.grid_column(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}col@{index}';
@{fullclass} { left: @base * @index; }
}
.grid_row(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}row@{index}';
@{fullclass} { top: @base * @index; }
}
.grid_width(@prefix; @index; @base) {
@fullclass: ~'.grid-@{prefix}hspan@{index}';
@amatiasq
amatiasq / app.build.js
Last active December 16, 2015 08:09
Testing a script to be used instead of almond
({
name: "require.optimized",
optimize: "none",
include: ["main"],
out: "out.js"
})
@amatiasq
amatiasq / clone.js
Last active February 15, 2021 22:18
Creates a copy of a object duplicating every property, even prototyped ones.
var extend = Object.getOwnPropertyNames ?
function ecma5extend(obj) {
var proto = obj;
var protos = [];
var result = {};
var descriptors = {};
while (proto) {
protos.push(proto);
proto = Object.getPrototypeOf(proto);
@amatiasq
amatiasq / base-extend.js
Last active December 17, 2015 13:39
A function to create
/**
* Provides:
* Function extend(Function parent, Object config, Object statics);
*
* It extends constructors with it's methods
* Also provides to every method who overwrites another one
* with a this.base() method to invoke overwrote method.
* This feature is based in Dean Edwards implementation:
* http://dean.edwards.name/weblog/2006/03/base/
*
@amatiasq
amatiasq / loadFiles.js
Created July 17, 2013 16:21
A file to load every file found on the same folder or subfolders.
'use strict';
var fs = require("fs");
function scan(dir) {
var files = [];
fs.readdirSync(dir).forEach(function(file) {
var path = dir + '/' + file;
var stat = fs.statSync(path);
//jshint camelcase:false
(function() {
function noop() {}
/**
* Returns true if {target} is a function
*
* @param target The object to analyze
@amatiasq
amatiasq / remote.js
Created September 30, 2013 13:44
A series of angular modules to unify firebase's angularFire library and remoteStorage protocol
angular.module('remote-firebase', [ 'firebase' ])
.value('firebaseServer', null)
.factory('remoteCollection', function(firebaseServer, angularFireCollection) {
return function(module) {
var url = firebaseServer + '/' + module;
var ref = new Firebase(url);
return angularFireCollection(ref);
};
@amatiasq
amatiasq / mq-appcache.js
Last active December 29, 2015 18:19
Two AngularJS directives to manage appcache updates.
'use strict';
angular.module('mq-appcache', [])
.directive('manifest', function() {
return {
compile: function() {
if (window.applicationCache) {
applicationCache.addEventListener('updateready', function() {
console.log('New version downloaded, reload to see the changes.');
});