This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getAge($birth){ | |
$t = time(); | |
$age = ($birth < 0) ? ( $t ($birth * -1) ) : $t - $birth; | |
return floor($age/31536000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple image proxy for Nodejs | |
* @param {Express} app Express app | |
* @return {function} | |
*/ | |
var http = require('http'), | |
url = require('url'); | |
module.exports = function (app) { | |
app.get('/proxy/:image', function (request_from_client, response_to_client) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculate the elapsed time between two timestamps | |
* and display in a pretty human way. | |
* @param integer $start Initial timestamp | |
* @param integer $end Final timestamp, set to -1 for current time. | |
* @return string Formatted elapsed time. | |
*/ | |
function timeBetween($start, $end=-1){ | |
if($end < 0) $end = time(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_time="$(date +%s)" | |
# Antigen — A zsh plugin manager | |
export ANTIGEN_DEFAULT_REPO_URL=https://github.com/sharat87/oh-my-zsh.git | |
source ~/antigen.zsh | |
# Load the oh-my-zsh's library. | |
antigen use oh-my-zsh | |
# Bundles from the default repo declared above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check if url includes #/ | |
if(window.location.hash.length < 1 || window.location.hash == ''){ | |
window.location = window.location.origin + window.location.pathname + '#/' + window.location.search; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('serviceName', []) | |
.factory('resourceName', ['$resource', | |
function($resource) { | |
var status = $resource('/endpoint'); | |
return status.get().$promise; | |
} | |
]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('aurbano.draggable', []) | |
.directive('draggable', ['$document', function($document) { | |
return { | |
scope: { | |
config: '=draggable' | |
}, | |
link: function(scope, element, attr) { | |
var dragElement = element; | |
if(scope.config.target){ | |
if(scope.config.target === 'parent'){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function htmlEncode(value){ | |
// Create a in-memory div, set it's inner text(which jQuery automatically encodes) | |
// then grab the encoded contents back out. The div never exists on the page. | |
return $('<div/>').text(value).html(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove all specified keys from an object, no matter how deep they are. | |
* The removal is done in place, so run it on a copy if you don't want to modify the original object. | |
* This function has no limit so circular objects will probably crash the browser | |
* | |
* @param obj The object from where you want to remove the keys | |
* @param keys An array of property names (strings) to remove | |
*/ | |
function removeKeys(obj, keys){ | |
var index; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given an array of objects that have an Id, return an array where the Id is the key | |
* @param arr Array to normalize | |
* @param key [Optional] Object key to use, defaults to Id | |
* @returns {Array} Normalized array | |
*/ | |
function normalizeArrayId(arr, key){ | |
var total = arr.length, | |
index = key || 'Id', | |
ret = []; |