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 / 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 / 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 / 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}';
// 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 / 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();
@amatiasq
amatiasq / constructor-extend.js
Last active February 15, 2021 22:18
A simple constructor extension function. Creates a constructor who prototypes "this" and adds the properties passed.
/*globals define, module */
//jshint camelcase: false, curly:false
(function(root) {
'use strict';
// __proto__ will be used if supported
//jshint -W103
function prototype_PROTO(parent, child, methods) {
@amatiasq
amatiasq / clazz.js
Created March 21, 2013 18:12
A implementation of the fake-operator-overload inheritance. (http://www.2ality.com/2011/12/fake-operator-overloading.html) Just for fun
(function(root) {
var current = {
parent: null,
config: null,
};
function clazz(name) {
function Class(config) {
@amatiasq
amatiasq / expect.js
Created March 21, 2013 15:59
Another expectation module
/**
* Copyright © 2009-2012 A. Matías Quezada
*/
(function(root) {
var undefined;
function extend(config) {
var parent = this;
@amatiasq
amatiasq / extensions.js
Last active December 13, 2015 22:49
How to dominate Javascript's world
(function extensions() {
function arr(val) {
return Array.prototype.slice.call(val);
}
function extend(Type, prototype) {
function E(val) { this.val = val }
E.prototype = prototype;
prototype.constructor = E;
@amatiasq
amatiasq / tpl.js
Last active February 15, 2021 22:18
A simple RequireJS plugin to include Handlebars templates
define(function(require) {
var text = require('text');
var view = require('view');
var cache = {};
function load(name, parentRequire, done, config) {
text.load(name, parentRequire, function(template) {
cache[name] = template;