Skip to content

Instantly share code, notes, and snippets.

View josedaniel's full-sized avatar
Building.

José Daniel Paternina josedaniel

Building.
View GitHub Profile
@josedaniel
josedaniel / gist:1677160
Created January 25, 2012 16:42
Loop + condition example [codeigniter]
<?php
//create the array in the controller and add it ot the $data array
//then, in the view...
foreach($elements as $element){
if($element->name == 'example'){
//do stuff
}
}
@josedaniel
josedaniel / localStorage.js
Created May 31, 2011 21:55
Local storage cookies fallback
if (!window.localStorage){
function createCookie(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=/";
}
@josedaniel
josedaniel / validate_email.js
Created May 3, 2011 19:09
Function to validate an email addres
//FUNCTION TO VALIDATE AN EMAIL ADDRESS
//USAGE: Ej:, validate_email(josedaniel.paterninasoto@gmail.com);
//This will return TRUE if the email is valid or FALSE if not.
function validate_email(email){
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return(true);
}else{
return(false);
@josedaniel
josedaniel / just_numbers.js
Created May 3, 2011 10:31
Avoid letters in number inputs
$(document).ready(function(){
//cuando se intenten meter letras en un campo de precio
$('.cantidad_producto').keypress(function(e){
if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){
return false;
}
});
});
@josedaniel
josedaniel / md5.js
Created May 2, 2011 14:21
Javascript MD5 Tool
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*