<?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>Linux Blog &#187; programing</title>
	<atom:link href="http://www.rz0r.net/tag/programing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rz0r.net</link>
	<description>Otro blog mas de linux</description>
	<lastBuildDate>Tue, 23 Aug 2011 05:26:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Consumir web services SOAP facil con Python Suds</title>
		<link>http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/</link>
		<comments>http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 05:26:32 +0000</pubDate>
		<dc:creator>rz0r</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.rz0r.net/?p=186</guid>
		<description><![CDATA[Suds es un tremendo cliente SOAP para consumir web services es basado en Python a diferencia de los clientes en Java no hay generación de clases, y el API es tipo orientado a objetos. Y lo mejor es el poco código que se debe escribir para consumir un servicio web y para muestra un ejemplo [...]]]></description>
			<content:encoded><![CDATA[<img style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=90e8a2b5c540d915d4179fab9eeaf31d&amp;default=http://en.gravatar.com/avatar/90e8a2b5c540d915d4179fab9eeaf31d?s=80&r=any' alt='No Gravatar' width=40 height=40/><p>Suds es un tremendo cliente SOAP para consumir web services es basado en Python a diferencia de los clientes en Java no hay generación de clases, y el API es tipo orientado a objetos. Y lo mejor es el poco código que se debe escribir para consumir un servicio web y para muestra un ejemplo sencillo:</p>
<p>Lo primero instalar el cliente ya sea descargándolo del sitio o instalando el paquetes si nuestra distribución de linux lo incluye en sus repositorios.</p>
<pre class="brush: bash; title: ; notranslate">
# fedora 15
yum -y install python-suds
# tarball
wget https://fedorahosted.org/releases/s/u/suds/python-suds-0.4.tar.gz
tar xzvf python-suds-0.4.tar.gz
cd python-suds-0.4
python setup.py install
</pre>
<p>Para el ejemplo utilizaremos uno de los webservices del sitio webservicesx.net</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python

from suds.client import Client
url = 'http://www.webservicex.net/globalweather.asmx?WSDL'
client = Client(url)
print client
</pre>
<p>si todo esta correcto la salida del script mostrara esto:</p>
<p>web service output</p>
<pre class="brush: plain; title: ; notranslate">
Suds ( https://fedorahosted.org/suds/ )  version: 0.3.9 GA  build: R659-20100219

Service ( GlobalWeather ) tns=&quot;http://www.webserviceX.NET&quot;
   Prefixes (0)
   Ports (2):
      (GlobalWeatherSoap)
         Methods (2):
            GetCitiesByCountry(xs:string CountryName, )
            GetWeather(xs:string CityName, xs:string CountryName, )
         Types (0):
      (GlobalWeatherSoap12)
         Methods (2):
            GetCitiesByCountry(xs:string CountryName, )
            GetWeather(xs:string CityName, xs:string CountryName, )
         Types (0):
</pre>
<p>El servicio web tiene 2 metodos los cuales podemos invocar de la siguiente manera:</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python

from suds.client import Client
url = 'http://www.webservicex.net/globalweather.asmx?WSDL'
client = Client(url)
#print client
weather =  client.service.GetWeather('Managua', 'Nicaragua')
print weather
</pre>
<p>esto generara un string conteniendo el xml para que luego pueda ser procesado según se requiera .</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;CurrentWeather&gt;
  &lt;Location&gt;Managua A. C. Sandino, Nicaragua (MNMG) 12-09N 086-10W 56M&lt;/Location&gt;
  &lt;Time&gt;Jul 18, 2011 - 12:00 AM EDT / 2011.07.18 0400 UTC&lt;/Time&gt;
  &lt;Wind&gt; from the ESE (110 degrees) at 5 MPH (4 KT):0&lt;/Wind&gt;
  &lt;Visibility&gt; greater than 7 mile(s):0&lt;/Visibility&gt;
  &lt;SkyConditions&gt; partly cloudy&lt;/SkyConditions&gt;
  &lt;Temperature&gt; 77 F (25 C)&lt;/Temperature&gt;
  &lt;DewPoint&gt; 73 F (23 C)&lt;/DewPoint&gt;
  &lt;RelativeHumidity&gt; 88%&lt;/RelativeHumidity&gt;
  &lt;Pressure&gt; 29.88 in. Hg (1011 hPa)&lt;/Pressure&gt;
  &lt;Status&gt;Success&lt;/Status&gt;
&lt;/CurrentWeather&gt;
</pre>
<p>Referencias:</p>
<p>Python Suds</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.rz0r.net%2F2011%2F07%2Fconsumir-web-services-soap-facil-con-python-suds%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/"  data-text="Consumir web services SOAP facil con Python Suds" data-count="horizontal" data-via="rz0r">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.rz0r.net/2011/07/consumir-web-services-soap-facil-con-python-suds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Permutaciones con Python</title>
		<link>http://www.rz0r.net/2010/04/permutaciones-con-python/</link>
		<comments>http://www.rz0r.net/2010/04/permutaciones-con-python/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 05:24:18 +0000</pubDate>
		<dc:creator>rz0r</dc:creator>
				<category><![CDATA[planeta]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.rz0r.net/?p=139</guid>
		<description><![CDATA[Después de un buen rato sin postear nada en el blog por falta de tiempo, ahora regreso para postear algunos artículos sobre programación. Python es un excelente lenguaje para una tarea como la de generar códigos por ejemplo series o códigos para una lotería o promoción. Python en su versión 2.6 que probé viene con [...]]]></description>
			<content:encoded><![CDATA[<img style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=90e8a2b5c540d915d4179fab9eeaf31d&amp;default=http://en.gravatar.com/avatar/90e8a2b5c540d915d4179fab9eeaf31d?s=80&r=any' alt='No Gravatar' width=40 height=40/><p>Después de un buen rato sin postear nada en el blog por falta de tiempo, ahora regreso para postear algunos artículos sobre programación.</p>
<p>Python es un excelente lenguaje para una tarea como la de generar códigos por ejemplo series o códigos para una lotería o promoción.</p>
<p>Python en su versión 2.6 que probé viene con la librería &#8220;<a href="http://docs.python.org/library/itertools.html">Itertools</a>&#8221; la cual provee funciones iterativas para el manejo eficiente de ciclos y secuencias.</p>
<p>Para demostrar el uso de la librería un ejemplo sencillo seria generar códigos sin repetición únicos alfanuméricos de 5 dígitos suponiendo que los caracteres pueden ser: &#8217;3479JKLNPQRTWXY&#8217;.</p>
<p>recordando un poco de matematica  n!/(n-r)!   se pueden hacer 360360 permutaciones.</p>
<p>supongamos que necesitamos los codigos generados en sets de 50,000 y necesitamos 300,000  tendriamos algo como esto</p>
<pre class="brush: python; title: ; notranslate">
import itertools

# permutacion
code = '3479JKLNPQRTWXY'
codigos = itertools.permutations(code,5)

# ruta a los archivos
path_prefix = '/home/strafe/data-codes/'

# numeracion de los archivos
files_number = range(1,6,1)

# lista con los nombres de los archivos
files = []
for x in files_number:
    files.append(path_prefix + &quot;set&quot;+str(x)+&quot;.csv&quot;)

# procesamiento.
inicio=0
fin=50000
for f in files:
    file = open(f,'w')
    x = list(itertools.islice(codigos,inicio,fin,1))
    for i in x:
        print &gt;&gt; file, &quot;&quot;.join(i)

    file.close()
    inicio=fin
    fin=fin+50000   
</pre>
<p>en el codigo se utilizan &#8220;itertools.permutations&#8221; y &#8220;itertools.islice&#8221;,  itertools.permutations hace el trabajo y itertools.islice permite tomar un rango determinado de la tupla.</p>
<p>Por razones de desempeño y uso de memoria es mas eficiente usar itertools.islice ya que de esa manera la memoria no se agotaria en tratar de procesar el resultado de itertools.permutations de una sola vez. </p>
<p>al final se tendria un resultado como este en los archivos:</p>
<p>3PQ4K<br />
3PQ4L<br />
3PQ4N<br />
3PQ4R<br />
&#8230;</p>
<p>referencias:</p>
<p><a href="http://docs.python.org/library/itertools.html">http://docs.python.org/library/itertools.html</a></p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.rz0r.net%2F2010%2F04%2Fpermutaciones-con-python%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.rz0r.net/2010/04/permutaciones-con-python/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.rz0r.net/2010/04/permutaciones-con-python/"  data-text="Permutaciones con Python" data-count="horizontal" data-via="rz0r">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.rz0r.net/2010/04/permutaciones-con-python/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://www.rz0r.net/2010/04/permutaciones-con-python/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.rz0r.net/2010/04/permutaciones-con-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configurando sun web server 7 con el PHP de Linux</title>
		<link>http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/</link>
		<comments>http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 00:32:53 +0000</pubDate>
		<dc:creator>rz0r</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programing]]></category>
		<category><![CDATA[sun web server]]></category>

		<guid isPermaLink="false">http://www.rz0r.net/?p=98</guid>
		<description><![CDATA[En un post anterior habia mostrado como instalar el Sun Web Server 7  en Fedora8 utilizando el agregado PHP provisto por Sun,  el agregado esta bien si solo deseas utilizar las funciones mas comunes o basicas del PHP5, por lo general el PHP incluido en las distribuciones de linux viene con mas extensiones que le [...]]]></description>
			<content:encoded><![CDATA[<img style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=90e8a2b5c540d915d4179fab9eeaf31d&amp;default=http://en.gravatar.com/avatar/90e8a2b5c540d915d4179fab9eeaf31d?s=80&r=any' alt='No Gravatar' width=40 height=40/><p>En un <a href="http://www.rz0r.net/2008/03/sun-java-system-web-server-70-php5-en-fedora8/" target="_blank">post anterior</a> habia mostrado como instalar el Sun Web Server 7  en Fedora8 utilizando el agregado PHP provisto por Sun,  el agregado esta bien si solo deseas utilizar las funciones mas comunes o basicas del PHP5, por lo general el PHP incluido en las distribuciones de linux viene con mas extensiones que le brinda caracteristicas adicionales al lenguaje.</p>
<p>Ahora bien para usar el PHP5 que viene con la distribuccion de Linux solo necesitamos hacer un par de ajustes al archivo obj.conf .</p>
<pre class="brush: plain; title: ; notranslate">
Service type=&quot;magnus-internal/php&quot;
fn=&quot;responder-fastcgi&quot;
bind-path=&quot;localhost:3101&quot;
app-path=&quot;/usr/bin/php-cgi&quot;
app-env=&quot;PHP_FCGI_CHILDREN=2&quot;
app-env=&quot;PHP_FCGI_MAX_REQUEST=200&quot;
app-env=&quot;FCGI_WEB_SERVER_ADDRS=127.0.0.1&quot;
app-env=&quot;LD_LIBRARY_PATH=/usr/lib/php&quot;
</pre>
<p>agregamos la ruta hacia el cgi de php en el &#8220;app-path&#8221;, y la ruta donde estan las extensiones por lo general es &#8220;/usr/lib/php&#8221; en &#8220;app-env&#8221;</p>
<p>luego en la consola de administracion hacemos un pull &amp; deploy de la configuracion y listo tendremos PHP5 que viene con la distro y todas las extensiones trabajando con nuestro Sun Web Server 7.</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.rz0r.net%2F2009%2F04%2Fconfigurando-sun-web-server-7-con-el-php-de-linux%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/"  data-text="Configurando sun web server 7 con el PHP de Linux" data-count="horizontal" data-via="rz0r">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.rz0r.net/2009/04/configurando-sun-web-server-7-con-el-php-de-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

