Skip to content

Instantly share code, notes, and snippets.

View tanrax's full-sized avatar

Andros Fenollosa tanrax

View GitHub Profile
@tanrax
tanrax / gist:8941620
Created February 11, 2014 18:59
JQuery: Arreglar imágenes sin terminar de cargar
$('img').error(function(){
$(this).attr('src', 'img/broken.png');
});
@tanrax
tanrax / gist:8941631
Created February 11, 2014 19:00
JQuery: Intercambiar clases efecto hover
$('.btn').hover(function(){
$(this).addClass('hover');
}, function(){
$(this).removeClass('hover');
});
@tanrax
tanrax / gist:8941648
Created February 11, 2014 19:00
JQuery: Deshabilitar campos de entrada (formularios)
// para deshabilitar un campo, en este caso un botón para enviar
$('input[type="submit"]').attr("disabled", true);
// para volver a habilitar el botón
$('input[type="submit"]').removeAttr('disabled');
@tanrax
tanrax / gist:8972076
Created February 13, 2014 09:10
PHP: Consulta MySQL (SQL)
<?php
/* Conexion */
$conexion = mysql_connect('localhost', 'root', '');
mysql_select_db('nombreBBDD', $conexion);
/* Consulta */
$sSQL = "SELECT * FROM";
$resultados = mysql_query($sSQL, $conexion) or die(mysql_error());
@tanrax
tanrax / gist:8973112
Created February 13, 2014 10:51
PHP: Convertir valor en variable (texto en variable)
<?php
$sHola = 'texto';
$sVariable = 'sHola';
echo $$sVariable;
?>
@tanrax
tanrax / gist:9141515
Created February 21, 2014 19:25
CSS: Tabulación
.tabulacion:first-letter {
margin-left: 15px;
}
@tanrax
tanrax / gist:9279571
Created February 28, 2014 20:47
JS: Canvas image (imagen)
var c = document.getElementById("lienzo");
var ctx = c.getContext("2d");
var imageObj = new Image();
imageObj.src = 'img_the_scream.jpg';
imageObj.onload = function() {
ctx.drawImage(imageObj, 69, 50);
};
@tanrax
tanrax / gist:9544289
Created March 14, 2014 08:52
AJAX: Envío de datos (Enviar por GET)
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Ejemplo de formulario con AJAX</title>
<style>
body {
font-size: 14px;
text-align: center;
}
@tanrax
tanrax / BD.class.php
Created March 18, 2014 11:41
PHP POO: Clase base de datos (Class object SQL)
<?php
/**
* Clase para utilizar la base de datos
* 1.1v
*/
class DB {
//Variables
public static $DB_HOST = 'localhost';
@tanrax
tanrax / gist:9681952
Created March 21, 2014 08:27
JQuery: Scroll suave (mover lento)
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;