Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
(function(number){
console.log(number); // 2
number = 1;
console.log(arguments[0]); // 1
}(2));
(function(number){
"use strict";
console.log(number); // 2
number = 1;
@alejandrolechuga
alejandrolechuga / ObjectPropertiesChecker.js
Created March 23, 2011 00:41
Object Property Checker
//Just in case is not supported or not included by your framework
//***************************************************
Array.prototype.some = function(fn, thisObj) {
var scope = thisObj || window;
for ( var i=0, j=this.length; i < j; ++i ) {
if ( fn.call(scope, this[i], i, this) ) {
return true;
}
}
return false;
<?php
if ($_GET['key'] == $_SESSION['hash_key']) {
//has key validation passed
}
?>
function convertir($fecha) {
$months = array();
$months [] = "Enero";
$months [] = "Febrero";
$months [] = "Marzo";
$months [] = "Abril";
$months [] = "Mayo";
$months [] = "Junio";
$months [] = "Julio";
$months [] = "Agosto";
@alejandrolechuga
alejandrolechuga / functionRegExp.js
Last active October 13, 2015 20:47
Gets the function argument names in an Array
function injector (objects) {
function functionArgsName(fn) {
var fragment;
fn = fn.toString();
//remove comments
fn = fn.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm,"");
fragment = fn.match(/function\s*\w*\s*\((.*?)\)/)[1];
if (!/^[\s]*$/g.test(fragment)) {
return fragment.replace(/(\s)/g,"").split(",");
@alejandrolechuga
alejandrolechuga / observable1.js
Last active July 22, 2016 14:56
Observables with RxJS
var Observable = Rx.Observable;
var button = document.getElementById('button');
var clicks = Observable.fromEvent(button, 'click');
clicks.forEach(function( ){
console.log('click')
});
// dispose
var Observable = Rx.Observable;
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
@alejandrolechuga
alejandrolechuga / high-order-functions.js
Created February 19, 2017 05:53
Functional Programming
// Notes from funfunfunction videos
/*
Functional programming
According to the video FP should improve your code, less time and more understandable, in javascript functions are values
*/
// functions can be assigned to variables
var triple = function (x) {
return x * 3;
}
var waffle = triple;
// mutators
// push , pop, shift, unshift
var array = [];
/
function memoria(limit) {
var array = [];
return function (element) {
var isSet = arguments.length >= 1;
if (isSet) {
array.push(element)
@alejandrolechuga
alejandrolechuga / oauth.js
Created November 18, 2016 15:24 — forked from keiver/oauth.js
Get Authentication header with OAuth using oauth-1.0a and crypto-js
import OAuth from 'oauth-1.0a';
import CryptoJS from 'crypto-js';
/**
* oAuthHeader - Get Authentication header with OAuth.
*
* @param {string} url Request URL
* @param {string} method HTTP method.
* @return {object} Authentication header object
*/