Skip to content

Instantly share code, notes, and snippets.

View mrroot5's full-sized avatar
🏠
Working from home

Adrián mrroot5

🏠
Working from home
View GitHub Profile
@mrroot5
mrroot5 / example
Last active August 29, 2015 14:22
Imprimimos código HTML visible desde la web, evitando que las entidades HTML actúen como tal.
http://jsfiddle.net/odxg8tfu/
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uuid;
}
@mrroot5
mrroot5 / index.html
Last active August 29, 2015 14:24
Previsualizar imagen input file. FROM: http://jsfiddle.net/LvsYc/
<form id="my_form">
<input type="file" id="img-input-file">
<img id="#img-input-file-preview" src="#" alt="imagen" />
</form>
@mrroot5
mrroot5 / humanize.js
Created July 30, 2015 11:08
Humanize
String.prototype.humanize = function (str) {
return str.replace(/\w\S*/g, function (txt) {return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
};
@mrroot5
mrroot5 / vimeoId.php
Created August 21, 2015 08:01
Obtener el id de vimeo con https opcional. FROM: https://gist.github.com/erknrio/97a62bfbe5d2f77158c3
<?php
function vimeoID($url) {
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $url, $id)) {
return "<strong>".$id[3]."</strong>";
} else {
return "<strong class='error'>error</strong>";
}
}
$vimeo = array(
$url_list = array("http://www.miwebchula.com,",
"http://blabla.miwebchula.com",
"http://blabla.miweb-chula.com",
"http://www.miwebchula.com/param1/param2",
"http://www.miwebchula.com/param1/param2/",
"http://www.miwebchula.com/?var1=value1",
"http://www.miwebchula.com/?var1=value1",
"http://www.miwebchula.com/param1/param2?var1=value1",
"http://www.miwebchula.com/param1/param2?var1=val1&var2=val2",
"http://www.miwebchula.com.es",
@mrroot5
mrroot5 / random_string.js
Last active September 15, 2015 16:42
Generar cadena aleatoria. Generar string aleatorio.
// Random entre 1 y 10
var randomString = ((Math.random() * 10) +1).toString(32);
@mrroot5
mrroot5 / multiple_string.js
Created September 16, 2015 18:11
Javascript multiline string con variables
var foo = 'foo',
bar = 'bar',
string = `Mi string \
contiene multiples lineas '${foo}' \
cada una de ellas: "${bar}" es importante`;
window.console.log(string);
@mrroot5
mrroot5 / is_assoc.php
Created September 24, 2015 16:39
Comprueba si el array es asociativo
function is_assoc($array = array())
{
if (!is_array($array) || empty($array)) {
return FALSE;
} else {
return (bool)count(array_filter(array_keys($array), 'is_string'));
}
}
// pos: Inserta despues de esta posicion
// preserve: boolean, indica si quieres conservar las claves del array
function insertNewElement($array, $element, $pos, $preserve) {
try {
if (empty($array) || empty($element)) {
throw new Exception('Faltan Datos', 1);
} else {
$pos = (isset($pos)) ? $pos : 1;
$preserve = (empty($preserve)) ? FALSE : $preserve;