<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I'll code 4 Food &#187; codigo</title>
	<atom:link href="http://blog.illcode4food.com/tag/codigo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.illcode4food.com</link>
	<description>The Homeless Drunken Koder</description>
	<lastBuildDate>Fri, 06 Nov 2009 11:13:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Howto : Classpath en php5</title>
		<link>http://blog.illcode4food.com/2008/12/11/howto-classpath-en-php5/</link>
		<comments>http://blog.illcode4food.com/2008/12/11/howto-classpath-en-php5/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 14:51:07 +0000</pubDate>
		<dc:creator>Homeless Coder</dc:creator>
				<category><![CDATA[codigo]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.illcode4food.com/?p=207</guid>
		<description><![CDATA[Antes de empezar doy por supuesto que se tienen todos los conocimientos basicos de programacion en php y configuracion basica de servidor apache.
Una de las grandes carencias de php es tener que hacer un require o include continuamente para poder crear las clases, no hay nada parecido a un classpath como en java o python [...]]]></description>
			<content:encoded><![CDATA[<p>Antes de empezar doy por supuesto que se tienen todos los conocimientos basicos de programacion en php y configuracion basica de servidor apache.</p>
<p>Una de las grandes carencias de php es tener que hacer un require o include continuamente para poder crear las clases, no hay nada parecido a un classpath como en java o python o otros lenguajes <abbr title="Objec Oriented Programming">oop</abbr>.</p>
<p>Para solucionarlo se puede hacer a traves de un simple include en el archivo inicial para a partir de ese momento hacer todos los &#8220;new ClassName()&#8221; que queramos sin tener que recurrir a imports gracias a la funcion de <a title="Autoload en php.net" href="http://es.php.net/autoload" target="_blank">autoload</a> que nos permite importar clases automaticamente si se encuentra disponible.</p>
<p>Para empezar creamos una variable array con las rutas donde tenemos nuestras clases y la haremos accesible a cualquier parte con un define serializandolo con un string separado con comas, tal que asi</p>
<pre name="code" class="php">var $classfolders = Array(
  "/opt/php/modules/",
  "/opt/php/clases/"
);

define("CLASSPATH",implode($classfolders,","));</pre>
<p>Despues en el archivo del cual haremos include, tendremos la funcion autoload con un throw al final para controlar excepciones</p>
<pre name="code" class="php">function __autoload( $klass ){
 // ruta de los modulos a incluir, trailing slash
 $class_path = explode(",",CLASSPATH);
 foreach ( $class_path as $key => $path ) {
      	   if( file_exists( $file = $path.$klass.".php" ) ){
    		require_once $file;
    		return true;
    	   }
 }
 throw new Exception("La Clase $klass no se encuentra en el classpath");
}</pre>
<p>Una vez finalizado todo esto podremos importar las clases que tengamos en las correspondientes carpetas sin tener que importar el archivo, por lo tanto si tuvieramos la clase HelloTest.php en la carpeta &#8220;/opt/php/clases/&#8221; con el siguiente codigo :</p>
<pre name="code" class="php">class HelloTest {
      function __construct(){
            echo "Hola Mundo!";
      }
}</pre>
<p>Podemos hacer en el archivo &#8220;index.php&#8221; :</p>
<pre name="code" class="php">var $classfolders = Array(
          "/opt/php/modules/",
          "/opt/php/clases/"
);

define("CLASSPATH",implode($classfolders,","));

require_once('classpath.php');

$hello = new HelloTest();</pre>
<p>Nos saldria en el navegador :</p>
<p>Hola Mundo!</p>
<p>Y hasta aqui un ejemplo de como simular classpath en php para olvidarnos de los aburridos imports y requires en todos lados, solo hay q incluir el archivo classpath.php y tener definida la variable CLASSPATH explicado antes.</p>
<p>Hasta otra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.illcode4food.com/2008/12/11/howto-classpath-en-php5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QueryManager Class Submit</title>
		<link>http://blog.illcode4food.com/2007/11/08/querymanager-class-submit/</link>
		<comments>http://blog.illcode4food.com/2007/11/08/querymanager-class-submit/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 07:16:02 +0000</pubDate>
		<dc:creator>Homeless Coder</dc:creator>
				<category><![CDATA[codigo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://markcial.wordpress.com/2007/11/08/querymanager-class-submit/</guid>
		<description><![CDATA[Y aqui esta la mencionada clase QueryManager


class QueryManager {

&#160; private $_select = "SELECT %s FROM %s";
&#160; private $_where = " WHERE %s ";
&#160; private $_order = " ORDER BY %s ";
&#160; private $_limit = " LIMIT %s, %s ";

&#160; private $_insert = "INSERT INTO %s ";
&#160; private $_values = "( %s )VALUES( %s )";

&#160; private [...]]]></description>
			<content:encoded><![CDATA[<p>Y aqui esta la mencionada clase QueryManager</p>
<pre name="code" class="PHP">

class QueryManager {

&nbsp; private $_select = "SELECT %s FROM %s";
&nbsp; private $_where = " WHERE %s ";
&nbsp; private $_order = " ORDER BY %s ";
&nbsp; private $_limit = " LIMIT %s, %s ";

&nbsp; private $_insert = "INSERT INTO %s ";
&nbsp; private $_values = "( %s )VALUES( %s )";

&nbsp; private $_update = "UPDATE %s ";
&nbsp; private $_set = "SET %s ";

&nbsp; private $_delete = "DELETE FROM %s";

&nbsp; private $_sql_build = "";
&nbsp; private $_rsc;
&nbsp; private $_junk;
&nbsp; private $_data = array();
&nbsp; private $_pgn = array();
&nbsp; private $_page = 0;

&nbsp; public $table;
&nbsp; public $con;

&nbsp; function __construct($oCon, $sTable){
&nbsp;&nbsp;&nbsp; $this-&gt;table = $sTable;
&nbsp;&nbsp;&nbsp; $this-&gt;con = $oCon;
&nbsp; }

&nbsp; public function setPage($nPage){
&nbsp;&nbsp;&nbsp; $this-&gt;_page = $nPage;
&nbsp; }

&nbsp; public function getPage(){
&nbsp;&nbsp;&nbsp; return $this-&gt;_page;
&nbsp; }

&nbsp; public function length($sWhere="true"){
&nbsp;&nbsp;&nbsp; return mysql_query($this-&gt;buildCount( $sWhere ),$this-&gt;con) or die( mysql_error() );
&nbsp; }

&nbsp; public function getById($nId){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_rsc = mysql_query($this-&gt;buildSelect("id_$this-&gt;table=$nId"),$this-&gt;con) or die( mysql_error() );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_data = mysql_fetch_object($this-&gt;_rsc) or die( mysql_error() );
&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result($this-&gt;_rsc);
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_data;
&nbsp; }

&nbsp; public function getLast(){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_rsc = mysql_query($this-&gt;buildSelect("true", "id_$this-&gt;table desc", array(0,1)),$this-&gt;con) or die( mysql_error() );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_data = mysql_fetch_object($this-&gt;_rsc) or die( mysql_error() );
&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result($this-&gt;_rsc);
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_data;
&nbsp; }

&nbsp; public function select( $sWhere="true", $nPage=0, $nItemsPerPage=10, $sOrder=""){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_pgn["in"] = $nPage &gt; 0 ? ( $nPage * $nItemsPerPage + 1 ) : ( $nPage * $nItemsPerPage );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_pgn["out"] = $nItemsPerPage * ( $nPage + 1 );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_rsc = mysql_query( $this-&gt;buildSelect( $sWhere, $sOrder ), $this-&gt;con ) or die( mysql_error( ) );
&nbsp;&nbsp;&nbsp;&nbsp; while( $this-&gt;_junk = mysql_fetch_object( $this-&gt;_rsc ) ){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_data[] = $this-&gt;_junk;
&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result($this-&gt;_rsc);
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_data;
&nbsp; }

&nbsp; public function insert($aValues){
&nbsp;&nbsp;&nbsp;&nbsp; return mysql_query( $this-&gt;buildInsert( $aValues ),$this-&gt;con ) or die( mysql_error() );
&nbsp; }

&nbsp; public function update($nId,$aValues){
&nbsp;&nbsp;&nbsp;&nbsp; return mysql_query( $this-&gt;buildUpdate( $nId, $aValues ), $this-&gt;con ) or die( mysql_error() );
&nbsp; }

&nbsp; public function destroy($nId){
&nbsp;&nbsp;&nbsp;&nbsp; return mysql_query( $this-&gt;buildDelete( $nId ), $this-&gt;con ) or die( mysql_error() );
&nbsp; }

&nbsp; private function buildCount($sWhere){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build = sprintf($this-&gt;_select, "COUNT(*)", $this-&gt;table );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= sprintf($this-&gt;_where, $sWhere );
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_sql_build;
&nbsp; }

&nbsp; private function buildSelect($sWhere="true", $sOrder=""){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build = sprintf($this-&gt;_select, "*", $this-&gt;table );
&nbsp;&nbsp;&nbsp;&nbsp; if( !empty( $sWhere ) ){ $this-&gt;_sql_build .= sprintf($this-&gt;_where, $sWhere ); };
&nbsp;&nbsp;&nbsp;&nbsp; if( !empty( $sOrder ) ){ $this-&gt;_sql_build .= sprintf($this-&gt;_order, $sOrder ); };
&nbsp;&nbsp;&nbsp;&nbsp; if( !empty( $this-&gt;_pgn ) ){ $this-&gt;_sql_build .= sprintf($this-&gt;_limit, $this-&gt;_pgn["in"], $this-&gt;_pgn["out"] ); };
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_sql_build;
&nbsp; }

&nbsp; private function buildInsert( $aValues ){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build = sprintf($this-&gt;_insert, $this-&gt;table );
&nbsp;&nbsp;&nbsp;&nbsp; if(!empty( $aValues )){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sKeys = "";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sValues = "";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach( $aValues as $sKey=&gt;$sVal){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sKeys != "" ? $sKeys .= "," : false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sValues != "" ? $sValues .= "," : false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sKeys .= sprintf("%s", $sKey );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sValues .= sprintf("'%s'", $sVal );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= sprintf($this-&gt;_values, $sKeys, $sValues );
&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_sql_build;
&nbsp; }

&nbsp; private function buildUpdate( $nId, $aValues ){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build = sprintf($this-&gt;_update, $this-&gt;table );
&nbsp;&nbsp;&nbsp;&nbsp; if(!empty( $aValues )){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sSentence = "";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach( $aValues as $sKey=&gt;$sVal){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sSentence != "" ? $sSentence .= "," : false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sSentence .= sprintf( "%s='%s'", $sKey, $sVal );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= sprintf($this-&gt;_set, $sSentence );
&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= sprintf($this-&gt;_where, "id_$this-&gt;table=$nId" );
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_sql_build;
&nbsp; }

&nbsp; public function buildDelete($nId){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build = sprintf($this-&gt;_delete, $this-&gt;table );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= sprintf($this-&gt;_where, "id_$this-&gt;table=$nId" );
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_sql_build .= " LIMIT 1";
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_sql_build;
&nbsp; }

&nbsp; public function runQuery($sQuery){
&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_rsc = mysql_query( $sQuery ) or die( mysql_error() );
&nbsp;&nbsp;&nbsp;&nbsp; while( $this-&gt;_junk = mysql_fetch_object( $this-&gt;_rsc ) ){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;_data[] = $this-&gt;_junk;
&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result($this-&gt;_rsc);
&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;_data;
&nbsp; }
}
?&gt;
</pre>
<p>El tema de getById es si en la tabla se define el id asi : id_`nombre de la tabla`, si alguien quiere adaptarselo al gusto que toquetee.</p>
<p>Y ahora espero pedradas o algun consejo, hasta otra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.illcode4food.com/2007/11/08/querymanager-class-submit/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Snippet del dia, serie gratis</title>
		<link>http://blog.illcode4food.com/2007/10/03/snippet-del-dia-serie-gratis/</link>
		<comments>http://blog.illcode4food.com/2007/10/03/snippet-del-dia-serie-gratis/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 21:19:40 +0000</pubDate>
		<dc:creator>Homeless Coder</dc:creator>
				<category><![CDATA[aficiones]]></category>
		<category><![CDATA[anime]]></category>
		<category><![CDATA[codigo]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[fallo]]></category>
		<category><![CDATA[log]]></category>

		<guid isPermaLink="false">http://markcial.wordpress.com/2007/10/03/snippet-del-dia-serie-gratis/</guid>
		<description><![CDATA[Como hoy estaba aburrido y en GNU/Linux con el mplayer se ven tan bien los videos de la pagina de los chicos de stage6 me entretuve a hacer un snippet de codigo para dejar a ordenador descargando una serie a la que me estoy aficionando ultimamente porque es un completo sinsentido y una locura, Excel [...]]]></description>
			<content:encoded><![CDATA[<p>Como hoy estaba aburrido y en GNU/Linux con el mplayer se ven tan bien los videos de la pagina de los chicos de <a href="http://stage6.divx.com" target="_blank">stage6</a> me entretuve a hacer un snippet de codigo para dejar a ordenador descargando una serie a la que me estoy aficionando ultimamente porque es un completo sinsentido y una locura, <a href="http://es.wikipedia.org/wiki/Excel_Saga" target="_blank">Excel Saga</a>, si os veis capaces de usar un script de python para descargaros la serie ( falta el 17, no esta subido se ve ) aqui os dejo el codigo, si alguien ya sabe como usarlo y le interesa adelante y quien no sepa&#8230; <abbr title="Read The Fuckin' Manual">RTFM</abbr> -&gt; <a href="http://docs.python.org" target="_blank">aqui</a>.<br />
<span id="more-63"></span></p>
<pre name="code" class="python">

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os,sys,urllib

MAIN_URL = "http://video.stage6.com/"

data = [{"file":"1582866.divx","title":"Excel Saga - 01 - El plan para asesinar a Koshi Rikudo"},
{"file":"1586626.divx","title":"Excel Saga - 02 - La Chica que vino de Marte"},
{"file":"1600436.divx","title":"Excel Saga - 03 - Escapar del Infierno mortal"},
{"file":"1600824.divx","title":"Excel Saga - 04 - Amor extrano"},
{"file":"1607539.divx","title":"Excel Saga - 05 - La gigantesca torre gigante"},
{"file":"1607741.divx","title":"Excel Saga - 06 - Frio, es invierno. La historia"},
{"file":"1608393.divx","title":"Excel Saga - 07 - Desastre. Melodia subterranea"},
{"file":"1608732.divx","title":"Excel Saga - 08 - La semana"},
{"file":"1611500.divx","title":"Excel Saga - 09 - Escalada del grado del espectador"},
{"file":"1611927.divx","title":"Excel Saga - 10 - La gran aventura"},
{"file":"1620120.divx","title":"Excel Saga - 11 - Primavera de la Juventud"},
{"file":"1621998.divx","title":"Excel Saga - 12 - La gran parte de la Ciudad"},
{"file":"1626648.divx","title":"Excel Saga - 13 - Anos nuevos de competencia"},
{"file":"1629407.divx","title":"Excel Saga - 14 - Ocultar el talento"},
{"file":"1661295.divx","title":"Excel Saga - 16 - Amor otra vez"},
# falta el 17 {"file":".divx","title":""},
{"file":"1683714.divx","title":"Excel Saga - 18 - Fuerzas Municipales Daitenjin"},
{"file":"1684496.divx","title":"Excel Saga - 19 - La grandiosa aventura de Menchi 2"},
{"file":"1684863.divx","title":"Excel Saga - 20 - Lo mejor del senor Pedro"},
{"file":"1692034.divx","title":"Excel Saga - 21 - K Visual"},
]

for nd in data:
url = MAIN_URL+nd["file"].replace('.','/.')
name = nd["title"]+'.avi'
print "descargando archivo %s, desde %s, en carpeta %s"%(name,url,os.path.abspath(os.path.curdir))
urllib.urlretrieve(url, name)
</pre>
<p>Tambien dire que mientras me lo curraba a los de stage6 les dio un colapso en el servidor, cosa de que tienen mal alimentados los hamsters dicen estos chicos, esperemos que lo cuiden mas porque esta pagina la ve mucha gente. Aqui va un pantallazo<br />
<a title="Fallo en divx" href="http://blog.illcode4food.com/wp-content/uploads/2007/10/error_stage6divx.png"><img src="http://markcial.files.wordpress.com/2007/10/error_stage6divx.thumbnail.png" alt="Fallo en divx" /></a><br />
Buen, nus vemuz taotra \m/</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.illcode4food.com/2007/10/03/snippet-del-dia-serie-gratis/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
