Skip to content

Instantly share code, notes, and snippets.

Avatar

A. Matías Quezada amatiasq

View GitHub Profile
@amatiasq
amatiasq / 1_README.md
Last active Aug 29, 2015
Safe extension for native javascript objects
View 1_README.md

A simple function to extend native object

void extendNative(Function constructor, optional String property, Object methods);

In order to prevent collisions with future standard all extensions are added under a specific property ($ by default), this is configurable by the optional second argument:

extendNative(String, {
  someExtension: function() { }
});

'my string'.$.someExtension();

View http-request.js
(function(global) {
'use strict';
function chain(obj, method) {
var original = obj[method];
obj[method] = function() {
original.apply(this, arguments);
return this;
};
}
View listenDom.js
function listenAll(target) {
var protos = [],
proto = target;
while (proto) {
protos.push(proto);
proto = Object.getPrototypeOf(proto)
}
protos
View Deferred.js
(function() {
function Deferred() {
if (window.Promise) {
var that = this;
this.promise = new Promise(function(resolve, reject) {
that._resolve = resolve;
that._reject = reject;
});
}
@amatiasq
amatiasq / search.js
Last active Aug 29, 2015
Parse URL search section ('?foo=123&bar=stuff')
View search.js
function getSearch() {
return window.location.search
.substr(1) // remove the '?'
.split('&')
.map(function(entry) {
return entry
.split('=')
.map(decodeURIComponent);
});
}
View gist:5358554750a63891811a
1 """adding display_networktab column to blog
2
3 Revision ID: 43dd765b5380
4 Revises: 4b76556140fb
5 Create Date: 2014-12-09 17:54:39.803860
6
7 """
8
9 # revision identifiers, used by Alembic.
10 revision = '43dd765b5380'
View gist:be8c238f6470c3872187
[app:api]
use = egg:thefc
pyramid.debug = true
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = true
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_tm
@amatiasq
amatiasq / jshintrc.js
Last active Aug 29, 2015
All JSHint options
View jshintrc.js
// jshint maxlen:false
{
// Enforcing
"bitwise": true, // Prohibits the use of bitwise operators such as ^ (XOR), | (OR) and others.
"camelcase": true, // Allows you to force all variable names to use either camelCase style or UPPER_CASE with underscores.
"curly": false, // Requires you to always put curly braces around blocks in loops and conditionals.
"enforceall": false, // Is a short hand for the most strict JSHint configuration.
"eqeqeq": true, // This options prohibits the use of == and != in favor of === and !==.
"es3": false, // Tells JSHint that your code needs to adhere to ECMAScript 3 specification.
@amatiasq
amatiasq / funct.js
Created Jan 20, 2015
Wrap functions to support promises as arguments
View funct.js
// $q comes from angular
function wrapFunct(fn) {
return function() {
var context = this;
var args = [].slice.call(arguments);
var resolved = $q.all(args.map($q.when));
return resolved.then(function(values) {
return fn.apply(context, values);
View split-name.js
// Calculates the space closest to the middle of the name
function splitName(name) {
var middle = name.length / 2;
var spaces = [];
var last = name.indexOf(' ');
while(last !== -1) {
spaces.push(last);
last = name.indexOf(' ', last + 1)
}