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 / advice.js
Created June 11, 2012 13:46 — forked from angus-c/advice.js
simplest advice functional mixin
// usage
withAdvice.call(targetObject);
var withSomething = function() {
this.wrap('walk', function() {
// before
this.base();
// after
});
};
@amatiasq
amatiasq / HurdlesHack.js
Created August 7, 2012 13:50
Hack today's Google's Doodle (press numpad 0 to start)
function press(key) {
document.getElementById("hplogo").onkeydown({
keyCode:key,
preventDefault:function() { }
});
}
var interval;
document.addEventListener('keydown', function(e) {
if (e.keyCode !== 96)
@amatiasq
amatiasq / extend.base.js
Last active October 12, 2015 14:07
Simple base class with this.base() to call parent mehtod
/**
* Provides:
* Function extend(Function parent, Object config);
*
* 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.
*
* Created constructor has methods
* .extend(Object config)
@amatiasq
amatiasq / Preferences.sublime-settings
Created November 16, 2012 15:08
My Sublime Text configuration
{
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"rulers": [ 80, 120 ],
"highlight_line": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"auto_complete_commit_on_tab": true,
"shift_tab_unindent": true,
@amatiasq
amatiasq / Handlebars- Backbone.js
Created February 5, 2013 00:06
This allow Handlebars to look up Backbone Model's attributes: {{ user.address.street }} If user is a Backbone Model this will become user.get("address").street And if user.get("adress") is also a Backbone Model this will be produced: user.get("address").get("street")
Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
var result = '(' + parent + ' instanceof Backbone.Model ? ' + parent + '.get("' + name + '") : ' + parent;
if (/^[0-9]+$/.test(name)) {
return result + "[" + name + "])";
} else if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return result + "." + name + ')';
} else {
return result + "['" + name + "'])";
}
};
@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;
@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 / 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 / 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 / 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) {