<?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/category/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>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: Twitt al azar con JQuery, Ajax y la Search API de Twitter</title>
		<link>http://albertein.com.mx/archives/657</link>
		<comments>http://albertein.com.mx/archives/657#comments</comments>
		<pubDate>Thu, 11 Jun 2009 17:34:55 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=657</guid>
		<description><![CDATA[Con motivo del Partido del No Trabajo hice una pequeña pagina de broma donde gracias a la API de búsqueda de Twitter se muestra aleatoriamente un twitt que haga referencia al partido (hashtag #PNT). Una ves terminado decidí aprovechar un poco de lo realizado para hacer una mini guia para realizar un visor de twitts [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify">Con motivo del <a href="http://pnt.gamersla.net">Partido del No Trabajo hice una pequeña pagina de broma</a> donde gracias a la API de búsqueda de Twitter se muestra aleatoriamente un twitt que haga referencia al partido (hashtag #PNT). Una ves terminado decidí aprovechar un poco de lo realizado para hacer una mini guia para realizar un visor de twitts aleatorios sobre algún tema en especifico.</p>
<p style="text-align: justify">Debido a que la API de twitter no te informa la cantidad de twitts sobre un tema en particular tenemos que hacer un poco de trampa, y en ves de buscar un twitt aleatorio buscamos un twitt aleatorio entre los últimos N twits respecto al tema. Con esta aclaración en mente iniciamos con el Markup de la pagina.</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="xhtml" style="font-family:monospace;">&lt;p&gt;
    Show me a random twitt about 
    &lt;input type=&quot;text&quot; id=&quot;topic&quot; /&gt; 
    using the last 
    &lt;input type=&quot;text&quot; id=&quot;twittsQty&quot; /&gt; 
    twitts. 
    &lt;span id=&quot;go&quot;&gt;GO!&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
    &lt;img src=&quot;&quot; id=&quot;userImage&quot; alt=&quot;&quot; /&gt; 
    &lt;span id=&quot;user&quot;&gt;&lt;/span&gt;
    : &lt;span id=&quot;text&quot;&gt;&lt;/span&gt;
&lt;/p&gt;</pre></td></tr></table></div>

<p style="text-align: justify">El input con id &#8220;topic&#8221; sera donde el usuario especificara el tema a buscar, como &#8220;#PNT&#8221;, y además ocupamos saber de entre cuantos twitts vamos a buscar, esto lo obtendremos del input con id &#8220;twittsQty&#8221;. Por ultimo el span con id &#8220;go&#8221; hará la funcion de un botón. Al presionar el span con id &#8220;go&#8221; obtendremos el twitt aleatorio y pondremos su contenido en el segundo p, img con id &#8220;userImage&#8221; contendra el avatar del autor, el span &#8220;user&#8221; tendrá su nombre de usuario y el span &#8220;text&#8221; contendrá el contenido del twitt.</p>
<p style="text-align: justify">Lo siguiente es ver como obtener el twitt, si buscamos en la documentación de twitter descubriremos que ocupamos llamar a &#8220;http://search.twitter.com/search.json?q=BUSQUEDA&#038;show_user=true&#038;rpp=1&#038;page=PAGINA&#038;callback=?&#8221; donde BUSQUEDA es el tema a buscar y PAGINA el numero aleatorio generado, ¿por que PAGINA es el numero aleatorio?, como se puede ver rpp tiene un valor de &#8220;1&#8243;, por lo que twitter tomara en cuenta un twitt por pagina, de esta forma el valor de PAGINA nos daré el Nesimo twitt. Con eso solo debemos de tener en mente que la BUSQUEDA debe de estar escapada. El código seria 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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<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;#go&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #003366; font-weight: bold;">var</span> twitterPage <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> Math.<span style="color: #660066;">floor</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</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;#twittsQty&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</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: #003366; font-weight: bold;">var</span> twitterQuery <span style="color: #339933;">=</span> encodeURIComponent <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#topic&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</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: #003366; font-weight: bold;">var</span> requestUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://search.twitter.com/search.json?q=@query&amp;show_user=true&amp;rpp=1&amp;page=@page&amp;callback=?&quot;</span>.
            <span style="color: #660066;">replace</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/@query/g</span><span style="color: #339933;">,</span> twitterQuery<span style="color: #009900;">&#41;</span>.
            <span style="color: #660066;">replace</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/@page/g</span><span style="color: #339933;">,</span> twitterPage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">getJSON</span> <span style="color: #009900;">&#40;</span>requestUrl<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> twitt <span style="color: #339933;">=</span> data.<span style="color: #660066;">results</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#userImage&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;src&quot;</span><span style="color: #339933;">,</span> twitt.<span style="color: #660066;">profile_image_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#user&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span> <span style="color: #009900;">&#40;</span>twitt.<span style="color: #660066;">from_user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span> <span style="color: #009900;">&#40;</span>twitt.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <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;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Ahora agregamos un poco de estilo:</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="css" style="font-family:monospace;"><span style="color: #cc00cc;">#go</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> Blue<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</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>
<span style="color: #cc00cc;">#userImage</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">52px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">52px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Y nos quedamos con lo siguiente:</p>
<p>
    Show me a random twitt about </p>
<input type="text" id="topic" />
    using the last </p>
<input type="text" id="twittsQty" />
    twitts.<br />
    <span id="go">GO!</span>
</p>
<p>
    <img src="" id="userImage" alt="" /><br />
    <span id="user"></span><br />
    : <span id="text"></span>
</p>
<style type="text/css">
#go
{
	color: Blue;
	text-decoration: underline;
	cursor: pointer;
}
#userImage
{
	width: 52px;
	height: 52px;
}
</style>
<p><script type="text/javascript" language="javascript" src="http://albertein.gamersla.net/demos/jquery.js"></script><br />
<script type="text/javascript" language="javascript" src="http://albertein.gamersla.net/demos/rndTwitt/script.js"></script></p>
<p>Tamien pueden ver el resultado <a href="http://albertein.gamersla.net/demos/rndTwitt/index.html">aquí</a> o en <a href="http://pnt.gamersla.net">la Web del Partido del No Trabajo (PNT)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/657/feed</wfw:commentRss>
		<slash:comments>4</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>SVG+Firefox me han fallado</title>
		<link>http://albertein.com.mx/archives/52</link>
		<comments>http://albertein.com.mx/archives/52#comments</comments>
		<pubDate>Thu, 08 Jan 2009 16:30:05 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[estandares]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[navegadores]]></category>
		<category><![CDATA[svg]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=52</guid>
		<description><![CDATA[Recientemente me vi con la necesidad de crear una pagina web que visualizara gráficos dinámicos de acuerdo a ciertos datos recabados en tiempo real. Debido a que ocupaba mostrar el gráfico tanto en una pantalla gigante como en dispositivos móviles pensé que la solución obvia era usar gráficos vectoriales. ¿Que tan difícil podía ser?. Que [...]]]></description>
			<content:encoded><![CDATA[<p>Recientemente me vi con la necesidad de crear una pagina web que visualizara gráficos dinámicos de acuerdo a ciertos datos recabados en tiempo real.</p>
<p>Debido a que ocupaba mostrar el gráfico tanto en una pantalla gigante como en dispositivos móviles pensé que la solución obvia era usar gráficos vectoriales. <i>¿Que tan difícil podía ser?.</i></p>
<p><b>Que ingenuo fui.</b></p>
<p>Innegablemente la clara solución era SVG (Scalable Vectors Graphics), sabia que me toparía con un par de problemas, principalmente con compatibilidad entre navegadores. Ninguna batalla que algún desarrollador web no haya luchado alguna vez. Un trabajo sucio pero alguien tiene que hacerlo.</p>
<p>IE no soporta SVG, a su vez usa un formato propietario VML (Vector Markup Language) el cual no tengo interés de aprender (ningún otro navegador lo soporta), pero afortunadamente Adobe ofrece un plugin que le da a IE la posibilidad de visualizar SVG, una pequeña molestia pero nada infranqueable.</p>
<p>Entre otras cosas lo que requería hacer era insertar varias instancias de una misma imagen SVG sobre otra imagen SVG base y manipularla a través de scripting para asignar su posicionamiento, mascara, etc. Pero al intentar insertar la imagen no aparecía nada.</p>
<p><b>WTF?!</b><br />
Después de batallar, leer, moverle, etc. Se me ocurre insertar una imagen PNG a la vez de SVG y todo funciona correctamente. WHAT?. Resulta que Firefox solo soporta insertar imágenes rasterizadas (jpg, png) dentro de SVG, y no puedo insertar otras imágenes vectoriales dentro de imágenes vectoriales.</p>
<p><b>DAMN!</b><br />
En ese instante quede aturdido, que sentido tiene usar SVG por ser escalable si no puedo insertar imágenes escalables (Ojo, es un bug de Firefox, la recomendación de SVG especifica que esto debe de ser permitido). No tenia sentido que siguiera con mi esfuerzo de implementarlo a golpe de SVG con javascript.</p>
<p>Por mucho que me doliera tuve que abandonar la solución que utilizaba estandares para usar formatos propietarios.</p>
<p><em>Una ves mas, Flash ha ganado la batalla.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/52/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Navidad y Compiladores</title>
		<link>http://albertein.com.mx/archives/50</link>
		<comments>http://albertein.com.mx/archives/50#comments</comments>
		<pubDate>Wed, 24 Dec 2008 00:07:34 +0000</pubDate>
		<dc:creator>AlbertEin</dc:creator>
				<category><![CDATA[Ocio]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[compiladores]]></category>
		<category><![CDATA[navidad]]></category>

		<guid isPermaLink="false">http://albertein.gamersla.net/?p=50</guid>
		<description><![CDATA[Compiladores Desde hace varios años cuando aun estaba estudiando en la universidad me llamaba mucho la atención el diseño e implementación de compiladores. Lamentablemente en la universidad nunca tuve la oportunidad de implementar uno a través de mis clases de compiladores (donde curiosamente nunca llegamos a ver compiladores, solo autómatas y cosas por el estilo). [...]]]></description>
			<content:encoded><![CDATA[<h1>Compiladores</h1>
<p>Desde hace varios años cuando aun estaba estudiando en la universidad me llamaba mucho la atención el diseño e implementación de compiladores. Lamentablemente en la universidad nunca tuve la oportunidad de implementar uno a través de mis clases de compiladores (donde curiosamente nunca llegamos a ver compiladores, solo autómatas y cosas por el estilo).</p>
<p>Claro que eso no es pretexto, pero jamas tuve el animo de tomar el famoso libro del dragón de los compiladores y leerlo a fondo, tan solo una ojeada bastaba para intimidar al mas duros y valientes con la notación de gramática.</p>
<p>expr -> expr + term | expr &#8211; term | term<br />
term -> term * factor | term / factor | factor<br />
factor -> digit | (expr)</p>
<p>Decidí dejar de procrastinar al respecto y me conseguí el libro, y lo que antes parecía brujería de la mala con un vistazo resulto ser entendible y manejable con una lectura mas profunda. Eso o eh madurado un poco. Lo mas probable es que sea un poco de ambas cosas.</p>
<div id="attachment_40" class="wp-caption alignnone" style="width: 340px"><img src="http://albertein.gamersla.net/wp-content/uploads/2008/12/purple_dragon_book_b.jpg" alt="Compilers: Principles, Techniques, and Tools 2nd Edition (Purple Dragon Book)" title="El causante de mis mas grandes temores" width="330" height="500" class="size-medium wp-image-40" /><p class="wp-caption-text">Compilers: Principles, Techniques, and Tools 2nd Edition (Purple Dragon Book)</p></div>
<p>Espero poder terminarlo y poder completar un compilador o interprete (Aun no me decido) como proyecto personal.</p>
<h1>Navidad</h1>
<p>Mi hermosa esposa me ha dado unos increíbles regalos de navidad, ¡gracias mi amor!</p>
<p>Detalles de los regalos:</p>
<ul>
<li>
<p><strong>Brisingr:</strong> La tercera parte de la trilogía (ahora parece que es saga) de Christopher Paollini, en estos momentos estoy leyendo los dos primeros libros (Eragon y Eldest) para tener fresca la tercera parte cuando inicie su lectura.
</p>
<p><div id="attachment_42" class="wp-caption alignnone" style="width: 310px"><img src="http://albertein.gamersla.net/wp-content/uploads/2008/12/brisingr_book_cover.png" alt="Brisingr, tercera parte de El Legado" title="Brisingr" width="300" height="450" class="size-medium wp-image-42" /><p class="wp-caption-text">Brisingr, tercera parte de El Legado</p></div>
</li>
<li>
<p><strong>Guitar Hero III Legends of Rock: </strong>¿Necesito decir mas?</p>
<p><div id="attachment_44" class="wp-caption alignnone" style="width: 265px"><img src="http://albertein.gamersla.net/wp-content/uploads/2008/12/guitar-hero-iii-cover-image.jpg" alt="Guitar Hero III Legends of Rock" title="Guitar Hero III Legends of Rock" width="255" height="380" class="size-medium wp-image-44" /><p class="wp-caption-text">Guitar Hero III Legends of Rock</p></div>
</li>
<li>
<p><strong>Guitar Hero World Tour: </strong>Así es, versión solo guitarra, no puedo darme el lujo de una batería con niños tan curiosos =P</p>
<p><div id="attachment_46" class="wp-caption alignnone" style="width: 266px"><img src="http://albertein.gamersla.net/wp-content/uploads/2008/12/guitar_hero_world_tour.jpg" alt="Guitar Hero World Tour" title="Guitar Hero World Tour" width="256" height="320" class="size-medium wp-image-46" /><p class="wp-caption-text">Guitar Hero World Tour</p></div>
</li>
<li>
<p><strong>Trauma Center New Blood: </strong>Quede sorprendido cuando jugué Trauma Center Under the Knife en el DS de Kid hace ya mas de un año, un juego sumamente adictivo, ¡espero que la versión para Wii sea al menos tan bueno!</p>
<p><div id="attachment_47" class="wp-caption alignnone" style="width: 310px"><img src="http://albertein.gamersla.net/wp-content/uploads/2008/12/new_blood_game_cover.jpg" alt="Trauma Center New Blood" title="Trauma Center New Blood" width="300" height="421" class="size-medium wp-image-47" /><p class="wp-caption-text">Trauma Center New Blood</p></div>
</li>
</ul>
<p>Gracias de nuevo amor, y ¡Feliz Navidad a Todos!</p>
]]></content:encoded>
			<wfw:commentRss>http://albertein.com.mx/archives/50/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
