<?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>Historias de un Geek &#187; Programacion</title>
	<atom:link href="http://albertein.com.mx/archives/tag/programacion/feed" rel="self" type="application/rss+xml" />
	<link>http://albertein.com.mx</link>
	<description>AlbertEin - Desvarios de una mente perturbada</description>
	<lastBuildDate>Wed, 28 Apr 2010 15:51:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Desarrollando Webs Dinamicas</title>
		<link>http://albertein.com.mx/archives/795</link>
		<comments>http://albertein.com.mx/archives/795#comments</comments>
		<pubDate>Mon, 26 Apr 2010 15:45:32 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Eventos]]></category>
		<category><![CDATA[flisol]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://albertein.com.mx/?p=795</guid>
		<description><![CDATA[Aquí les dejo la liga al material de lo que se vio en el demotaller &#8220;Desarrollando Webs Dinámicas (con HTML y jQuery)&#8221;. Y aprovecho parea dejarles liga a las fotos del FLISol. Saludos!. Desarrollando Webs Dinámicas (con HTML y jQuery) Fotos del FLISol Sinaloa 2010]]></description>
			<content:encoded><![CDATA[<p>Aquí les dejo la liga al material de lo que se vio en el <em>demotaller</em> <strong>&#8220;Desarrollando Webs Dinámicas (con HTML y jQuery)&#8221;</strong>. Y aprovecho parea dejarles liga a las fotos del FLISol.</p>
<p>Saludos!.</p>
<p><a href="http://albertein.com.mx/talks/dynamicweb/" target="_blank">Desarrollando Webs Dinámicas (con HTML y jQuery)</a><br />
<a href="http://picasaweb.google.com/openenterprisesolutions" target="_blank">Fotos del FLISol Sinaloa 2010</a></p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/795/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hágalo usted mismo: Integrando Twitter @Anywhere en WordPress, ¡a la mala!</title>
		<link>http://albertein.com.mx/archives/783</link>
		<comments>http://albertein.com.mx/archives/783#comments</comments>
		<pubDate>Sat, 17 Apr 2010 16:51:48 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[@anywhere]]></category>
		<category><![CDATA[hagalo usted mismo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://albertein.com.mx/?p=783</guid>
		<description><![CDATA[Hace algunos días Twitter presento su nueva API @Anywhere, y justo ayer @Robsainz me pidió que lo implementara en su Web. Fruto de eso les tengo esta mini guía para implementar @Anywhere en su blog de WordPress, aun que fácilmente puede ser adaptado para demás sitios. Cabe señalar que esta es una manera &#8220;rudimentaria&#8221; de [...]]]></description>
			<content:encoded><![CDATA[<p>Hace algunos días Twitter presento su nueva API @Anywhere, y justo ayer @Robsainz me pidió que lo implementara en su <a href="http://langaria.net" target="_blank">Web</a>.</p>
<p>Fruto de eso les tengo esta mini guía para implementar @Anywhere en su blog de WordPress, aun que fácilmente puede ser adaptado para demás sitios. Cabe señalar que esta es una manera &#8220;rudimentaria&#8221; de lograrlo con mucho espíritu &#8220;hágalo usted mismo&#8221;, modificando tu Template actual. La mejor forma de hacerlo sería con un plugin, pero debido a lo reciente de la API de momento no se encuentra ninguno estable y configurable disponible.</p>
<p>Primero se debe de registrar su aplicación (o en este caso web) en http://dev.twitter.com/apps/new para optener su API key. Despues de hacerlo no olviden seguir los pasos que están en : <a href="http://groups.google.com/group/twitter-development-talk/browse_thread/thread/5c96366e2362fe85#">http://groups.google.com/group/twitter-development-talk/browse_thread/thread/5c96366e2362fe85#</a></p>
<ol>
<li> Go to: http://twitter.com/oauth</li>
<li> Click on your application</li>
<li> On the &#8220;Application Details&#8221; page click the &#8220;Edit Application<br />
Settings&#8221; button</li>
<li> On the settings page for your application, scroll down to the item<br />
labeled &#8220;Default Access type&#8221;</li>
<li> Change the &#8220;Default Access type&#8221; to &#8220;Read &#038; Write&#8221; </li>
</ol>
<p>Después necesitan editar el archivo <em>header.php</em> del tema que estén usando, justo sobre el tag <em>&lt;/head&gt;</em> deben de poner el siguiente código (reemplazando AQUIVATUAPIKEY por tu api key Y AQUIVATUTWITTERUSER por tu usuario de twitter):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script src=&quot;http://platform.twitter.com/anywhere.js?id=AQUIVATUAPIKEY&amp;v=1&quot;&gt;
&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        twttr.<span style="color: #660066;">anywhere</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>twitter<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            twitter.<span style="color: #660066;">hovercards</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            twitter<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#twitt-box&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tweetBox</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>
                counter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                height<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
                width<span style="color: #339933;">:</span> <span style="color: #CC0000;">250</span><span style="color: #339933;">,</span>
                label<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Twittea desde aqui&quot;</span><span style="color: #339933;">,</span>
                defaultContent<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Estoy probando @Anywhere en mi blog&quot;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            twitter<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#follow-me&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">followButton</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;AQUIVATUTWITTERUSER&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Y después solo falta que crees un Widget que contenga lo siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;">&lt;div id=&quot;follow-me&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;twitt-box&quot;&gt;&lt;/div&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/783/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hagalo usted mismo: Efecto marquesina con Javascript</title>
		<link>http://albertein.com.mx/archives/611</link>
		<comments>http://albertein.com.mx/archives/611#comments</comments>
		<pubDate>Sat, 30 May 2009 18:28:47 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[hagalo usted mismo]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=611</guid>
		<description><![CDATA[Recientemente m313n45 me pidio ayuda para hacer un efecto de marquesina con unas imágenes y al dar click sobre alguna de ellas se viera la versión completa, todo esto sin usar flash. Lo realice obviamente con Javascript + JQuery y a continuacion veremos paso a paso como lograrlo. Tambien pueden ver el ejemplo completo aquí [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" language="javascript" src="/demos/jquery.js">
</script></p>
<p>Recientemente <a href="http://m313n45.gamersla.net">m313n45</a> me pidio ayuda para hacer un efecto de marquesina con unas imágenes y al dar click sobre alguna de ellas se viera la versión completa, todo esto sin usar flash. </p>
<p>Lo realice obviamente con Javascript + JQuery y a continuacion veremos paso a paso como lograrlo.</p>
<p><a href="http://albertein.gamersla.net/demos/marquee/index.html">Tambien pueden ver el ejemplo completo aquí</a></p>
<p>Las imágenes para las marquesina son 6, iniciamos con el markup de las imágenes.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;container&quot;&gt;
	&lt;img src=&quot;01.png&quot; alt=&quot;1&quot;/&gt;
	&lt;img src=&quot;02.png&quot; alt=&quot;2&quot;/&gt;
	&lt;img src=&quot;03.png&quot; alt=&quot;3&quot;/&gt;
	&lt;img src=&quot;04.png&quot; alt=&quot;4&quot;/&gt;
	&lt;img src=&quot;05.png&quot; alt=&quot;5&quot;/&gt;
	&lt;img src=&quot;06.png&quot; alt=&quot;6&quot;/&gt;
&lt;/div&gt;
&lt;div id=&quot;viewport&quot;&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>Además ocupamos darle estilo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#container</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">64px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#container</span> img
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">64px</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>overflow: hidden; hace que las imágenes que no quepan en el contenedor esten ocultas en ves de causar scrolling o un efecto similar, además hacemos las imágenes mas pequeñas y asignamos su posicion como relativa, lo cual sera útil a realizar la animación.</p>
<p>Hasta el momento esto se ve así:</p>
<style type="text/css">
#container1, #container2, #container3, #container4
{
	overflow: hidden;
	width: 400px;
	height: 64px;
	border-style: solid;
}
#container4 img
{
	position: relative;
	width: 60px;
	height: 64px;
	cursor: pointer;
}
#container1 img, #container2 img, #container3 img
{
	position: relative;
	width: 60px;
	height: 64px;	
}</p>
</style>
<div id="container1">
	<img src="/demos/marquee/01.png" alt="1"/><img src="/demos/marquee/02.png" alt="2"/><img src="/demos/marquee/03.png" alt="3"/><img src="/demos/marquee/04.png" alt="4"/><img src="/demos/marquee/05.png" alt="5"/><img src="/demos/marquee/06.png" alt="6"/>
</div>
<p>Notece que una de las imágenes se encuentra oculta de momento, debido a que no se alcanza a mostrar en el contenedor.</p>
<p>Después iniciamos con la animacion, requerimos a JQuery para facilitarnos las cosas, tendrán que agregar la referencia a la libreria en su header además de agregar el código de animación:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> deltaX <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> deltaT <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span>	
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//start animation</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> animate <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> left <span style="color: #339933;">=</span> parseInt <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	left <span style="color: #339933;">-=</span> deltaX<span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> left <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	setTimeout <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//continue animation</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Donde deltaT define cada cuantos milisegundos ocurrira la animacion y deltaX indica el desplazamiento cada intervalo de deltaT milisegundos. La animación la realizamos modificando la propiedad left del css. Ahora esto se ve así:</p>
<p><script type="text/javascript" language="javascript" src="/demos/marquee/script2.js"></script></p>
<div id="container2">
	<img src="/demos/marquee/01.png" alt="1"/><img src="/demos/marquee/02.png" alt="2"/><img src="/demos/marquee/03.png" alt="3"/><img src="/demos/marquee/04.png" alt="4"/><img src="/demos/marquee/05.png" alt="5"/><img src="/demos/marquee/06.png" alt="6"/>
</div>
<p>Pero para el momento en que ustedes lleguen a leerlo todas las imágenes habrán desaparecido hacia la izquierda, así que recarguen la pagina por favor y bajen rápidamente hasta este punto para ver la animación. </p>
<p>Eso ocurre por que ocupamos hacer que la marquesina sea giratoria, para lograr el efecto debemos de quitar la primer imagen cuando esta ya no sea visible y ponerla después de la ultima imagen. La primer imagen no es visible cuando su atributo css left tenga un valor de -LongitudImagen, en este caso, -60px. </p>
<p>Como quitaremos la imagen, ocupamos volver a ajustar el desplazamiento a la izquierda aumentando el atributo css left con la longitud de la imagen que quitamos, es decir 60px. El script queda entonces:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> deltaX <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> deltaT <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span>	
<span style="color: #003366; font-weight: bold;">var</span> imageWidth <span style="color: #339933;">=</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//start animation</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> animate <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> left <span style="color: #339933;">=</span> parseInt <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	left <span style="color: #339933;">-=</span> deltaX<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left <span style="color: #339933;">&lt;=</span> <span style="color: #339933;">-</span>imageWidth<span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//if first image is no longer visible</span>
	<span style="color: #009900;">&#123;</span>
		left <span style="color: #339933;">+=</span> imageWidth<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img:first&quot;</span><span style="color: #009900;">&#41;</span>
                	.<span style="color: #660066;">remove</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                	.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img:last&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> left <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	setTimeout <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//continue animation</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Y ya podemos ver la animación circular:</p>
<p><script type="text/javascript" language="javascript" src="/demos/marquee/script3.js"></script></p>
<div id="container3">
	<img src="/demos/marquee/01.png" alt="1"/><img src="/demos/marquee/02.png" alt="2"/><img src="/demos/marquee/03.png" alt="3"/><img src="/demos/marquee/04.png" alt="4"/><img src="/demos/marquee/05.png" alt="5"/><img src="/demos/marquee/06.png" alt="6"/>
</div>
<p>Por ultimo requerimos que al dar click en una imagen la mostremos en su tamaño original, para dar el efecto de vinculo debemos de cambiar el css de las imágenes para que aparezca la &#8220;manita&#8221; cuando pongamos el puntero sobre la imagen, el css queda entonces:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#container</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">64px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#container</span> img
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">64px</span><span style="color: #00AA00;">;</span>	
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Solo nos falta el script, pero debemos de tener cuidado, por que cuando quitamos la imagen para ponerla al final de la lista perdemos la asociación del evento y tenemos que volverla agregar,por lo que el script final queda:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> deltaX <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> deltaT <span style="color: #339933;">=</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span>	
<span style="color: #003366; font-weight: bold;">var</span> imageWidth <span style="color: #339933;">=</span> <span style="color: #CC0000;">60</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span> <span style="color: #009900;">&#40;</span>changeViewportImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//start animation</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> changeViewportImage <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#viewport img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#viewport&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clone</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> animate <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> left <span style="color: #339933;">=</span> parseInt <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	left <span style="color: #339933;">-=</span> deltaX<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left <span style="color: #339933;">&lt;=</span> <span style="color: #339933;">-</span>imageWidth<span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//if first image is no longer visible</span>
	<span style="color: #009900;">&#123;</span>
		left <span style="color: #339933;">+=</span> imageWidth<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img:first&quot;</span><span style="color: #009900;">&#41;</span>
		    .<span style="color: #660066;">remove</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		    .<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img:last&quot;</span><span style="color: #009900;">&#41;</span>
		    .<span style="color: #660066;">click</span> <span style="color: #009900;">&#40;</span>changeViewportImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> left <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	setTimeout <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;animate()&quot;</span><span style="color: #339933;">,</span> deltaT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//continue animation</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Y queda finalmente así (recuerden dar click sobre alguna imagen):<br />
<script type="text/javascript" lang="javascript" src="/demos/marquee/script4.js"></script></p>
<div id="container4">
	<img src="/demos/marquee/01.png" alt="1"/><img src="/demos/marquee/02.png" alt="2"/><img src="/demos/marquee/03.png" alt="3"/><img src="/demos/marquee/04.png" alt="4"/><img src="/demos/marquee/05.png" alt="5"/><img src="/demos/marquee/06.png" alt="6"/>
</div>
<div id="viewport4">
</div>
<p><a href="http://albertein.gamersla.net/demos/marquee/index.html">Tambien pueden ver el ejemplo completo aquí</a></p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/611/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Evaluando expresiones aritméticas con C# (Shunting-yard)</title>
		<link>http://albertein.com.mx/archives/605</link>
		<comments>http://albertein.com.mx/archives/605#comments</comments>
		<pubDate>Tue, 26 May 2009 23:54:52 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=605</guid>
		<description><![CDATA[Fire_Tony tenia que escribir un programa que parseara una expresión aritmética infija (3*1/(2-6)), la convirtiera en un arbol binario, para después mostrar la expresión en notación polaca inversa (sufija) y evaluara el resultado. El pobre no pudo terminar el problema a tiempo, y como me llamo la atención y no tenia mucho que hacer me [...]]]></description>
			<content:encoded><![CDATA[<p>Fire_Tony tenia que escribir un programa que parseara una expresión aritmética infija (3*1/(2-6)), la convirtiera en un arbol binario, para después mostrar la expresión en notación polaca inversa (sufija) y evaluara el resultado.</p>
<p>El pobre no pudo terminar el problema a tiempo, y como me llamo la atención y no tenia mucho que hacer me ofrecí a resolver el problema para que revisara el código y no se viera en ese dilema la próxima ocacion.</p>
<p>El programa por sencillez solo evalúa numeros de 0 al 9 y reconoce los operadores *,+,- y / pero puede ser expandido fácilmente para mas casos.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> SixPackJoy
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Console.<span style="color: #0000FF;">WriteLine</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Expression: &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var expression <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var output <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stack<span style="color: #008000;">&lt;</span>BinaryNode<span style="color: #008000;">&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var stack <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stack<span style="color: #008000;">&lt;</span><span style="color: #0600FF;">Operator</span><span style="color: #008000;">&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var index <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var token <span style="color: #0600FF;">in</span> expression<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            index<span style="color: #008000;">++;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0123456789&quot;</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">//numeric token</span>
            <span style="color: #000000;">&#123;</span>
                output.<span style="color: #0000FF;">Push</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> BinaryNode <span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;*/+-&quot;</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">//operator token</span>
            <span style="color: #000000;">&#123;</span>
                var op <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #0600FF;">Operator</span> <span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                var lastOperator <span style="color: #008000;">=</span> stack.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">?</span> stack.<span style="color: #0000FF;">Peek</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> null<span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>lastOperator <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> 
                    <span style="color: #008000;">!</span>lastOperator.<span style="color: #0000FF;">IsParenthesis</span> <span style="color: #008000;">&amp;&amp;</span> 
                    op.<span style="color: #0000FF;">ComparePrecedence</span><span style="color: #000000;">&#40;</span>stack.<span style="color: #0000FF;">Peek</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    var node <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BinaryNode<span style="color: #000000;">&#40;</span>stack.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>output.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Insuficcient operator argumets, process halted&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                        return<span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    node.<span style="color: #0000FF;">RightChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    node.<span style="color: #0000FF;">LeftChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    output.<span style="color: #0000FF;">Push</span><span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                stack.<span style="color: #0000FF;">Push</span><span style="color: #000000;">&#40;</span>op<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>token <span style="color: #008000;">==</span> <span style="color: #666666;">'('</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                stack.<span style="color: #0000FF;">Push</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #0600FF;">Operator</span><span style="color: #000000;">&#40;</span>token<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>token <span style="color: #008000;">==</span> <span style="color: #666666;">')'</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>stack.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Parenthesis missmatch at {0}, process halted&quot;</span>, index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                        return<span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    var op <span style="color: #008000;">=</span> stack.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>op.<span style="color: #0000FF;">IsParenthesis</span><span style="color: #000000;">&#41;</span>
                        break<span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>output.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        Console.<span style="color: #0000FF;">WriteLine</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Insuficcient operator argumets, process halted&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                        return<span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    var node <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BinaryNode <span style="color: #000000;">&#40;</span>op.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    node.<span style="color: #0000FF;">RightChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    node.<span style="color: #0000FF;">LeftChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    output.<span style="color: #0000FF;">Push</span> <span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Invalid token '{0}' at {1}, process halted&quot;</span>, token, index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>stack.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var op <span style="color: #008000;">=</span> stack.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>op.<span style="color: #0000FF;">IsParenthesis</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Parenthesis missmatch, process halted&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>output.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Insuficcient operator argumets, process halted&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            var node <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BinaryNode<span style="color: #000000;">&#40;</span>op.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            node.<span style="color: #0000FF;">RightChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            node.<span style="color: #0000FF;">LeftChild</span> <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            output.<span style="color: #0000FF;">Push</span><span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>output.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Invalid expression, process halted&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            return<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        var ast <span style="color: #008000;">=</span> output.<span style="color: #0000FF;">Pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0} = {1}&quot;</span>, ast.<span style="color: #0000FF;">GetSufixNotation</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, ast.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #FF0000;">class</span> BinaryNode
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> BinaryNode LeftChild<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">public</span> BinaryNode RightChild<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> BinaryNode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">char</span> value<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Value <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">char</span> Value<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">double</span> Evaluate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>LeftChild <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">double</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>Value.<span style="color: #0000FF;">ToString</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        var operations <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">char</span>, Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">double</span>, <span style="color: #FF0000;">double</span>, <span style="color: #FF0000;">double</span><span style="color: #008000;">&gt;&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
             <span style="color: #000000;">&#123;</span><span style="color: #666666;">'*'</span>, <span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> x <span style="color: #008000;">*</span> y<span style="color: #000000;">&#125;</span>,
             <span style="color: #000000;">&#123;</span><span style="color: #666666;">'/'</span>, <span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> x <span style="color: #008000;">/</span> y<span style="color: #000000;">&#125;</span>,
             <span style="color: #000000;">&#123;</span><span style="color: #666666;">'+'</span>, <span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> x <span style="color: #008000;">+</span> y<span style="color: #000000;">&#125;</span>,
             <span style="color: #000000;">&#123;</span><span style="color: #666666;">'-'</span>, <span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> x <span style="color: #008000;">-</span> y<span style="color: #000000;">&#125;</span>,
          <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">return</span> operations<span style="color: #000000;">&#91;</span>Value<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span>LeftChild.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, RightChild.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetSufixNotation<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>LeftChild <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">return</span> Value.<span style="color: #0000FF;">ToString</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0} {1} {2}&quot;</span>,
            LeftChild.<span style="color: #0000FF;">GetSufixNotation</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
            RightChild.<span style="color: #0000FF;">GetSufixNotation</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
            Value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #FF0000;">class</span> <span style="color: #0600FF;">Operator</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">char</span> Value<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">Operator</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">char</span> value<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Value <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> IsParenthesis
    <span style="color: #000000;">&#123;</span>
        get
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> Value <span style="color: #008000;">==</span> <span style="color: #666666;">'('</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> ComparePrecedence<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Operator</span> o<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;+-&quot;</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>Value<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;+-&quot;</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>o.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">else</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;+-&quot;</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>o.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">else</span>
            <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/605/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Regex replace</title>
		<link>http://albertein.com.mx/archives/389</link>
		<comments>http://albertein.com.mx/archives/389#comments</comments>
		<pubDate>Mon, 06 Apr 2009 18:19:35 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[twitiriqui]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=389</guid>
		<description><![CDATA[Ya e hablado aquí y aquí sobre las expresiones regulares, pero nunca se tenie demasiadas de ellas. Trabajando con un pequeño proyecto personal requería buscar dentro de un texto ocurrencias como @Nombre y #Nombre y convertirlas en un link, la solución es obvia y sencilla con expresiones regulares: Regex.Replace&#40;&#34;this is an example @AlbertEin&#34;, &#34;(?&#60;type&#62;[@#])(?&#60;nick&#62;\\w{1,}[^ ])&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Ya e hablado <a href="/archives/9">aquí</a> y <a href="/archives/24">aquí</a> sobre las expresiones regulares, pero nunca se tenie demasiadas de ellas.</p>
<p>Trabajando con un pequeño proyecto personal requería buscar dentro de un texto ocurrencias como @Nombre y #Nombre y convertirlas en un link, la solución es obvia y sencilla con expresiones regulares:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;this is an example @AlbertEin&quot;</span>, 
                    <span style="color: #666666;">&quot;(?&lt;type&gt;[@#])(?&lt;nick&gt;<span style="color: #008080; font-weight: bold;">\\</span>w{1,}[^ ])&quot;</span>, 
                    <span style="color: #666666;">&quot;&lt;a href=<span style="color: #008080; font-weight: bold;">\&quot;</span>http://twitter.com/${nick}<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;${type}${nick}&lt;/a&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Esto remplaza &#8220;this is an example @AlbertEin&#8221; por &#8220;this is an example <a href="http://twitter.com/AlbertEin">@AlbertEin</a>&#8220;.</p>
<p>La expresión regular:</p>

<div class="wp_syntax"><div class="code"><pre class="regex" style="font-family:monospace;">(?&lt;type&gt;[@#])(?&lt;nick&gt;\\w{1,}[^ ])</pre></div></div>

<p>significa: captura bajo el nombre &#8220;type&#8221; la ocurrencia de texto que inicie con @ ó #, despues captura bajo el nombre &#8220;nick&#8221; el texto que siga que contenga al menos un carácter de texto hasta que te encuentres con un espacio en blanco. </p>
<p>Espero que después de <a href="/archives/tag/regex">tres advertencias</a> ahora si vayan y aprendan de esta útil herramienta para la manipulación de texto.</p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/389/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Parsing de HTML con HtmlAgilityPack</title>
		<link>http://albertein.com.mx/archives/209</link>
		<comments>http://albertein.com.mx/archives/209#comments</comments>
		<pubDate>Thu, 05 Feb 2009 19:38:07 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[aprende]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=209</guid>
		<description><![CDATA[La web esta llena de información, todo tipo de información, desde el vídeo divertido mas irrelevante hasta noticias o documentos de verdadera importancia. Hay un mundo de información a la cual tu computadora esta unida por el cordón umbilical de tu cable de red, dispuesta a ser accesada y mostrada en tu pantalla a la [...]]]></description>
			<content:encoded><![CDATA[<p>La web esta llena de información, todo tipo de información, desde el vídeo divertido mas irrelevante hasta noticias o documentos de verdadera importancia. Hay un mundo de información a la cual tu computadora esta unida por el cordón umbilical de tu cable de red, dispuesta a ser accesada y mostrada en tu pantalla a la mas mínima orden tuya.</p>
<p><strong>Pero tiene un problema.</strong></p>
<p>Toda esta valiosa información se encuentra ofuscada en HTML, un lenguaje el cual a sido seriamente abusado durante el transcurso de los años, debido a que su especificación indica que los navegadores deben hacer lo mejor posible para corregir errores en el formateo de un documento, por lo que los usuarios terminaron en volverse descuidados, olvidando una etiqueta de cierre aquí y halla, al fin y al cabos el resultado es el mismo, ¿no?, los navegadores hacen todo lo posible por mostrar incluso los documentos mas mal formados.</p>
<p>Eso hace que hacer un programa para extraer información de un documento HTML pueda llegar a ser un poco complicado en ocasiones.</p>
<p><strong>HtmlAgilityPack to the rescue!</strong></p>
<p><a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> es una librería para .NET que nos brinda un parser de HTML que nos permite leer, escribir y manipular documentos HTML y soporta Xpath, <a href="http://albertein.gamersla.net/archives/14">el cual discutí hace tiempo</a>. Y lo que lo hace realmente especial es que es increíblemente permisivo, soportando los documentos mas perversamente malformados que te puedes encontrar en tu navegación día a día.</p>
<p>HtmlAgilityPack combinado con <a href="https://addons.mozilla.org/es-ES/firefox/addon/1843">Firebug</a> nos permite extraer hasta la ultima gota de información requerida, y para no hacérselas larga pondré un par de ejemplos en el resto del post.</p>
<p><strong>Quiero obtener la lista de títulos del blog del AlbertEin</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">WebClient</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    client.<span style="color: #0000FF;">Encoding</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">UTF8</span><span style="color: #008000;">;</span>
    var document <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlAgilityPack.<span style="color: #0000FF;">HtmlDocument</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    document.<span style="color: #0000FF;">LoadHtml</span><span style="color: #000000;">&#40;</span>client.<span style="color: #0000FF;">DownloadString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://albertein.gamersla.net&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>HtmlAgilityPack.<span style="color: #0000FF;">HtmlNode</span> node <span style="color: #0600FF;">in</span> 
        document.<span style="color: #0000FF;">DocumentNode</span>.<span style="color: #0000FF;">SelectNodes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;//a[@class='title']&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>node.<span style="color: #0000FF;">InnerHtml</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Quiero obtener la lista de palabras listada en una web de un <a href="http://diccionario.babylon.com/Humanidades/Mitolog%C3%ADa/A/1">diccionario</a></strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var url <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://diccionario.babylon.com/Humanidades/Mitolog%C3%ADa/A/1/&quot;</span><span style="color: #008000;">;</span>
    var client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">WebClient</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    client.<span style="color: #0000FF;">Encoding</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">UTF8</span><span style="color: #008000;">;</span>
    var document <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlAgilityPack.<span style="color: #0000FF;">HtmlDocument</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    document.<span style="color: #0000FF;">LoadHtml</span><span style="color: #000000;">&#40;</span>client.<span style="color: #0000FF;">DownloadString</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>HtmlAgilityPack.<span style="color: #0000FF;">HtmlNode</span> node <span style="color: #0600FF;">in</span>
        document.<span style="color: #0000FF;">DocumentNode</span>.<span style="color: #0000FF;">SelectNodes</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;//a[@class='words']&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>node.<span style="color: #0000FF;">InnerHtml</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Quiero bajar todos los malditos comics de Penny Arcade</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var url <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://www.penny-arcade.com/comic/1998/11/18/&quot;</span><span style="color: #008000;">;</span>
    var baseUrl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://www.penny-arcade.com&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">bool</span> lastStrip <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
    var client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span>.<span style="color: #0000FF;">WebClient</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    client.<span style="color: #0000FF;">Encoding</span> <span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span>.<span style="color: #0000FF;">Encoding</span>.<span style="color: #0000FF;">UTF8</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>lastStrip<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        var document <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlAgilityPack.<span style="color: #0000FF;">HtmlDocument</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        document.<span style="color: #0000FF;">LoadHtml</span><span style="color: #000000;">&#40;</span>client.<span style="color: #0000FF;">DownloadString</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        var imageQuery <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/html/body/div[2]/div[3]/div/div[2]/img&quot;</span><span style="color: #008000;">;</span>
        var nextButtonQuery <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/html/body/div[2]/div[3]/div/div[3]/a[4]&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        var imageUrl <span style="color: #008000;">=</span> document.<span style="color: #0000FF;">DocumentNode</span>.
            <span style="color: #0000FF;">SelectSingleNode</span><span style="color: #000000;">&#40;</span>imageQuery<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Attributes</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;src&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Aquí iria el codigo para descargar la imagen que se encuentra en</span>
        <span style="color: #008080; font-style: italic;">//baseUrl + imageUrl</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Obtenemos la dirección del próximo comic</span>
&nbsp;
        url <span style="color: #008000;">=</span> baseUrl <span style="color: #008000;">+</span> document.<span style="color: #0000FF;">DocumentNode</span>.
            <span style="color: #0000FF;">SelectSingleNode</span> <span style="color: #000000;">&#40;</span>nextButtonQuery<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Attributes</span> <span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;href&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span> 
&nbsp;
        lastStrip <span style="color: #008000;">=</span> url <span style="color: #008000;">==</span> baseUrl<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Llegamos al ultimo comic?</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Podría seguir así todo el día, pero supongo que con eso es suficiente para que capten la idea.</p>
<p><strong>¿Y tu, como lo has usado?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/209/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Mi primera vez (python)</title>
		<link>http://albertein.com.mx/archives/211</link>
		<comments>http://albertein.com.mx/archives/211#comments</comments>
		<pubDate>Sun, 01 Feb 2009 02:36:28 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[primera vez]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=211</guid>
		<description><![CDATA[Hace tiempo que habia visto a python, me llamo la atención por sus características poco usuales, como que los espacios tenga un valor semántico a diferencia de uno puramente visual, donde la identación en el código crea los bloques de codigos que en otros lenguajes se crean con &#8220;begin y end&#8221;, &#8220;{ y }&#8221;, etc. [...]]]></description>
			<content:encoded><![CDATA[<p>Hace tiempo que habia visto a python, me llamo la atención por sus características poco usuales, como que los espacios tenga un valor semántico a diferencia de uno puramente visual, donde la identación en el código crea los bloques de codigos que en otros lenguajes se crean con &#8220;begin y end&#8221;, &#8220;{ y }&#8221;, etc.</p>
<p>Desgraciadamente no habia tenido oportunidad de usarlo para un requerimiento real de mi trabajo, pero eso cambio el día de hoy.</p>
<p><strong>Hoy fue mi primera vez.</strong></p>
<p>El siguiente script fue mi primero con python, toma dos parámetros de la linea de comando, el primero es un archivo con una lista de nombres de usuarios, como el que se obtiene con el siguiente comando:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> : <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">&gt;</span> userDatabase.txt</pre></td></tr></table></div>

<p>El segundo parámetro es un archivo que contiene una lista de usuario{Tabulador}password como por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">panchito	pancho123
albertein	paparazi
dariamox	password</pre></td></tr></table></div>

<p>Lo que hace es imprimir el usuario y contraseña (separado por &#8220;:&#8221;) del segundo archivo cuando el usuario se encuentre listado en el primer archivo. Un formato idóneo para usarlo junto con chpasswd (utilería que cambia las contraseñas del sistema en modo batch).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">python passwordFormatter.py systemUsers passwordDatabase <span style="color: #000000; font-weight: bold;">|</span> chpasswd</pre></td></tr></table></div>

<p>El dichoso script, es este:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #008000;">file</span> = <span style="color: #008000;">open</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span> <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
userList = <span style="color: #008000;">file</span>.<span style="color: black;">read</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
<span style="color: #008000;">file</span>.<span style="color: black;">close</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #008000;">file</span> = <span style="color: #008000;">open</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span> <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">file</span>:
       userData = line.<span style="color: black;">split</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span><span style="color: black;">&#41;</span>
       username = userData <span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
       password = userData <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
       <span style="color: #ff7700;font-weight:bold;">if</span> username <span style="color: #ff7700;font-weight:bold;">in</span> userList:
               <span style="color: #ff7700;font-weight:bold;">print</span> username + <span style="color: #483d8b;">':'</span> + password,
&nbsp;
<span style="color: #008000;">file</span>.<span style="color: black;">close</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/211/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Problemas de Programación I</title>
		<link>http://albertein.com.mx/archives/136</link>
		<comments>http://albertein.com.mx/archives/136#comments</comments>
		<pubDate>Mon, 12 Jan 2009 18:13:26 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[quiz]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=136</guid>
		<description><![CDATA[Aunque pocas personas leen este blog, y mas pocas aun saben de programación voy a experimentar poner pequeños problemas de programación para que los resuelvan en los comentarios y así ganen la infame gloria en el dulce cáliz de la victoria. Las respuestas pueden ser en cualquier lenguaje o pseudocodigo a excepción de los casos [...]]]></description>
			<content:encoded><![CDATA[<p>Aunque pocas personas leen este blog, y mas pocas aun saben de programación voy a experimentar poner pequeños problemas de programación para que los resuelvan en los comentarios y así ganen la infame gloria en el dulce cáliz de la victoria.</p>
<p>Las respuestas pueden ser en cualquier lenguaje o pseudocodigo a excepción de los casos donde se indiquen, tratare de empezar con problemas sencillos y tal ves aumentar la dificultad en el futuro. Algunos problemas incluso podrían ser resueltos por personas que no sepan programar si describen los procesos paso a paso en español.</p>
<p>Los problemas tendrán dos características:</p>
<ol>
<li>Las respuestas requerirán de ingenio o pensar en otra forma de resolver problemas comunes</li>
<li>En algunas ocasiones se requerirá que se preste especial atención en la formulación del problema, una palabra puede cambiar muchas cosas.</li>
</ol>
<p>Sin mas por el momento les dejo los problemas iniciales:</p>
<ol>
<li>Define una función para multiplicación de dos números enteros mayores a cero sin utilizar el operador * (multiplicación) </li>
<li>Define la función anterior sin utilizar ciclos dentro de la función (No for, while, do until, goto, etc.)
<li>Define una función similar a la anterior pero que realice divisiones (resultados enteros)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/136/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>¿Como funciona el swaping con XOR?</title>
		<link>http://albertein.com.mx/archives/26</link>
		<comments>http://albertein.com.mx/archives/26#comments</comments>
		<pubDate>Thu, 06 Mar 2008 20:09:42 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[masturbacion mental]]></category>
		<category><![CDATA[pseudomath]]></category>
		<category><![CDATA[trucos]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/archives/26</guid>
		<description><![CDATA[Los que estudiaron programación indudablemente se encontraron con el problema de swapear dos variables, es decir, intercambiar su valor, y los profesores indudablemente mostraban la resolución: 1 2 3 4 5 6 void Swap &#40;ref int a, ref int b&#41; &#123; int swapTemporal = a; a = b; b = swapTemporal; &#125; Donde se usaba [...]]]></description>
			<content:encoded><![CDATA[<p>Los que estudiaron programación indudablemente se encontraron con el problema de swapear dos variables, es decir, intercambiar su valor, y los profesores indudablemente mostraban la resolución:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #0600FF;">void</span> Swap <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> a, <span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> b<span style="color: #000000;">&#41;</span> 
	<span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">int</span> swapTemporal <span style="color: #008000;">=</span> a<span style="color: #008000;">;</span>
		a <span style="color: #008000;">=</span> b<span style="color: #008000;">;</span>
		b <span style="color: #008000;">=</span> swapTemporal<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Donde se usaba una variable temporal para no perder el valor de a cuando se le asigna el valor de b, para posteriormente asignárselo a b. Algunos tal ves se hayan encontrado la resolución alternativa, usando XOR sin variable temporal:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">	<span style="color: #0600FF;">void</span> Swap <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> a, <span style="color: #0600FF;">ref</span> <span style="color: #FF0000;">int</span> b<span style="color: #000000;">&#41;</span> 
	<span style="color: #000000;">&#123;</span>
		a <span style="color: #008000;">=</span> a <span style="color: #008000;">^</span> b<span style="color: #008000;">;</span>
		b <span style="color: #008000;">=</span> a <span style="color: #008000;">^</span> b<span style="color: #008000;">;</span>
		a <span style="color: #008000;">=</span> a <span style="color: #008000;">^</span> b<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Y quedaron sorprendidos por que ciertamente funciona.</p>
<p><strong>¿Pero, por que?</strong></p>
<p>Empezamos definiendo rápidamente, XOR es un OR exclusivo, lo que significa que es un operador binario que nos da como resultado un 1 solamente si uno de los dos (pero no ambos) operandos es igualmente 1, es decir, la siguiente tabla de verdad:</p>
<pre>
	_________________
	| a | b | a ^ b |
	-----------------
	| 0 | 0 |   0   |
	| 0 | 1 |   1   |
	| 1 | 0 |   1   |
	| 1 | 1 |   0   |
	-----------------
</pre>
<p>Dado esto podemos definir un par de axiomas:</p>
<pre>
	a ^ a = 0
	a ^ 0 = a
</pre>
<p>es decir:</p>
<ul>
<li>Si ambos operandos son iguales en un XOR el resultado es invariablemente cero</li>
<li>Si un operando es igual a cero en un XOR el resultado es invariablemente el valor del otro operando</li>
</ul>
<p>Y estos dos axiomas son lo único que necesitamos para comprobar que el primer y segundo código son equivalentes:</p>
<blockquote>
<p>	<strong>a&#8217; = a ^ b</strong> //Es a prima para evitar confundir la variable con el valor original de a</p>
<p>	b&#8217; = a&#8217; ^ b<br />
	Si sutituimos el valor de a&#8217; tenemos:<br />
	b&#8217; = (a ^ b) ^ b<br />
	b ^ b = 0 por nuestro primer axioma, por lo que nos queda:<br />
	b&#8217; = a ^ 0<br />
	a ^ 0 = a por nuestro segundo axioma, por lo que tenemos<br />
	<strong>b&#8217; = a</strong></p>
<p>	a&#8217; = a&#8217; ^ b&#8217; //Si sustituimos los valores de a&#8217; y b&#8217; tenemos:<br />
	a&#8217; = (a ^ b) ^ a<br />
	a ^ a = 0 por nuestro primer axioma, por lo que nos queda:<br />
	a&#8217; = b ^ 0<br />
	b ^ 0 = b por nuestro segundo axioma, por lo que tenemos<br />
	<strong>a&#8217; = b</strong></p>
<p>	Asi, al finl de las tres operaciones a&#8217; tiene el valor original de b, y b&#8217; el valor original de a.</p>
<p><strong>Q.E.D. \o/</strong>
</p></blockquote>
<p>Como ven la demostración es trivial y seguramente un overkill, pero te puede matar 5 minutos de aburrimiento :p. Nos vemos en la siguiente entrega cuando demuestre que el negro es blanco, claro, al menos que muera antes en un crucero de zebras.</p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/26/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Aprendiendo Regex &#8211; El imperio contrataca.</title>
		<link>http://albertein.com.mx/archives/24</link>
		<comments>http://albertein.com.mx/archives/24#comments</comments>
		<pubDate>Thu, 21 Feb 2008 21:53:50 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[aprende]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/archives/24</guid>
		<description><![CDATA[Gnoblis posteo hacerca de un pequeño programa que hizo para convertir bbcode a html en su web: http://gnoblis.gamersla.net/?p=67. El codigo esta aca http://gamersla.net/gnoblis/descargas/CCast.cs Su solucion si bien funciona, no es de lo mas elegante. El problema es facilmente resuelto con expresiones regulares, y se lo hizo saber en un comentario en su post. Claro, los [...]]]></description>
			<content:encoded><![CDATA[<p>Gnoblis posteo hacerca de un pequeño programa que hizo para convertir bbcode a html <a href="http://gnoblis.gamersla.net/?p=67"> en su web: http://gnoblis.gamersla.net/?p=67</a>. El codigo esta aca <a href="http://gamersla.net/gnoblis/descargas/CCast.cs"> http://gamersla.net/gnoblis/descargas/CCast.cs</a></p>
<p>Su solucion si bien funciona, no es de lo mas elegante. El problema es facilmente resuelto con expresiones regulares, y se lo hizo saber en un comentario en su post.</p>
<p>Claro, los que me conocen sabran que no es suficiente haberle dicho como se podria resolver mejor, ¡hace falta hacerlo uno mismo!</p>
<p>Asi que como demostracion del poder de las expresiones regulares y que no soy un hablador les muestro el codigo:</p>
<p>Nota, el programa no lo probe a excepcion de las expreciones regulares, por lo que pueden encontrarse con sorpresas <img src='http://albertein.com.mx/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
        StreamReader inputReader<span style="color: #008000;">;</span>
        StreamWriter outputWriter<span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> actualLine<span style="color: #008000;">;</span>
        StringBuilder inputFileContent <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> actualFile <span style="color: #0600FF;">in</span> args<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">//Agrego la capacidad de convertir varios archivos a la ves</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>File.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>actualFile<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;File not found, skipped: {0}&quot;</span>, actualFile<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                continue<span style="color: #008000;">;</span>                   <span style="color: #008080; font-style: italic;">//Ignoramos el archivo, pero seguimos con los demas \o/</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            inputReader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #000000;">&#40;</span>File.<span style="color: #0000FF;">OpenRead</span><span style="color: #000000;">&#40;</span>actualFile<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
            inputFileContent.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, inputFileContent.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>actualLine <span style="color: #008000;">=</span> inputReader.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                inputFileContent.<span style="color: #0000FF;">AppendLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}{1}&quot;</span>, actualLine, <span style="color: #666666;">&quot;&lt;br /&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            inputReader.<span style="color: #0000FF;">Close</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>inputFileContent.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Empty file, skipped: {0}&quot;</span>, actualFile<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                continue<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #FF0000;">string</span> bbcodeData <span style="color: #008000;">=</span> inputFileContent.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Quitamos todos los espacios antes y despues de un igual, no solo uno</span>
            bbcodeData <span style="color: #008000;">=</span> Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>bbcodeData, <span style="color: #666666;">@&quot;\ {0,}=\ {0,}&quot;</span>, <span style="color: #666666;">&quot;=&quot;</span>, RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> 
                                                                          RegexOptions.<span style="color: #0000FF;">Multiline</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Convertimos [b], [i], [u], [s] y sus respectivos cierres</span>
            bbcodeData <span style="color: #008000;">=</span> Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>bbcodeData, <span style="color: #666666;">@&quot;\[(?&lt;tag&gt;\/{0,1}[b|i|u|s])\]&quot;</span>, <span style="color: #666666;">@&quot;&lt;${tag}&gt;&quot;</span>, 
                RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> RegexOptions.<span style="color: #0000FF;">Multiline</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//imagenes</span>
            bbcodeData <span style="color: #008000;">=</span> Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>bbcodeData, <span style="color: #666666;">@&quot;\[img\](?&lt;url&gt;.*?)\[\/img\]&quot;</span>,
                <span style="color: #666666;">&quot;&lt;img src=<span style="color: #008080; font-weight: bold;">\&quot;</span>${url}<span style="color: #008080; font-weight: bold;">\&quot;</span> /&gt;&quot;</span>, RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> RegexOptions.<span style="color: #0000FF;">Multiline</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Links</span>
            bbcodeData <span style="color: #008000;">=</span> Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>bbcodeData, <span style="color: #666666;">@&quot;\[url=(?&lt;url&gt;.*?)\](?&lt;data&gt;.*?)\[/url\]&quot;</span>,
                <span style="color: #666666;">&quot;&lt;a href=<span style="color: #008080; font-weight: bold;">\&quot;</span>${url}<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;${data}&lt;/a&gt;&quot;</span>, RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> RegexOptions.<span style="color: #0000FF;">Multiline</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Colores</span>
            bbcodeData <span style="color: #008000;">=</span> Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>bbcodeData, <span style="color: #666666;">@&quot;\[color=(?&lt;color&gt;.*?)\](?&lt;data&gt;.*?)\[/color\]&quot;</span>, 
                <span style="color: #666666;">&quot;&lt;font color=<span style="color: #008080; font-weight: bold;">\&quot;</span>${color}<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;${data}&lt;/font&gt;&quot;</span>, RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> 
                                                           RegexOptions.<span style="color: #0000FF;">Multiline</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            outputWriter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter <span style="color: #000000;">&#40;</span>File.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>actualFile <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.html&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            outputWriter.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>bbcodeData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            outputWriter.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/24/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
