Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
jgarciaruiz / index.html
Created February 29, 2016 17:05
js fallback if CND fails to load
<!-- load script from CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<!-- if fails, fallback a local version -->
<script>window.angular || document.write('<script src="js/angular.min.js"><\/script>');</script>
@jgarciaruiz
jgarciaruiz / url-param.js
Created March 1, 2016 10:13
Read URL parameters via js
function $_GET(param) {
var vars = {};
window.location.href.replace( location.hash, '' ).replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback
vars[key] = value !== undefined ? value : '';
}
);
@jgarciaruiz
jgarciaruiz / update-or-add-url-params.js
Created March 1, 2016 18:04
Changing URL parameters with jQuery
var queryParameters = {}, queryString = location.search.substring(1),
re = /([^&=]+)=([^&]*)/g, m;
// Creates a map with the query string parameters
while (m = re.exec(queryString)) {
queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
// Usage: Add new parameters or update existing ones
queryParameters['user_language'] = 'en';
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
<?php
function sanitize_input($the_data){
$the_data = stripslashes($the_data);
$the_data = strip_tags($the_data);
$the_data = htmlspecialchars($the_data);
$the_data = mysqli_real_escape_string($the_data);
$the_data = utf8_decode($the_data);
return $the_data;
}
?>
@jgarciaruiz
jgarciaruiz / index.html
Created June 12, 2016 15:57
HTML5 skeleton
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Skeleton</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<script src="js/main.js"></script>
@jgarciaruiz
jgarciaruiz / days2ms.js
Created June 13, 2016 12:15
modify datepicker params dynamically
$(function () {
$("#myfield").datepicker("destroy");
var newMinDate = new Date( +new Date + days2ms(2) );
$('#myfield').datepicker({
minDate: newMinDate
});
});
function validarCP(cp){
var regexp = /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/;
return regexp.test(cp);
}
function validarEmail(mail) {
var regexp = /^[0-9a-z_\-\.]+@[0-9a-z\-\.]+\.[a-z]{2,4}$/i;
return regexp.test(mail);
}
function validarMovil(tlf) {
var regexp = /6\d{8}/;
<?php
$protocol = empty($_GET['ssl']) ? 'http' : 'https';
header("Location: " . $protocol . "://site.com");
exit;
?>
@jgarciaruiz
jgarciaruiz / wp_custom_table_loop.php
Created July 8, 2016 08:19
WP custom table loop snippet
<?php
global $wpdb;
$postid = $wp_query->post->ID;
$id_video = $postid;
$query_tabla_videos = "SELECT * FROM videos WHERE id_video = '$id_video'";
$results = $wpdb->get_results($query_tabla_videos);
foreach ($results as $row) {
$v_id_cat = $row->id_cat;
$v_fecha = $row->fecha;