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 / 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 / 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 / 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.');
});
@amatiasq
amatiasq / analyzer.js
Last active December 31, 2015 03:59
Dirty code than recursively analyzes a object for a specific string without using recursive functions because of call stack limit.
function find(term, obj, name) {
var key = '!"·$% &/()';
var visited = Date.now() + Math.random();
var _current = [{}];
var _keys = [[name || 'your_object']];
var _index = [0];
var results = [];
var current = obj;
var keys = Object.keys(obj)
@amatiasq
amatiasq / request-to-curl.js
Last active December 31, 2015 15:09
A node script than opens a server and creates a bash script per each request, containing the curl command to replicate the request it received.
#!/usr/bin/env node
//jshint node:true
'use strict';
var fs = require('fs');
var url = require('url');
var http = require('http');
var port = process.argv[2];
var folder = process.argv[3];