Apr 15 2010

The God Delusion

Published by Jose Hidalgo under Books, Religion

The God Delusion The God Delusion by Richard Dawkins


My rating: 5 of 5 stars
It’s the best consciousness raiser

View all my reviews >>

One response so far

Mar 29 2010

Zend Framework: /public folder redirect

Published by Jose Hidalgo under Programming, php

If you use the Zend Framework everything is going to work just fine until you have to upload the application, then you realize that your hosting facility is not going to change the Document Root inside apache’s config.

That’s when you have to use the .htaccess to circumvent this situation. Here is one of many possible solutions that works for me:

# Turn On the engine
RewriteEngine on

# Change yourdomain.com to be your main domain, No Case sensitive
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ [NC]

#we are redirecting what doesn't have the /public already
RewriteCond %{REQUEST_URI} !^/public/

#if its a file or directory that exists, then just hit it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#save the url and redirect to it with the '/public' at the begging
RewriteRule ^(.*)$ /public/$1 [L]

#finally if the request goes to the base, show the /public/index
RewriteCond %{HTTP_HOST} ^(www.)?innova.joseche.com$ [NC]
RewriteRule ^(/)?$ public/index.php [L]

No responses yet

Jan 25 2010

Provincias y Cantones de Costa Rica en dos toques(tablas)

Published by Jose Hidalgo under Costa Rica, Programming, html

Para los programadores de mi linda Costa Rica. Uno de pronto ocupa el listado de Cantones y Provincias para guardar direcciones, así que si les sirve de algo, algunas funciones y obviamente la lista de Cantones por Provincia.

Uso MySQL por que es el estándar de la red

CREATE TABLE `provincias` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nombre` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

Ahora para llenar las provincias es muy sencillo:

INSERT INTO `provincias` VALUES (1,'San Jose'),(2,'Alajuela'),(3,'Cartago'),(4,'Heredia'),(5,'Guanacaste'),(6,'Puntarenas'),(7,'Limon');

Ahora para los cantones, primero crear una tabla básica:

CREATE TABLE `canton` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `provincia_id` int(10) unsigned NOT NULL,
  `nombre` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=88 DEFAULT CHARSET=latin1;

Y ahora la data:

INSERT INTO `canton` (`provincia_id`, `nombre`) VALUES (1,'San José'),(1,'Escazú'),(1,'Desamparados'),(1,'Puriscal'),(1,'Tarrazú'),(1,'Aserrí'),(1,'Mora'),(1,'Goicoechea'),(1,'Santa Ana'),(1,'Alajuelita'),(1,'V´zquez de Coronado'),(1,'Acosta'),(1,'Tibás'),(1,'Moravia'),(1,'Montes de Oca'),(1,'Turrubares'),(1,'Dota'),(1,'Curridabat'),(1,'Pérez Zeledón'),(1,'León Cortés'),(2,'Alajuela'),(2,'San Ramón'),(2,'Grecia'),(2,'San Mateo'),(2,'Atenas'),(2,'Naranjo'),(2,'Palmares'),(2,'Poás'),(2,'Orotina'),(2,'San Carlos'),(2,'Alfaro Ruíz'),(2,'Valverde Vega'),(2,'Upala'),(2,'Los Chiles'),(2,'Guatuso'),(3,'Cartago'),(3,'Paraíso'),(3,'La Union'),(3,'Jiménez'),(3,'Turrialba'),(3,'Alvarado'),(3,'Oreamuno'),(3,'El Guarco'),(4,'Heredia'),(4,'Barva'),(4,'Santo Domingo'),(4,'Santa Bárbara'),(4,'San Rafael'),(4,'San Isidro'),(4,'Belén'),(4,'Flores'),(4,'San Pablo'),(4,'Sarapiquí'),(5,'Liberia'),(5,'Nicoya'),(5,'Santa Cruz'),(5,'Bagaces'),(5,'Carrillo'),(5,'Cañas'),(5,'Abangares'),(5,'Tilarán'),(5,'Nandayure'),(5,'La Cruz'),(5,'Hojancha'),(6,'Puntarenas'),(6,'Esparza'),(6,'Buenos Aires'),(6,'Montes de Oro'),(6,'Osa'),(6,'Aguirre'),(6,'Golfito'),(6,'Coto Brus'),(6,'Parrita'),(6,'Corredores'),(6,'Garabito'),(7,'Limón'),(7,'Pococí'),(7,'Siquirres'),(7,'Talamanca'),(7,'Matina'),(7,'Guácimo');

Listo !,
Ahora usted puede hacer una consulta como la siguiente:

SELECT p.nombre,c.nombre FROM provincias p, canton c
WHERE p.id=c.provincia_id
ORDER BY p.id,c.id;

Ojala les sea de utilidad

No responses yet

Dec 29 2009

Javascript print_r

Published by Jose Hidalgo under Programming, javascript

This is my own javascript version of the PHP’s print_r function, which is used to print the properties of an object with its values.

Download

This is the function, and below you can find the explanation.

    function print_r(obj, tab, depth){

        var ignorezero= true;
        var ignorefunction= true;
        var ignorenull= true;
        var ignoremaxreached = true;

        var output = tab + obj + ":\n";
        try {
            tab += " - ";
            for (var childname in obj){

                var func= 0;
                childval= obj[childname];

                if (childval==null){
                   if (ignorenull) continue;
                   else childstr= "null";
                }else if ((childval==0 || childval=="") && ignorezero )
                   continue;
                else
                   childstr= childval.toString();

                if (childstr.length>8)
                   if (childstr.substring(0,8)=="function")
                      func= 1;

                if (func){
                   if (!ignorefunction)
                       output += tab + childname +": function\n";
                }else if (typeof childval=="object"){
                   if (childval != null){
                      if (depth==0)
                         output += tab + childname + ": " +childstr + "\n";
                      else
                         output += tab + childname +": "+print_r(childval,tab,depth-1)+"\n";
                   }else if(!ignorenull)
                      output += tab + childname +": null\n";
                }else{
                   output += tab + childname +": "+ childstr + "\n";
                }
            }
        }catch(exc){
        }
        return output;
    }

So here it goes slowly:

function print_r(obj, tab, depth){
  • obj: This is the object, array, variable you want to print, examples: document.form, ajaxresponse, etc…
  • tab: most of the times it will be: “”, it’s just the tab spacing you want to use
  • depth: how many levels it should dig, for example, if you want to print “document”, it can go to: document.form.input.value which will be the 4th level
        var ignorezero= true;
        var ignorefunction= true;
        var ignorenull= true;
        var ignoremaxreached = true;

These are some control variables you can customize depending on how much information you want to have.

  • ignorezero: if the value of a property is “” or 0 don’t print it
  • ignorefunction: do not print methods
  • ignorenull: if the property is another object equals to null, do not print it
  • ignoremaxreached: once the max depth has been reached and an object is found, ignore it
var output = tab + obj + ":\n";
try {
            tab += " - ";

output is the variable used to store the properties, we use tab for spacing and in this case the toString() method of the obj.

Once we saved the name of the object we need to indent the properties, that’s why we use the tab variable.

            for (var childname in obj){

                var func= 0;
                childval= obj[childname];

This is just the loop thru the properties of the object. func is another control variable to know childname is a method (function) or not. childval is the actual property.

                if (childval==null){
                   if (ignorenull) continue;
                   else childstr= "null";
                }else if ((childval==0 || childval=="") && ignorezero )
                   continue;
                else
                   childstr= childval.toString();

Ignore basic cases, and store the string value of the property.

                if (childstr.length>8)
                   if (childstr.substring(0,8)=="function")
                      func= 1;

               if (func){
                   if (!ignorefunction)
                       output += tab + childname +": function\n";
                }

This is the way I know if a property is a method, if you have something better just let me know.

else if (typeof childval=="object"){
                   if (childval != null){
                      if (depth==0)
                         output += tab + childname + ": " +childstr + "\n";
                      else
                         output += tab + childname +": "+print_r(childval,tab,depth-1)+"\n";
                   }else if(!ignorenull)
                      output += tab + childname +": null\n";
                }

If the property is another object ask if see if we loop into it or just print it’s name. Also ignore if it is null.

else{
                   output += tab + childname +": "+ childstr + "\n";
                }
            }
        }catch(exc){
        }
        return output;
    }

If the property is not an object or a function just print it.
Exception are ignored, and just return the output.

No responses yet

Dec 28 2009

(X)HTML templates

Published by Jose Hidalgo under Programming

These are the templates I use that may become handy for other people, hope it helps !

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="stylesheet" type="text/css" href="css/style.css"></script>
      <title></title>
    </head>
    <body>

    </body>
</html>

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="css/style.css"></script>
        <title></title>
    </head>
    <body>

    </body>
</html>

HTML 4.01 Strict

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <link rel="stylesheet" type="text/css" href="css/style.css"></script>
   <title></title>
 </head>
 <body>

 </body>
</html>

HTML 4.01 Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css"></script>
        <title></title>
    </head>
    <body>

    </body>
</html>

One response so far

Older Entries »