Skip to content

Instantly share code, notes, and snippets.

Avatar
🦝
Working at Checkly

Nacho Anaya ianaya89

🦝
Working at Checkly
View GitHub Profile
View IE8IndexOf.js
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
@ianaya89
ianaya89 / isNative.js
Created Aug 26, 2014
Detect if a function is native.
View isNative.js
;(function() {
// Used to resolve the internal `[[Class]]` of values
var toString = Object.prototype.toString;
// Used to resolve the decompiled source of functions
var fnToString = Function.prototype.toString;
// Used to detect host constructors (Safari > 4; really typed array specific)
var reHostCtor = /^\[object .+?Constructor\]$/;
@ianaya89
ianaya89 / debugger.js
Last active Aug 29, 2015
CSS Layout Debugger
View debugger.js
//Using jquery
[].forEach.call(document.querySelectorAll("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
//Full CSS Layout Debugger Tool
http://pesticide.io/
@ianaya89
ianaya89 / module.js
Last active Aug 29, 2015
Universal Module Definition (UMD)
View module.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['b'], factory); //AMD
} else if (typeof exports === 'object') {
module.exports = factory; //CommonJS
} else {
root.amdWeb = factory(root.b); //Global
}
}(this, function (b) {
return {}; //Module
@ianaya89
ianaya89 / format.js
Created Nov 26, 2014
String.format() method.
View format.js
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
@ianaya89
ianaya89 / gulp.sh
Created Dec 1, 2014
Using gulp as web server
View gulp.sh
npm install gulp -g && npm install --save-dev gulp-connect
@ianaya89
ianaya89 / .bash_profile
Last active Oct 20, 2017
Custom Setting for Mac Terminal
View .bash_profile
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
# Showing Git Branch.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
@ianaya89
ianaya89 / server.js
Created Dec 4, 2014
Using Command Line Arguments in Node
View server.js
//Simple commands: type in console server -f/-g
var units = process.argv[2];
if(units == '-f'){
this.setUnits('Fahrenheit');
} else {
this.setUnits('Celsius');
}
//Flag and Argument Pairs: type in console node -c Tampa,FL
@ianaya89
ianaya89 / little.js
Created Dec 10, 2014
Douglas Crockford JS version of the The Little LISPer.
View little.js
// The Little JavaScripter
// http://www.crockford.com/javascript/little.js
// Copyright 2003 Douglas Crockford. All rights reserved wrrrld wide.
// May 4, 2011
// Produce a printable presentation of an s-expression
function p(x) {
View patterns.js
var Patterns = {
INT: /[0-9 -()+]+$/,
FLOAT: /[-+]?([0-9]*.[0-9]+|[0-9]+)/,
EMAIL: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/,
IP: /bd{1,3}.d{1,3}.d{1,3}.d{1,3}b/,
CREDIT_CARD: /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35d{3})d{11})$/,
USER_NAME: /^[a-z0-9_-]{3,16}$/,
PASSWORD: /^[a-z0-9_-]{6,18}$/,
PASSWORD_STRENGTH: /((?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,15})/gm,