Skip to content

Instantly share code, notes, and snippets.

View telekosmos's full-sized avatar
💭
👻

Guillermo C. Martínez telekosmos

💭
👻
View GitHub Profile
@telekosmos
telekosmos / gist:4203206
Created December 4, 2012 12:16
angularjs mvctodo controller with coffeescript
@TodoController = () ->
@todos = []
@newTodo = ""
@addTodo = () ->
if @newTodo.length > 0
@todos.push( { content: @newTodo, done: false, editing: false } )
@newTodo = ""
@editTodo = (todo) ->
@telekosmos
telekosmos / gist:4619917
Created January 24, 2013 10:48
toType js function: returns the most accurate js type for a js object
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
@telekosmos
telekosmos / gist:5372354
Created April 12, 2013 14:21
Comparison between class members and configs in ExtJs 4 class model. It seems the configs are diff from members regarding to getter/setter methods created, apply methods created and no straight access to configs (as opposite to members). In addition, members are read-write
Ext.define('My.sample.Person', {
/** @readonly */
name: 'Unknown',
config: {
midname: undefined
},
constructor: function(name, config) {
this.initConfig(config);
this.name = name;
@telekosmos
telekosmos / gist:5372464
Created April 12, 2013 14:37
Array of function objects with (potentially) asynchronous execution which keeps the result inside an object...
var sum = function (a, b, context) {
var res = a+b;
context.result = res;
};
var prod = function (a, b, context) {
var res = a*b;
context.result = res;
};
@telekosmos
telekosmos / gist:5388045
Created April 15, 2013 13:26
Private methods in a ExtJs4 class, using kind of Module Pattern. Do not abuse of this!!!
Ext.define('PrivateTest', (function () {
var privTest = function (param) {
return 'privTest method!!!';
};
var privTest2 = function (param) {
return 'another privTest2('+param+') method!!!';
};
return {
@telekosmos
telekosmos / Util.js
Created April 16, 2013 14:28
Recursive static methods in ExtJS 4
Ext.define('Util', {
config: {},
constructor: function () {},
/**
* Returns a string with the object properties and values. Could be static
* @param {Object} obj
@telekosmos
telekosmos / bad-statics.js
Last active December 16, 2015 08:08
A bad example on statics in ExtJS 4
Ext.define('My.Cat', {
statics: {
speciesName: 'Cat', // My.Cat.speciesName = 'Cat'
domestic: {
is: undefined
},
// Bad: this.self is undefined if called as My.Cat.dump();
dump: function () {
var domestic = this.self.domestic.is? 'domestic': 'wild';
@telekosmos
telekosmos / fullParallel.js
Created October 9, 2013 20:33
Asynchronous control flow in node.js
// FullParallel businessLogichronous engine
function fullParallel(callbacks, last) {
var results = [];
var result_count = 0;
callbacks.forEach(function(callback, index) {
callback( function() {
results[index] = Array.prototype.slice.call(arguments);
@telekosmos
telekosmos / modulepattern-prototype.js
Created April 3, 2014 09:03
Module pattern along with prototypal inheritance...
namespace('MINE');
MINE.parent = (function() {
// private funcs and vars here
// Public API - constructor
var Parent = function (coords) {
// ...do constructor stuff here
};
@telekosmos
telekosmos / prototypical-functional-inheritance.js
Created April 3, 2014 09:06
Combination of Functional/Prototypal Inheritance
var Animal = function () {
var helloCount = 0;
var self = this;
//priviledge methods
this.AnimalHello = function() {
helloCount++;
console.log(self.Name + ' says hello (animalHello)');
};