<?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>KodeGeek &#187; java</title>
	<atom:link href="http://kodegeek.com/blog/category/programacion/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://kodegeek.com/blog</link>
	<description>Programación, fitness, interés geek</description>
	<lastBuildDate>Sun, 05 Feb 2012 19:12:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mi primer 10K: Joe Kleinerman 10K</title>
		<link>http://kodegeek.com/blog/2012/01/07/mi-primer-10k-joe-kleinerman-10k/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mi-primer-10k-joe-kleinerman-10k</link>
		<comments>http://kodegeek.com/blog/2012/01/07/mi-primer-10k-joe-kleinerman-10k/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 20:38:49 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[10K]]></category>
		<category><![CDATA[carrera]]></category>
		<category><![CDATA[Joe Kleinerman 10K]]></category>
		<category><![CDATA[run]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=3257</guid>
		<description><![CDATA[Mi primer 10K, no estuvo nada mal Hoy corrí mi primer 10K; Decidí probar una estrategia dado que la distancia a batir es el doble de lo que yo estoy acostumbrado a correr; Comencé lento las 2 primeras millas, un poco más rápido las 2 siguiente y las 2 últimas con todo. Recorrido alrededor de [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Before the race by josevnz, on Flickr" href="http://www.flickr.com/photos/josevnz/6653375041/"><img src="http://farm8.staticflickr.com/7022/6653375041_f4ae6fc2c1_z.jpg" alt="Before the race" width="480" height="640" /><br />
Mi primer 10K, no estuvo nada mal</a></p>
<p>Hoy corrí <a href="http://www.flickr.com/photos/josevnz/sets/72157628734241761/">mi primer 10K</a>; Decidí probar una estrategia dado que la distancia a batir es el doble de lo que yo estoy acostumbrado a correr; Comencé lento las 2 primeras millas, un poco más rápido las 2 siguiente y las 2 últimas con todo.</p>
<p><a href="http://www.flickr.com/photos/josevnz/6659507703/" title="Central Park 6.2 mile loop by josevnz, on Flickr"><img src="http://farm8.staticflickr.com/7163/6659507703_eace8a42ab_z.jpg" width="640" height="425" alt="Central Park 6.2 mile loop"/><br />
Recorrido alrededor de Central Park, 6.2 millas</a></p>
<p>Sin contar con una ida obligatoria al baño en la cual gaste por lo menos 40 segundos (el baño estaba ocupado) creo que salió bien <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Los resultados <a href="http://web2.nyrrc.org/cgi-bin/htmlos.cgi/46150.1.4126623148517322302">oficiales</a>:</p>
<table width="700" border="1" cellspacing="0">
<tbody>
<tr bgcolor="EEEEEE">
<td nowrap="nowrap">
<p><a href="http://web2.nyrrc.org/cgi-bin/htmlos.cgi/87235.3.581221553714250724">Last Name</a></td>
<td nowrap="nowrap">
<p><a href="http://web2.nyrrc.org/cgi-bin/htmlos.cgi/87235.3.653769998914250724">First Name</a></td>
<td nowrap="nowrap">
Sex/<br />
Age</td>
<td nowrap="nowrap">
<p>Bib</td>
<td nowrap="nowrap">
<p>Team</td>
<td nowrap="nowrap">
<p>City</td>
<td nowrap="nowrap">
<p>State</td>
<td nowrap="nowrap">
<p>Country</td>
<td nowrap="nowrap">
<a href="http://web2.nyrrc.org/cgi-bin/htmlos.cgi/87235.3.739626665914250724">Overall<br />
Place</a></td>
<td nowrap="nowrap">
<a href="http://web2.nyrrc.org/cgi-bin/htmlos.cgi/87235.3.876538861614250724">Gender<br />
Place</a></td>
<td nowrap="nowrap">
Age<br />
Place</td>
<td nowrap="nowrap">
Net<br />
Time</td>
<td nowrap="nowrap">
Pace/<br />
Mile</td>
<td nowrap="nowrap">
AG<br />
Time</td>
<td nowrap="nowrap">AG<br />
Gender<br />
Place</td>
<td nowrap="nowrap">
<p>AG %</td>
</tr>
<tr>
<td nowrap="nowrap">Nunez Zuleta</td>
<td nowrap="nowrap">Jose V</td>
<td>M38</td>
<td>5735</td>
<td>0</td>
<td nowrap="nowrap">DARIEN</td>
<td>CT</td>
<td nowrap="nowrap">USA</td>
<td>2416</td>
<td>1701</td>
<td>316</td>
<td>0:55:05</td>
<td>08:54</td>
<td>0:52:51</td>
<td>1843</td>
<td nowrap="nowrap">50.82</td>
</tr>
</tbody>
</table>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr valign="top">
<td> Resultados oficiales</td>
</tr>
</tbody>
</table>
<p>Esta es una de las carreras del <a href="http://www.ingnycmarathon.org/about/9_1_guaranteed_entry.htm">9+1</a> para tener una entrada garantizada el maratón de NYC, sólo me faltan 8 más <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2012/01/07/mi-primer-10k-joe-kleinerman-10k/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>¿Como configurar Netbeans 7.10 beta y JavaFX 2.0 beta en OSX?</title>
		<link>http://kodegeek.com/blog/2011/10/15/%c2%bfcomo-configurar-netbeans-7-10-beta-y-javafx-2-0-beta-en-osx/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25c2%25bfcomo-configurar-netbeans-7-10-beta-y-javafx-2-0-beta-en-osx</link>
		<comments>http://kodegeek.com/blog/2011/10/15/%c2%bfcomo-configurar-netbeans-7-10-beta-y-javafx-2-0-beta-en-osx/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 23:07:13 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[netbeans javafx osx]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=3140</guid>
		<description><![CDATA[Es un poco fastidioso, pero una vez que se bajen los binarios y siguiendo las instrucciones (no muy precisas de Oracle) terminé haciendo esto: Netbeans 1.7.1 (beta) + JavaFX 2.0 (beta) ¡Ahora a jugar!]]></description>
			<content:encoded><![CDATA[<p>Es un poco fastidioso, pero una vez que se bajen los binarios y <a href="http://netbeans.org/kb/docs/java/javafx-setup.html">siguiendo las instrucciones</a> (no muy precisas de Oracle) terminé haciendo esto:</p>
<p><a href="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-15-at-7.00.50-PM.png"><img src="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-15-at-7.00.50-PM.png" alt="" title="Netbeans 1.7.1 (beta) + JavaFX 2.0 (beta)" width="883" height="547" class="alignnone size-full wp-image-3141" />Netbeans 1.7.1 (beta) + JavaFX 2.0 (beta)</a></p>
<p>¡Ahora a jugar! <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/10/15/%c2%bfcomo-configurar-netbeans-7-10-beta-y-javafx-2-0-beta-en-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hackeando mis datos en NikeRunning.com</title>
		<link>http://kodegeek.com/blog/2011/10/12/hackeando-mis-datos-en-nikerunning-com/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hackeando-mis-datos-en-nikerunning-com</link>
		<comments>http://kodegeek.com/blog/2011/10/12/hackeando-mis-datos-en-nikerunning-com/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 02:30:19 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[vida sana]]></category>
		<category><![CDATA[nikerunning xml webservices hacking javafx java]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=3123</guid>
		<description><![CDATA[Tipos de terreno para todas mis carreras, desde NikeRunning, mostrado con JavaFX Desde que comencé a correr he utilizado a NikeRunning.com de una u otra manera; Primero comencé con mi Itouch y ahora lo utilizó con el NikeWatch. Sin embargo, el sitio de Nike es un poco fastidioso; El sitio web está escrito en Flash [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-12-at-10.22.43-PM.png"><img src="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-12-at-10.22.43-PM.png" alt="" title="KodeGeek - Tipos de terreno para todas mis carreras, desde NikeRunning" width="502" height="500" class="alignnone size-full wp-image-3132" /><br />
Tipos de terreno para todas mis carreras, desde NikeRunning, mostrado con JavaFX</a></p>
<p>Desde que comencé a correr he utilizado a NikeRunning.com de una u otra manera; Primero comencé con mi Itouch y ahora lo utilizó con el NikeWatch.</p>
<p>Sin embargo, el sitio de Nike es un poco fastidioso; El sitio web está escrito en Flash (lo cual lo hace pesado), tiene gráficos limitados pero lo mas inconveniente es que mis datos están cautivos en el sitio web. Según ellos ya llevan tiempo trabajando en una migración que eliminará Flash:</p>
<blockquote><p>Hello Everyone,</p>
<p>Thank you all for your feedback.</p>
<p>To let everyone know, we are in the process of revamping our website. We are in transition to move away from flash to HTML. The goal is to be faster and more efficient.</p>
<p>We thank you for your patience as we update our sites. There is not an estimated time of when the transition will be fixed, but I can assure you that I&#8217;ve seen parts of the site and it&#8217;s looks and feels amazing.</p>
<p>Stay tuned! </p></blockquote>
<p>Buscando un poco en Google me conseguí conque se puede obtener toda la información de las carreras (siempre y cuando estas esten marcadas como públicas) usando el siguiente URL:</p>

<div class="wp_codebox"><table><tr id="p31236"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p3123code6"><pre class="bash" style="font-family:monospace;">http:<span style="color: #000000; font-weight: bold;">//</span>nikerunning.nike.com<span style="color: #000000; font-weight: bold;">/</span>nikeplus<span style="color: #000000; font-weight: bold;">/</span>v1<span style="color: #000000; font-weight: bold;">/</span>services<span style="color: #000000; font-weight: bold;">/</span>widget<span style="color: #000000; font-weight: bold;">/</span>get_public_run_list.jsp?<span style="color: #007800;">userID</span>=IDENTIFICADOR_DE_USUARIO</pre></td></tr></table></div>

<p>El archivo resultante está en formato XML.</p>
<p>Pero, ¿y de donde obtenemos el identificador del usuario? Es sencillo, simplemente vaya a nikerunning.nike.com y una vez que entre con su usuario y clave al sitio web haga click sobre una de sus corridas. El URL resultante se verá como esto:</p>

<div class="wp_codebox"><table><tr id="p31237"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p3123code7"><pre class="bash" style="font-family:monospace;">http:<span style="color: #000000; font-weight: bold;">//</span>nikerunning.nike.com<span style="color: #000000; font-weight: bold;">/</span>nikeos<span style="color: #000000; font-weight: bold;">/</span>p<span style="color: #000000; font-weight: bold;">/</span>nikeplus<span style="color: #000000; font-weight: bold;">/</span>en_US<span style="color: #000000; font-weight: bold;">/</span>plus<span style="color: #000000; font-weight: bold;">/</span><span style="color: #666666; font-style: italic;">#//runs/gps/IDENTIFICADOR_DE_USUARIO/299193444/</span></pre></td></tr></table></div>

<p>En donde IDENTIFICADOR_DE_USUARIO es el número mágico que queremos usar.</p>
<p>Se me ocurrió por ejemplo escribir un pequeño programa en Jython y JavaFX el cual muestra la distribución de tipos de terreno encontrados mientras corrí:</p>

<div class="wp_codebox"><table><tr id="p31238"><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
</pre></td><td class="code" id="p3123code8"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env jython</span>
<span style="color: #808080; font-style: italic;"># Author: Jose Vicente Nunez Zuleta, josevnz@kodegeek.com</span>
<span style="color: #808080; font-style: italic;"># This script parses the user run data and creates a simple distribtion by terrain types</span>
<span style="color: #808080; font-style: italic;"># See: http://nikerunning.nike.com/nikeos/p/nikeplus/en_EMEA/plus/#//dashboard/</span>
<span style="color: #808080; font-style: italic;"># Nike and Nikeplus/Nike+ are trademarks owned by Nike.</span>
<span style="color: #808080; font-style: italic;"># License: BSD</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">application</span> <span style="color: #ff7700;font-weight:bold;">import</span> Application
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> FXCollections
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> ObservableList
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span> <span style="color: #ff7700;font-weight:bold;">import</span> Scene
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">stage</span> <span style="color: #ff7700;font-weight:bold;">import</span> Stage
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span>.<span style="color: black;">chart</span> <span style="color: #ff7700;font-weight:bold;">import</span> PieChart
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span> <span style="color: #ff7700;font-weight:bold;">import</span> Group
<span style="color: #ff7700;font-weight:bold;">from</span> com.<span style="color: black;">kodegeek</span>.<span style="color: black;">fitness</span>.<span style="color: black;">nikerun</span>.<span style="color: black;">query</span> <span style="color: #ff7700;font-weight:bold;">import</span> CannedQuery
<span style="color: #ff7700;font-weight:bold;">from</span> com.<span style="color: black;">kodegeek</span>.<span style="color: black;">fitness</span>.<span style="color: black;">nikerun</span>.<span style="color: black;">public</span> <span style="color: #ff7700;font-weight:bold;">import</span> PlusPublicService
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> TerrainTypesChart<span style="color: black;">&#40;</span>Application<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> __getData__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        args = <span style="color: #008000;">self</span>.<span style="color: black;">getParameters</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">getRaw</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        pServ = PlusPublicService<span style="color: black;">&#40;</span>args<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        data = pServ.<span style="color: black;">getUserData</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        dp = CannedQuery<span style="color: black;">&#40;</span><span style="color: #483d8b;">'string'</span>, data<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> dp.<span style="color: black;">getTypesOfTerrain</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> start<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, stage<span style="color: black;">&#41;</span>:
        scene = Scene<span style="color: black;">&#40;</span>Group<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Terrain types found in all races&quot;</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setWidth</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setHeight</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span>
&nbsp;
        count = <span style="color: #008000;">self</span>.__getData__<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        data = <span style="color: black;">&#91;</span>PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span>key, value<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>key, value<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> count.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        pieChartData = FXCollections.<span style="color: black;">observableArrayList</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
        chart = PieChart<span style="color: black;">&#40;</span>pieChartData<span style="color: black;">&#41;</span>
        chart.<span style="color: black;">setTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Terrain types found&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
        scene.<span style="color: black;">getRoot</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">getChildren</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span>chart<span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setScene</span><span style="color: black;">&#40;</span>scene<span style="color: black;">&#41;</span>
        stage.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
        Application.<span style="color: black;">launch</span><span style="color: black;">&#40;</span>TerrainTypesChart<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #ff7700;font-weight:bold;">class</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: black;">&#41;</span></pre></td></tr></table></div>

<p>La clase &#8216;PlusPublicService&#8217; no es más que un simple cliente GET el cual se baja los datos del sitio de Nike:</p>

<div class="wp_codebox"><table><tr id="p31239"><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
</pre></td><td class="code" id="p3123code9"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">!</span>/usr/bin/env jython
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Author: Jose Vicente Nunez Zuleta, josevnz@kodegeek.com</span>
<span style="color: #808080; font-style: italic;"># See: http://nikerunning.nike.com/nikeos/p/nikeplus/en_EMEA/plus/#//dashboard/</span>
<span style="color: #808080; font-style: italic;"># Nike and Nikeplus/Nike+ are trademarks owned by Nike.</span>
<span style="color: #808080; font-style: italic;"># License: BSD</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">httplib</span> <span style="color: #ff7700;font-weight:bold;">import</span> HTTPConnection, HTTP_PORT
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
__URL__ = <span style="color: #483d8b;">'nikerunning.nike.com'</span>
__SERVICE__ = <span style="color: #483d8b;">'/nikeplus/v1/services/widget/get_public_run_list.jsp?userID='</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> PlusPublicService:
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, userId, port = HTTP_PORT<span style="color: black;">&#41;</span>:
                <span style="color: #008000;">self</span>.<span style="color: black;">service</span> = __SERVICE__ + userId
                <span style="color: #008000;">self</span>.<span style="color: black;">userId</span> = userId
                <span style="color: #008000;">self</span>.<span style="color: black;">port</span> = port
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> getUserData<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, debug=<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
                data = <span style="color: #008000;">None</span>
                con = HTTPConnection<span style="color: black;">&#40;</span>__URL__, <span style="color: #008000;">self</span>.<span style="color: black;">port</span><span style="color: black;">&#41;</span>
                con.<span style="color: black;">set_debuglevel</span><span style="color: black;">&#40;</span>debug<span style="color: black;">&#41;</span>
                con.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GET'</span>, <span style="color: #008000;">self</span>.<span style="color: black;">service</span><span style="color: black;">&#41;</span>
                response = con.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> response.<span style="color: black;">status</span> == <span style="color: #ff4500;">200</span>:
                        data = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                        <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Error. Status = %s, reason = %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                con.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> data
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
        argv = <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: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>argv<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
                pServ = PlusPublicService<span style="color: black;">&#40;</span>argv<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s&quot;</span> <span style="color: #66cc66;">%</span> pServ.<span style="color: black;">getUserData</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;NikeRunning user id is required!&quot;</span>
                <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">192</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Y para procesar mis datos utilizo un poco de XPATH en la clase &#8216;CannedQuery&#8217; la cual tiene un método el cual se encarga de crear la distribución para los distintos tipos de terreno:</p>

<div class="wp_codebox"><table><tr id="p312310"><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
</pre></td><td class="code" id="p3123code10"><pre class="python" style="font-family:monospace;">/usr/bin/env jython
<span style="color: #808080; font-style: italic;"># Author: Jose Vicente Nunez Zuleta, josevnz@kodegeek.com</span>
<span style="color: #808080; font-style: italic;"># See: http://nikerunning.nike.com/nikeos/p/nikeplus/en_EMEA/plus/#//dashboard/</span>
<span style="color: #808080; font-style: italic;"># Nike and Nikeplus/Nike+ are trademarks owned by Nike.</span>
<span style="color: #808080; font-style: italic;"># License: BSD</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">dom</span>.<span style="color: black;">minidom</span> <span style="color: #ff7700;font-weight:bold;">import</span> parse, parseString
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">etree</span> <span style="color: #ff7700;font-weight:bold;">import</span> ElementTree
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> DataParser<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">type</span>=<span style="color: #483d8b;">'string'</span><span style="color: black;">&#41;</span>:
                <span style="color: #008000;">self</span>.<span style="color: #008000;">type</span> = <span style="color: #008000;">type</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __parseDomFile__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> parse<span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __parseDomString__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> parseString<span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __parseXpathFile__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">file</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> ElementTree.<span style="color: black;">parse</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __parseXpathString__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> ElementTree.<span style="color: black;">fromstring</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __getDom__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, source<span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: #008000;">type</span> == <span style="color: #483d8b;">'string'</span>:
                        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.__parseDomString__<span style="color: black;">&#40;</span>source<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.__parseDomFile__<span style="color: black;">&#40;</span>source<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> __getTree__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, source<span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: #008000;">type</span> == <span style="color: #483d8b;">'string'</span>:
                        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.__parseXpathString__<span style="color: black;">&#40;</span>source<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.__parseXpathFile__<span style="color: black;">&#40;</span>source<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> CannedQuery<span style="color: black;">&#40;</span>DataParser<span style="color: black;">&#41;</span>:
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">type</span>, source<span style="color: black;">&#41;</span>:
                <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CannedQuery, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">type</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">source</span> = source
                <span style="color: #008000;">self</span>.<span style="color: black;">terrainMap</span> = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'0'</span>: <span style="color: #483d8b;">'Not defined'</span>, <span style="color: #483d8b;">'1'</span>: <span style="color: #483d8b;">'Road'</span>, <span style="color: #483d8b;">'2'</span>: <span style="color: #483d8b;">'Trail'</span>, <span style="color: #483d8b;">'3'</span>: <span style="color: #483d8b;">'Treadmill'</span>, <span style="color: #483d8b;">'4'</span>: <span style="color: #483d8b;">'Track'</span> <span style="color: black;">&#125;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> getTypesOfTerrain<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                tree = <span style="color: #008000;">self</span>.__getTree__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">source</span><span style="color: black;">&#41;</span>
                count = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> elem <span style="color: #ff7700;font-weight:bold;">in</span> tree.<span style="color: black;">findall</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;.//terrain&quot;</span><span style="color: black;">&#41;</span>:
                        key = <span style="color: #483d8b;">'Never collected'</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> elem.<span style="color: black;">text</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">terrainMap</span>:
                                key = <span style="color: #008000;">self</span>.<span style="color: black;">terrainMap</span><span style="color: black;">&#91;</span>elem.<span style="color: black;">text</span><span style="color: black;">&#93;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> key <span style="color: #ff7700;font-weight:bold;">in</span> count:
                                count<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span> += <span style="color: #ff4500;">1</span>
                        <span style="color: #ff7700;font-weight:bold;">else</span>:
                                count<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> count
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
        argv = <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: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>argv<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
                dp = CannedQuery<span style="color: black;">&#40;</span><span style="color: #483d8b;">'file'</span>, argv<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                count = dp.<span style="color: black;">getTypesOfTerrain</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s&quot;</span> <span style="color: #66cc66;">%</span> count</pre></td></tr></table></div>

<p>Pienso abrir un proyecto con todas estas clases de Python (Jython) en unos pocos días. Quiero agregarle un par de cosas más antes de soltarlas al aire libre <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/10/12/hackeando-mis-datos-en-nikerunning-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jython + JavaFX: Comienzo duro</title>
		<link>http://kodegeek.com/blog/2011/10/09/jython-javafx-comienzo-duro/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jython-javafx-comienzo-duro</link>
		<comments>http://kodegeek.com/blog/2011/10/09/jython-javafx-comienzo-duro/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 01:32:20 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[javafx java jython]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=3109</guid>
		<description><![CDATA[Al fin Oracle liberó su versión final de JavFX en JavaOne 2011; También hay una versión beta para OSX la cual me baje de una vez. Jugando con los ejemplos me dediqué a experimentar con el ejemplo de un gráfico de torta el cual se ve sencillo: 1 2 3 4 5 6 7 8 [...]]]></description>
			<content:encoded><![CDATA[<p>Al fin Oracle liberó su versión final de JavFX en JavaOne 2011; También hay una versión beta para OSX la cual me baje de una vez.</p>
<p>Jugando con los ejemplos me dediqué a experimentar con <a title="Gráfico de Torta con JavaFX" href="http://download.oracle.com/javafx/2.0/charts/pie-chart.htm#CIHFDADD" target="_blank">el ejemplo de un gráfico de torta</a> el cual se ve sencillo:</p>

<div class="wp_codebox"><table><tr id="p310920"><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
</pre></td><td class="code" id="p3109code20"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.Application</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.collections.FXCollections</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.collections.ObservableList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.chart.PieChart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Group</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PieChartSample <span style="color: #000000; font-weight: bold;">extends</span> Application <span style="color: #009900;">&#123;</span>
&nbsp;
    @Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span>Stage stage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Scene scene <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Scene<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agroup+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Group</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stage.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Imported Fruits&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stage.<span style="color: #006633;">setWidth</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stage.<span style="color: #006633;">setHeight</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        ObservableList pieChartData <span style="color: #339933;">=</span>
                FXCollections.<span style="color: #006633;">observableArrayList</span><span style="color: #009900;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">new</span> PieChart.<span style="color: #006633;">Data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Grapefruit&quot;</span>, <span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span>,
                <span style="color: #000000; font-weight: bold;">new</span> PieChart.<span style="color: #006633;">Data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Oranges&quot;</span>, <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span>,
                <span style="color: #000000; font-weight: bold;">new</span> PieChart.<span style="color: #006633;">Data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Plums&quot;</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>,
                <span style="color: #000000; font-weight: bold;">new</span> PieChart.<span style="color: #006633;">Data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pears&quot;</span>, <span style="color: #cc66cc;">22</span><span style="color: #009900;">&#41;</span>,
                <span style="color: #000000; font-weight: bold;">new</span> PieChart.<span style="color: #006633;">Data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Apples&quot;</span>, <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">final</span> PieChart chart <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PieChart<span style="color: #009900;">&#40;</span>pieChartData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        chart.<span style="color: #006633;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Imported Fruits&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agroup+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Group</span></a><span style="color: #009900;">&#41;</span> scene.<span style="color: #006633;">getRoot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getChildren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>chart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stage.<span style="color: #006633;">setScene</span><span style="color: #009900;">&#40;</span>scene<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        stage.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        launch<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Lo compilamos y corremos:</p>

<div class="wp_codebox"><table><tr id="p310921"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p3109code21"><pre class="bash" style="font-family:monospace;">Macintosh:javafx josevnz$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CLASSPATH</span>=<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>Shared<span style="color: #000000; font-weight: bold;">/</span>javafx-sdk2.0.2-beta<span style="color: #000000; font-weight: bold;">//</span>rt<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>jfxrt.jar:.
Macintosh:javafx josevnz$ javac PieChartSample.java <span style="color: #660033;">-d</span> .
Macintosh:javafx josevnz$ java PieChartSample</pre></td></tr></table></div>

<p><a href="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-09-at-9.19.06-PM.png"><img src="http://kodegeek.com/blog/wp-content/uploads/2011/10/Screen-Shot-2011-10-09-at-9.19.06-PM.png" alt="JavaFX Pie chart" title="JavaFX Pie chart" width="612" height="604" class="alignnone size-full wp-image-3114" />JavaFX gráfico de torta en acción<br />
</a></p>
<p>Así que traté de convertir este sencillo código a Jython:</p>

<div class="wp_codebox"><table><tr id="p310922"><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
</pre></td><td class="code" id="p3109code22"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env jython</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">application</span> <span style="color: #ff7700;font-weight:bold;">import</span> Application
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> FXCollections
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> ObservableList
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span> <span style="color: #ff7700;font-weight:bold;">import</span> Scene
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">stage</span> <span style="color: #ff7700;font-weight:bold;">import</span> Stage
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span>.<span style="color: black;">chart</span> <span style="color: #ff7700;font-weight:bold;">import</span> PieChart
<span style="color: #ff7700;font-weight:bold;">from</span> javafx.<span style="color: black;">scene</span> <span style="color: #ff7700;font-weight:bold;">import</span> Group
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> PieChartSample<span style="color: black;">&#40;</span>Application<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> start<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, stage<span style="color: black;">&#41;</span>:
        scene = Scene<span style="color: black;">&#40;</span>Group<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Imported Fruits&quot;</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setWidth</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setHeight</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span>
&nbsp;
        pieChartData = FXCollections.<span style="color: black;">observableArrayList</span><span style="color: black;">&#40;</span>
                PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Grapefruit&quot;</span>, <span style="color: #ff4500;">13</span><span style="color: black;">&#41;</span>,
                PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Oranges&quot;</span>, <span style="color: #ff4500;">25</span><span style="color: black;">&#41;</span>,
                PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Plums&quot;</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>,
                PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Pears&quot;</span>, <span style="color: #ff4500;">22</span><span style="color: black;">&#41;</span>,
                PieChart.<span style="color: black;">Data</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Apples&quot;</span>, <span style="color: #ff4500;">30</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        chart = PieChart<span style="color: black;">&#40;</span>pieChartData<span style="color: black;">&#41;</span>
        chart.<span style="color: black;">setTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Imported Fruits&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
        scene.<span style="color: black;">getRoot</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">getChildren</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span>chart<span style="color: black;">&#41;</span>
        stage.<span style="color: black;">setScene</span><span style="color: black;">&#40;</span>scene<span style="color: black;">&#41;</span>
        stage.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
        PieChartSample<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">launch</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: black;">&#41;</span></pre></td></tr></table></div>

<p>Pero al correrlo me se queja que no estoy extendiendo bien la clase &#8216;Aplication&#8217; y por eso falla:</p>

<div class="wp_codebox"><table><tr id="p310923"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p3109code23"><pre class="bash" style="font-family:monospace;">Macintosh:javafx josevnz$ .<span style="color: #000000; font-weight: bold;">/</span>piechart.py 
<span style="color: #000000; font-weight: bold;">*</span>sys-package-mgr<span style="color: #000000; font-weight: bold;">*</span>: can<span style="color: #ff0000;">'t create package cache dir, '</span><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>Shared<span style="color: #000000; font-weight: bold;">/</span>jython2.5.2<span style="color: #000000; font-weight: bold;">/</span>cachedir<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #ff0000;">'
Traceback (most recent call last):
  File &quot;./piechart.py&quot;, line 36, in &lt;module&gt;
    PieChartSample().launch(sys.argv[1:])
	at javafx.application.Application.launch(Application.java:186)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
&nbsp;
java.lang.RuntimeException: java.lang.RuntimeException: Error: class sun.reflect.NativeMethodAccessorImpl is not a subclass of javafx.application.Application
&nbsp;
&lt;/module&gt;</span></pre></td></tr></table></div>

<p>No tengo ni idea en donde esta el error, ¿alguno de ustedes tiene una pista? De verdad me muero de ganas por usar JavaFX con Jython, ya otros han tenido éxito similar con <a href="http://download.oracle.com/javafx/2.0/jruby/jfxpub-jruby.htm">JRuby</a> y <a href="http://groovy.codehaus.org/GroovyFX">Groovy</a>.</p>
<p>Amanecerá y veremos.</p>
<p><strong>Actualización</strong>: De la lista de Jython me llegaron muchas sugerencias, al final Weiqi Gao encontró cual era el verdadero problema y esta es la solución:</p>

<div class="wp_codebox"><table><tr id="p310924"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p3109code24"><pre class="java" style="font-family:monospace;"># The key to happiness in JavaFX <span style="color: #339933;">+</span> Jython is <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">if</span> __name__ <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;__main__&quot;</span><span style="color: #339933;">:</span>
    Application.<span style="color: #006633;">launch</span><span style="color: #009900;">&#40;</span>PieChartSample<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000000; font-weight: bold;">class</span>, sys.<span style="color: #006633;">argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>La explicación detallada a continuación:</p>
<blockquote><p>
The trick is with the last line of code that launches the application, which is accomplished with the javafx.application.Application.launch() method.  There are two overloaded versions of this method:</p>

<div class="wp_codebox"><table><tr id="p310925"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p3109code25"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> launch<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>and</p>

<div class="wp_codebox"><table><tr id="p310926"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p3109code26"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> launch<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span> <span style="color: #339933;">?</span> <span style="color: #000000; font-weight: bold;">extends</span> Application<span style="color: #339933;">&gt;</span> appClass, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The first version must be called from a method in a class that extends Application, which is not the case in the above python code.  So we have to use the second version.</p>
<p>The idiom for using the first version of launch() in Java is the following:</p>

<div class="wp_codebox"><table><tr id="p310927"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p3109code27"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #000000; font-weight: bold;">extends</span> Application <span style="color: #009900;">&#123;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span>Stage stage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// build the scene graph and show it</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Application.<span style="color: #006633;">launch</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The idiom for using the second version of launch() in Java is the following:</p>

<div class="wp_codebox"><table><tr id="p310928"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p3109code28"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #000000; font-weight: bold;">extends</span> Application <span style="color: #009900;">&#123;</span>
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span>Stage stage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// build the scene graph and show it</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Launcher <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Application.<span style="color: #006633;">launch</span><span style="color: #009900;">&#40;</span>Foo.<span style="color: #000000; font-weight: bold;">class</span>, args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>There is an inefficiency in my python code in that I instantiated PieChartSample once only to get its class.  I think there is a better way of doing it but can&#8217;t think of how at the moment.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/10/09/jython-javafx-comienzo-duro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>2011 Komen Greater NYC Race for The Cure</title>
		<link>http://kodegeek.com/blog/2011/09/07/2011-komen-greater-nyc-race-for-the-cure/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=2011-komen-greater-nyc-race-for-the-cure</link>
		<comments>http://kodegeek.com/blog/2011/09/07/2011-komen-greater-nyc-race-for-the-cure/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 01:31:14 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=3044</guid>
		<description><![CDATA[Bueno, ya dejando atrás la carrera del Yankee Stadium ahora me lanzo con quizas la última carrera de 5 kilómetros de este año para mi. El recorrido está aquí, es una carrera sin tiempo oficial y por diversión. La idea es colaborar contra el cáncer de seno. Me estoy recuperando aún de la lesión de [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, ya dejando atrás la carrera del <a href="http://kodegeek.com/blog/2011/08/07/segunda-carrera-de-5k-esta-vez-en-el-yankee-stadium/">Yankee Stadium</a> ahora me lanzo con quizas la última <a href="http://www.komennyc.org">carrera de 5 kilómetros de este año para mi</a>.</p>
<p>El recorrido está <a href="http://www.komennyc.org/site/PageServer?pagename=TR2011_race_map">aquí</a>, es una carrera sin tiempo oficial y por diversión. La idea es colaborar contra el cáncer de seno.</p>
<p>Me estoy recuperando aún de la lesión de la carrera anterior. Sin embargo las medicinas y el calzado han hecho una gran diferencia. No creo que mejore los tiempos (poco tiempo para entrenar, más recuperación), pero al menos espero mantener lo que hice la última carrera.</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/09/07/2011-komen-greater-nyc-race-for-the-cure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nueva carrera de 5 kilómetros, ¡esta vez en el Yankee Stadium!</title>
		<link>http://kodegeek.com/blog/2011/06/12/nueva-carrera-de-5-kilometros-%c2%a1esta-vez-en-el-yankee-stadium/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nueva-carrera-de-5-kilometros-%25c2%25a1esta-vez-en-el-yankee-stadium</link>
		<comments>http://kodegeek.com/blog/2011/06/12/nueva-carrera-de-5-kilometros-%c2%a1esta-vez-en-el-yankee-stadium/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 13:01:02 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[5 kilómetros]]></category>
		<category><![CDATA[5k]]></category>
		<category><![CDATA[cancer research]]></category>
		<category><![CDATA[carrera]]></category>
		<category><![CDATA[correr]]></category>
		<category><![CDATA[fitness]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[yankee stadium]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2951</guid>
		<description><![CDATA[Amigos y lectores del blog, este 7 de Agosto voy a correr la carrera de 5K en el Yankee Stadium en el estado de New York; Los fondos recolectados van a ser utilizados para estudios de cura contra el Cancer. Yo estoy recaudando fondos como parte de la carrera, los invito a que donen cualquier [...]]]></description>
			<content:encoded><![CDATA[<p><iframe width="853" height="510" src="http://www.youtube.com/embed/804ZxSf3WvM?hd=1" frameborder="0" allowfullscreen></iframe></p>
<p>Amigos y lectores del blog, este 7 de Agosto <a href="http://www.damonrunyon.org/yankeestadium">voy a correr la carrera de 5K en el Yankee Stadium en el estado de New York</a>; Los fondos recolectados van a ser utilizados para estudios de cura contra el Cancer.</p>
<p>Yo estoy recaudando fondos como parte de la carrera,<a href="http://Runyon5K.kintera.org/josevnz"> los invito a que donen cualquier cantidad</a> ya que es para una buena causa.</p>
<p>Un abrazo y gracias de antemano,</p>
<p>&#8211;José</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/06/12/nueva-carrera-de-5-kilometros-%c2%a1esta-vez-en-el-yankee-stadium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>¿Como saber el tipo de un archivo? (I)</title>
		<link>http://kodegeek.com/blog/2011/02/26/%c2%bfcomo-saber-el-tipo-de-un-archivo-i/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25c2%25bfcomo-saber-el-tipo-de-un-archivo-i</link>
		<comments>http://kodegeek.com/blog/2011/02/26/%c2%bfcomo-saber-el-tipo-de-un-archivo-i/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 23:25:08 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mime magic libmagic jni java]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[jni]]></category>
		<category><![CDATA[libmagic]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[mime type]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2762</guid>
		<description><![CDATA[Por alguna razón, este articulo viejo ha tenido algo de tráfico en los últimos días. Me dí cuenta que la idea de usar Java y JNI nunca se materializó, sólo dí unas pistas. Una forma de hacer esto es llamando a la librería &#8216;magic&#8217;. Magic viene prácticamente en cualquier sistema operativo que se parezca a [...]]]></description>
			<content:encoded><![CDATA[<p>Por alguna razón, <a href="http://kodegeek.com/blog/2007/09/22/echando-codigo-¿como-saber-de-que-tipo-es-un-archivo-desde-java">este articulo viejo</a> ha tenido algo de tráfico en los últimos días. Me dí cuenta que la idea de usar Java y JNI nunca se materializó, sólo dí unas pistas.</p>
<p>Una forma de hacer esto es llamando a la librería &#8216;magic&#8217;. Magic viene prácticamente en cualquier sistema operativo que se parezca a UNIX que se respete, como BSD, OSX y por supuesto Linux.</p>
<p>Si usted llama a la página man (man 3 libmagic) allí encontrará suficiente información. Por ejemplo, aquí les muestro un pequeño programa que hice en C el cual detecta el tipo de archivo que usted le pase por la línea de comandos:</p>

<div class="wp_codebox"><table><tr id="p276232"><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
</pre></td><td class="code" id="p2762code32"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include </span>
<span style="color: #339933;">#include </span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
 * Program that shows how to use the magic library to figure out the type of a file
 * @author Jose V Nunez (josevnz@kodegeek.com)
 * License: BSD
 */</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span> argv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;[ERROR]: Please provide the file name to check and try again!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// See manpage libmagic for details on what this flags mean</span>
        <span style="color: #993333;">int</span> flags <span style="color: #339933;">=</span> MAGIC_SYMLINK<span style="color: #339933;">|</span>MAGIC_COMPRESS<span style="color: #339933;">|</span>MAGIC_CONTINUE<span style="color: #339933;">|</span>MAGIC_PRESERVE_ATIME<span style="color: #339933;">|</span>MAGIC_ERROR<span style="color: #339933;">;</span>
&nbsp;
        magic_t cookie <span style="color: #339933;">=</span> magic_open<span style="color: #009900;">&#40;</span>flags<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cookie <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;There was a problem opening the magic library!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #993333;">int</span> status <span style="color: #339933;">=</span> magic_load<span style="color: #009900;">&#40;</span>cookie<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>status <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Unable to load magic default database!, %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> magic_error<span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                magic_close<span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> file_details <span style="color: #339933;">=</span>  magic_file<span style="color: #009900;">&#40;</span>cookie<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Type for file: %s is %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> file_details<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        magic_close<span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Para compilarlo les dejo un archivo Makefile:</p>

<div class="wp_codebox"><table><tr id="p276233"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2762code33"><pre class="makefile" style="font-family:monospace;">CPPFLAGS += -O2 -L/Users/Shared/lib -I/Users/Shared/include -lmagic
all: magic.c
        $(CC) $(CPPFLAGS) magic.c -o magic</pre></td></tr></table></div>

<p>Y finalmente como se corre:</p>

<div class="wp_codebox"><table><tr id="p276234"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2762code34"><pre class="bash" style="font-family:monospace;">auyan:c josevnz$ <span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">cc</span> <span style="color: #660033;">-O2</span> -L<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>Shared<span style="color: #000000; font-weight: bold;">/</span>lib -I<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>Shared<span style="color: #000000; font-weight: bold;">/</span>include <span style="color: #660033;">-lmagic</span> magic.c <span style="color: #660033;">-o</span> magic
auyan:c josevnz$ .<span style="color: #000000; font-weight: bold;">/</span>magic <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>josevnz<span style="color: #000000; font-weight: bold;">/</span>CTX.DAT
Mime <span style="color: #7a0874; font-weight: bold;">type</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span>: <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>josevnz<span style="color: #000000; font-weight: bold;">/</span>CTX.DAT is Java serialization data, version <span style="color: #000000;">5</span>
auyan:c josevnz$</pre></td></tr></table></div>

<p>En la siguiente entrada las prometo como hacer esto desde Java (pista, vamos a utilizar JNI).</p>
<p>&#8211;José</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2011/02/26/%c2%bfcomo-saber-el-tipo-de-un-archivo-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book reviews: JavaFX 1.2 Application Development Cookbook</title>
		<link>http://kodegeek.com/blog/2010/11/17/book-reviews-javafx-1-2-application-development-cookbook/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=book-reviews-javafx-1-2-application-development-cookbook</link>
		<comments>http://kodegeek.com/blog/2010/11/17/book-reviews-javafx-1-2-application-development-cookbook/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 12:10:42 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[apache pivot]]></category>
		<category><![CDATA[javafx 2.0]]></category>
		<category><![CDATA[visage]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2650</guid>
		<description><![CDATA[JavaFX 1.2 Application Development Cookbook is a really nice book; The cookbook title is a little bit misleading as the book is a quick progression over the features of the language and how it can be used to write applications, all done in a very professional y concise manner. Then why it is difficult to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.packtpub.com/javafx-1-2-application-development-cookbook/book">JavaFX 1.2 Application Development Cookbook</a> is a really nice book; The cookbook title is a little bit misleading as the book is a quick progression over the features of the language and how it can be used to write applications, all done in a very professional y concise manner.</p>
<p>Then why it is difficult to wrote about this book? Well, the first issue is than the latest API (with significant changes) for JavaFX is 1.3 while the book is written for 1.2; There are several performance and stability improvements, new graphic controls so this was definitely an mandatory upgrade for anyone thinking seriously into using the language. But the real deal breaker here is than <a href="http://weblogs.java.net/blog/fabriziogiudici/archive/2010/09/27/javafx-script-dead-long-live-visage">JavaFX script is being discontinued and instead is being made a proper Java API that can be used by your regular Java developers</a>.</p>
<p>All this will happen on the &#8216;JavaFX 2.0&#8242; version of the language, sometime next year. Also JavaFX script is not really dead &#8230; is reincarnated as an open source platform called <a href="http://learnjavafx.typepad.com/weblog/2010/10/expressionism-and-the-art-of-creating-user-interfaces.html">Visage</a>.</p>
<p>So if I were you I would wait to see how JavaFX 2.0 looks like instead, no investment in books or coding for the time being. As for Visage, I would rather go for a head to head comparison with other tools like <a href="http://pivot.apache.org/">Apache Pivot</a> which is more mature at this point.</p>
<p><strong>The good:</strong> The book is a good one, easy to read and with good concrete examples. The price tag is also good.</p>
<p><strong>The bad:</strong> Not a problem with the book itself, but the technology is changing to fast and too much, so it doesn&#8217;t make sense to invest on this book. Wait until Oracle delivers JavaFX 2.0.</p>
<p><strong>The ugly:</strong> Oracle should have pull the plug sooner. JavaFX has lost a lot of momentum and makes you wonder if now it&#8217;s real purpose will be to replace an aging Swing on the desktop. </p>
<p><a href="http://www.oracle.com/us/corporate/press/173728">There are great things scheduled for JavaFX</a>, but we will have to wait some more to see them. Perhaps a new version of this book will be more than welcome once the new version is out.</p>
<p>&#8211;Jose</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2010/11/17/book-reviews-javafx-1-2-application-development-cookbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX Script ha muerto, Swing aún sigue en pie</title>
		<link>http://kodegeek.com/blog/2010/09/21/javafx-script-ha-muerto-swing-aun-sigue-en-pie/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javafx-script-ha-muerto-swing-aun-sigue-en-pie</link>
		<comments>http://kodegeek.com/blog/2010/09/21/javafx-script-ha-muerto-swing-aun-sigue-en-pie/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 11:33:40 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jafavx]]></category>
		<category><![CDATA[javafx is dead]]></category>
		<category><![CDATA[javaone]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2603</guid>
		<description><![CDATA[Bueno, es un cambio de tono que no esperaba. En JavaOne de este año anunciaron que JavaFX Script está muerto y en va a tener integración desde Swing y otros lenguajes dinámicos. Las mentadas de madre no se hicieron esperar en Twitter y otros lados el día de hoy. Después de todo son 3 años [...]]]></description>
			<content:encoded><![CDATA[<p> Bueno, es un cambio de tono que no esperaba. En <a href="http://java.dzone.com/articles/oracle-discontinue-javafx">JavaOne de este año anunciaron que JavaFX Script</a> está muerto y en va a tener integración desde Swing y otros lenguajes dinámicos.</p>
<p><a href="http://twitter.com/search?q=%23javafx">Las mentadas de madre</a> no se hicieron esperar en Twitter y otros lados el día de hoy. Después de todo son 3 años en los cuales un producto se vuelve a reiniciar (yo me cuento entre quienes perdieron el tiempo leyendo sobre JavaFX). Por otro lado, Java Swing necesita mejoras pronto y quizas esta es la mejor decisión.</p>
<p>Como que alguien en Oracle se dio cuenta que la inversión en Swing de tantos años no se puede botar a la basura, sin embargo queda por verse si vale la pena invertir el tiempo en <a href="http://javafx.com/roadmap/">JavaFX antes de la versión 2.0</a> (apenas estamos en 1.3, la cual tiene todavía muchos huecos).</p>
<p>¿Quiere más detalles (código)? <a href="http://steveonjava.com/javafx-2-0/">Aquí</a> tienen una muestra de lo que viene&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2010/09/21/javafx-script-ha-muerto-swing-aun-sigue-en-pie/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>And the winner of the JavaFXpert RIA Exemplar Challenge</title>
		<link>http://kodegeek.com/blog/2010/09/20/and-the-winner-of-the-javafxpert-ria-exemplar-challenge/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=and-the-winner-of-the-javafxpert-ria-exemplar-challenge</link>
		<comments>http://kodegeek.com/blog/2010/09/20/and-the-winner-of-the-javafxpert-ria-exemplar-challenge/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 00:44:54 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[ria exemplar challenge]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2601</guid>
		<description><![CDATA[La aplicación es una belleza, además de que el código y el problema que resuelve son interesantes. Si agregar más nada And the winner [of the JavaFXpert RIA Exemplar Challenge] ¡Ah, y tiene código abierto!]]></description>
			<content:encoded><![CDATA[<p>La aplicación es una belleza, además de que el código y el problema que resuelve son interesantes. Si agregar más nada<br />
<a href="http://learnjavafx.typepad.com/weblog/2010/09/and-the-winner-to-the-javafxpert-ria-exemplar-challenge-is.html">And the winner [of the JavaFXpert RIA Exemplar Challenge]</a></p>
<p>¡Ah, y tiene código abierto!</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2010/09/20/and-the-winner-of-the-javafxpert-ria-exemplar-challenge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

