<?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>Alvaro Mouriño</title>
	<atom:link href="http://blog.mourino.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mourino.net</link>
	<description>On software, standards and some other boring things</description>
	<lastBuildDate>Mon, 20 Feb 2012 16:47:42 +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>Django Site matching query does not exist.</title>
		<link>http://blog.mourino.net/2011/12/15/django-site-matching-query-does-not-exist/</link>
		<comments>http://blog.mourino.net/2011/12/15/django-site-matching-query-does-not-exist/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 13:16:21 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=117</guid>
		<description><![CDATA[When you configure your brand new Django project you&#8217;ll see in your settings something like: SITE_ID = 1 That ID refers to the Django &#8220;sites&#8221; framework. If you plan on using the admin interface make sure that ID exists in the database, otherwise you&#8217;ll get an error: DoesNotExist at /admin/ Site matching query does not [...]]]></description>
			<content:encoded><![CDATA[<p>When you configure your brand new Django project you&#8217;ll see in your settings something like:</p>
<p><code lang="python"><br />
SITE_ID = 1<br />
</code></p>
<p>That ID refers to the <a href="https://docs.djangoproject.com/en/dev/ref/contrib/sites/" title="Django sites framework">Django &#8220;sites&#8221; framework</a>. If you plan on using the admin interface make sure that ID exists in the database, otherwise you&#8217;ll get an error:</p>
<p><code lang="python"><br />
DoesNotExist at /admin/</p>
<p>Site matching query does not exist.</p>
<p>Request Method: GET<br />
Request URL: http://localhost:8000/admin/<br />
Django Version: 1.3<br />
Exception Type: DoesNotExist<br />
Exception Value:</p>
<p>Site matching query does not exist.<br />
</code></p>
<p>If it doesn&#8217;t exist, create it:</p>
<p><code lang="python"><br />
>>> from django.contrib.sites.models import Site<br />
>>> site = Site()<br />
>>> site.domain = 'example.com'<br />
>>> site.name = 'My website'<br />
>>> site.save()<br />
>>> site.id<br />
3<br />
</code></p>
<p>That&#8217;s the ID you should use in your settings file:</p>
<p><code lang="python"><br />
SITE_ID = 3<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/12/15/django-site-matching-query-does-not-exist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2nd place for Santa&#8217;s Media Queries!</title>
		<link>http://blog.mourino.net/2011/12/07/2nd-place-for-santas-media-queries/</link>
		<comments>http://blog.mourino.net/2011/12/07/2nd-place-for-santas-media-queries/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 14:53:41 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=105</guid>
		<description><![CDATA[I&#8217;m happy to announce that my demo Santa&#8217;s Media Queries got the 2nd place on October&#8217;s Mozilla Dev Derby!! =) (Read the announcement) My first big surprise was to see the number of hits the demo was getting, never thought that it could attract so many people. At the time of this writing it has [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://developer.mozilla.org/en-US/demos/detail/santas-media-queries"><img src="http://blog.mourino.net/wp-content/uploads/2011/12/smqsnap.png" alt="Santa&#039;s Media Queries" title="Santa&#039;s Media Queries" width="300" height="177" class="alignleft size-full wp-image-108" /></a>I&#8217;m happy to announce that my demo <a href="https://developer.mozilla.org/en-US/demos/detail/santas-media-queries" title="Santa's Media Queries">Santa&#8217;s Media Queries</a> got the 2nd place on <a href="https://developer.mozilla.org/en-US/demos/devderby/2011/october/" title="October's Mozilla Dev Derby">October&#8217;s Mozilla Dev Derby</a>!! =)</p>
<p>(Read the <a href="http://hacks.mozilla.org/2011/11/congrats-to-our-october-dev-derby-winners/">announcement</a>)</p>
<p>My first big surprise was to see the number of hits the demo was getting, never thought that it could attract so many people. At the time of this writing it has received 1744 views and 35 likes. Never expected that.</p>
<p>My second (and biggest) surprise was to find out that from all the excellent submissions (I mentioned some in a <a href="http://blog.mourino.net/2011/10/30/css-media-queries/" title="CSS Media Queries">previous post</a>) mine got to be in the top 3. It&#8217;s such an honor.</p>
<p>What makes it even more special is the people who chose it. Let&#8217;s take a look at <a href="https://developer.mozilla.org/en-US/demos/devderby#tab-judging" title="Mozilla Dev Derby judges">the judges</a>:</p>
<ul>
<li><a href="http://isofarro.com/" title="Mike Davies">Mike Davies</a>, Web developer, <a href="http://twitter.com/isofarro">@isofarro</a></li>
<li><a href="http://wonko.com/" title="Ryan Grove">Ryan Grove</a>, YUI engineer at Yahoo!, <a href="http://twitter.com/yaypie" title="Ryan Grove">@yaypie</a></li>
<li><a href="http://encoding.com/" title="Jeff Malkin">Jeff Malkin</a>, President, encoding.com, <a href="http://twitter.com/jeffmalkin">@jeffmalkin</a></li>
<li><a href="http://nimbupani.com/" title="Divya Manian">Divya Manian</a>, Web opener at Opera, Open Web Vigilante, <a href="http://twitter.com/divya">@divya</a></li>
<li><a href="http://ethanmarcotte.com/" title="Ethan Marcotte">Ethan Marcotte</a>, Web designer, author, <a href="http://twitter.com/beep">@beep</a></li>
<li><a href="http://lea.verou.me/" title="Lea Verou">Lea Verou</a>, Web developer, Co-founder of Fresset LTD., <a href="http://twitter.com/leaverou">@leaverou</a></li>
<li><a href="https://github.com/defunkt" title="Chris Wanstrath">Chris Wanstrath</a>, Developer, Github co-founder, <a href="http://twitter.com/defunkt">@defunkt</a></li>
<li><a href="http://benward.me/" title="Ben Ward">Ben Ward</a>, Fron-end developer at twitter, <a href="http://twitter.com/benward">@benward</a></li>
</ul>
<p>And the prize is a beautiful <a href="http://www.rickshawbags.com/commuter-laptop-bag.html#color=1237">laptop messenger bag</a>, something I&#8217;ve been checking out on ebay recently, but this one is *way* better than what I intended to buy =)</p>
<p>It&#8217;s perfect.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/12/07/2nd-place-for-santas-media-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anatomy of a SPA. RubyConf Uruguay.</title>
		<link>http://blog.mourino.net/2011/12/03/anatomy-of-a-spa-rubyconf-uruguay/</link>
		<comments>http://blog.mourino.net/2011/12/03/anatomy-of-a-spa-rubyconf-uruguay/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 02:09:13 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=95</guid>
		<description><![CDATA[This is the prize I got for giving a talk at the RubyConf Uruguay, I totally loved it. It has my github nick in it =) My talk was &#8220;Anatomy of a Single-Page Application: Client-side Model-View-Controller&#8220;. (Watch it. Spanish audio, slides in english.) For me was a total success, got a lot of great feedback, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.mourino.net/wp-content/uploads/2011/11/rubyconfuy.png"><img src="http://blog.mourino.net/wp-content/uploads/2011/11/rubyconfuy-300x225.png" alt="My present from the RubyConf Organization" title="RubyConfUruguay" width="300" height="225" class="alignleft size-medium wp-image-98" /></a> This is the prize I got for giving a talk at the RubyConf Uruguay, I totally loved it. It has my github nick in it =)</p>
<p>My talk was &#8220;<a href="http://blog.mourino.net/wp-content/talks/rubyconf-20111112/">Anatomy of a Single-Page Application: Client-side Model-View-Controller</a>&#8220;. (<a href="http://www.eventials.com/rubyconfuy/recorded/M2UzZTJkMzY2MzdiNTg2NTUxNWM1MzI3NWY1YjRhMzYjIzQ1Mw_3D_3D">Watch it</a>. Spanish audio, slides in english.) For me was a total success, got a lot of great feedback, people approached me after the talk to ask questions and didn&#8217;t hear much of contrary opinions to what I said. I do know that how I said it wasn&#8217;t much fun for everyone.</p>
<p>I trolled a little. Not much, just enough, and (almost) always with proper justification. I trolled against jQuery, CoffeeScript and PHP. The problem was that I didn&#8217;t know there was a CoffeeScript talk right before mine. <a href="https://twitter.com/#!/dudadornelles" title="Duda Dornelles">Duda Dorenelles</a> talk about CoffeeScript, and as I watched his talk I was feeling bad for what I had on my slides.</p>
<p>&#8220;<a href="https://twitter.com/#!/dudadornelles/status/135348165338595330">Forget about CoffeeScript, be a man!</a>&#8221; I think it&#8217;s the most controversial line of my talk, but it&#8217;s not groundless, and I explained it. I also talked to Duda and he totally understood, he even agreed with me. He is a super cool guy, I hope we can share a beer again sometime.</p>
<p>The organization of the event was excellent, besides some delay in the talks which is totally normal, everything went very smoothly, at least it seemed so. The night before the event they took the speakers to dinner, I didn&#8217;t expect that, was a very nice surprise. And as I mentioned before, I got this beautiful present after the talk which was very cool.</p>
<p>I was very anxious and nervous after the talk so I didn&#8217;t look at it very well, didn&#8217;t realize it had my nick on it. Later, when I was more calm I saw it and really loved it. I&#8217;m looking forward to being part of next year&#8217;s RubyConf Uruguay.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/12/03/anatomy-of-a-spa-rubyconf-uruguay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyConf Uruguay 2011</title>
		<link>http://blog.mourino.net/2011/11/10/rubyconf-uruguay-2011/</link>
		<comments>http://blog.mourino.net/2011/11/10/rubyconf-uruguay-2011/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 13:38:14 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=87</guid>
		<description><![CDATA[Next 11th and 12th November is this year&#8217;s RubyConf here in Montevideo. This time I&#8217;ll be giving a talk about how to apply the MVC pattern on the client-side. About the event I enjoyed last year&#8217;s conference but the truth is that I couldn&#8217;t get much from it. It was intended for people with previous [...]]]></description>
			<content:encoded><![CDATA[<p>Next 11th and 12th November is this year&#8217;s RubyConf here in <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Montevideo" title="Montevideo, Uruguay">Montevideo</a>. This time I&#8217;ll be giving a talk about how to apply the MVC pattern on the client-side.</p>
<h2>About the event</h2>
<p>I enjoyed last year&#8217;s conference but the truth is that I couldn&#8217;t get much from it. It was intended for people with previous Ruby knowledge and there was little left for the rest of us.</p>
<p>It looks like this year&#8217;s schedule covers a wider range of topics and levels. In their website they promoted it as an event to attract developers from different areas, specially Java.</p>
<h2>The Java strategy</h2>
<p>In my opinion going after Java (and it&#8217;s satellite enterprisey languages) developers is a good strategy. It would be hard to convince people from other languages with a solid web foundation like Python or PHP to move to Ruby where you can basically accomplish the same tasks, and what matters most is how well you know the language/framework.</p>
<p>However, web development with Java is hard and bloated. Tools like GWT are an approach to attract the hardcore <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Object-oriented_programming" title="Object-Oriented Programming">OO</a> programmers to do web. This is wrong, Java and JavaScript share 4 characters in their names, the C-like syntax and little more. They are based on completely different paradigms.</p>
<p>So I think that for Java developers looking to do web it would really make a difference to switch to another language like Python or Ruby.</p>
<h2>About my talk</h2>
<p>I&#8217;ll be talking about JavaScript. As I have never written a single line of Ruby this is one of the few topics I could propose and that they&#8217;d be interested in.</p>
<p>The title of the talk is &#8220;<b>Anatomy of a <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Single-page_application" title="Single-Page Application">SPA</a>: Client-side <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Model–view–controller" title="Model-View-Controller">MVC</a></b>&#8220;. It&#8217;s an introduction to applying the pattern on JavaScript by the use of the Backbone.js library. I&#8217;ll starts by explaining the MVC pattern and when/why it&#8217;s important to apply it in your application, then I&#8217;ll shows what are the tools Backbone.js gives us for this. It will be more about concepts than actual code.</p>
<p>I have prepared many jokes, some flamewars and naked people. That&#8217;s a proven formula for success.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/11/10/rubyconf-uruguay-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Media Queries</title>
		<link>http://blog.mourino.net/2011/10/30/css-media-queries/</link>
		<comments>http://blog.mourino.net/2011/10/30/css-media-queries/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 23:45:29 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=81</guid>
		<description><![CDATA[October&#8217;s Mozilla Dev Derby was about CSS Media Queries. According to the Mozilla Developer Network documentation: CSS 3 enhances support for media-dependent style sheets by letting style sheets be more precisely labeled. A media query consists of a media type and at least one expression that limits the style sheets&#8217; scope by using media features, [...]]]></description>
			<content:encoded><![CDATA[<p>October&#8217;s <a href="https://developer.mozilla.org/en-US/demos/devderby" title="Mozilla Dev Derby">Mozilla Dev Derby</a> was about <a href="https://developer.mozilla.org/en/CSS/Media_queries" title="CSS Media Queries">CSS Media Queries</a>.</p>
<p>According to the <a href="https://developer.mozilla.org/en-US/" title="Mozilla Developer Network">Mozilla Developer Network</a> documentation:</p>
<blockquote><p>CSS 3 enhances support for media-dependent style sheets by letting style sheets be more precisely labeled.  A media query consists of a media type and at least one expression that limits the style sheets&#8217; scope by using media features, such as width, height, and color.  Media queries let the presentation of content be tailored to a specific range of output devices without having to change the content itself.</p></blockquote>
<p>This means, basically, you can switch style sheets depending on different properties such as the size of the browser window. Is a simple yet powerful feature, but I think the biggest challenge is coming up with something creative using such an unsophisticated feature.</p>
<p>I submitted two demos:</p>
<h3><a href="https://developer.mozilla.org/en-US/demos/detail/fueye">Fueye</a></h3>
<blockquote><p>This demo aims to show how properties can be manipulated based on the browser window size. This works by defining different stylesheets for each of the dimensions you want to take actions on. For the demo I created 14 stylesheets, a base one for every widow size and 13 others for 100px, 200px, 300px and so on until 1300px width.</p>
<p>As you resize the window you&#8217;ll see changes in the rotation, opacity, background, width and height of the elements.</p></blockquote>
<p>This was my first approach to Media Queries, nothing complex but it was fun to spice it up a little with transitions.</p>
<h3><a href="https://developer.mozilla.org/en-US/demos/detail/santas-media-queries">Santa&#8217;s Media Queries</a></h3>
<blockquote><p>Using CSS Media Queries this demo detects the size of your browser window and removes members of the family. Marge and Homer are not as alone as they&#8217;d like to be.</p></blockquote>
<p>My second demo was more a design challenge than a code challenge. Given an image of The Simpsons sitting in their famous couch I started removing them one by one with <a href="http://en.wikipedia.org/wiki/GIMP" title="GNU Image Manipulation Program">GIMP</a> until only Homer, Marge and Santa&#8217;s little helper were left. Brian, a friend, recommended me to add something more, that&#8217;s how <a href="http://shayatri.files.wordpress.com/2011/06/spider-pig-spiderpig-236328_750_580.gif" title="Spiderpig">spiderpig</a> got behind the couch. I was told that it looks like he eats the people <img src="http://th17.photobucket.com/albums/b87/RavenTashine/Guild Wars/th_smiley-tongue-out.gif" alt="=P" /></p>
<p>It got over 100 visits in just 24hs, I was impressed.</p>
<p>Some very good demos by other developers in no particular order:</p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/demos/detail/css3-cherry-blossom-media-queries">CSS3 Cherry Blossom &#8211; Media queries</a></li>
<li><a href="https://developer.mozilla.org/en-US/demos/detail/smooth-queries">Smooth queries</a></li>
<li><a href="https://developer.mozilla.org/en-US/demos/detail/too-many-fish-is-the-sea">Too many fish is the sea</a></li>
<li><a href="https://developer.mozilla.org/en-US/demos/detail/image-gallery-with-css3-columns-and-media-queries">Image Gallery with CSS3 Columns and Media Queries</a></li>
</ul>
<p>Maybe Michal meant &#8220;in&#8221; instead of &#8220;is&#8221; in &#8220;Too many fish is the sea&#8221;. Check out <a href="https://developer.mozilla.org/en-US/profiles/michal.b/" title="michal.b">michal.b</a>&#8216;s other demos, they are great.</p>
<p>I&#8217;m already thinking about what I&#8217;m going to do for next month&#8217;s Derby with <a href="https://developer.mozilla.org/en/HTML/Element/canvas" title="Canvas HTML element">canvas</a>. Let&#8217;s see what I can come up with.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/10/30/css-media-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Algorithm vs. Heuristic</title>
		<link>http://blog.mourino.net/2011/10/27/algorithm-vs-heuristic/</link>
		<comments>http://blog.mourino.net/2011/10/27/algorithm-vs-heuristic/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 11:47:41 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=69</guid>
		<description><![CDATA[According to Wikipedia: Algorithm In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning. In simple words an algorithm is a step-by-step procedure for calculations. Starting from an initial state and initial [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://en.wikipedia.org/">Wikipedia</a>:</p>
<h3><a href="http://en.wikipedia.org/wiki/Algorithm">Algorithm</a></h3>
<blockquote><p>In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning. In simple words an algorithm is a step-by-step procedure for calculations.</p>
<p>Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, will proceed through a finite number of well-defined successive states, eventually producing &#8220;output&#8221; and terminating at a final ending state.</p></blockquote>
<h3><a href="http://en.wikipedia.org/wiki/Heuristic">Heuristic</a></h3>
<blockquote><p>Heuristic refers to experience-based techniques for problem solving, learning, and discovery. Heuristic methods are used to speed up the process of finding a satisfactory solution, where an exhaustive search is impractical. Examples of this method include using a &#8220;rule of thumb&#8221;, an educated guess, an intuitive judgment, or common sense.</p>
<p>In more precise terms, heuristics are strategies using readily accessible, though loosely applicable, information to control problem solving in human beings and machines.</p></blockquote>
<p>Both are ways of reaching from point A to point B, but the algorithm is predictable, that is, the steps are predefined and do not change. On the other hand the heuristic is a higher level technique that does not output a result, as the algorithm does, but instead guides you in finding the solution. The final result varies because the heuristic is only a guide on how to look, not on what to find.</p>
<p>From the book <a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ref=sr_1_1?ie=UTF8&#038;qid=1319715515&#038;sr=8-1">Code Complete: A Practical Handbook of Software Construction</a>:</p>
<blockquote><p>Here is an algorithm for driving to someone’s house: Take highway 167 south to Puyallup. Take the South Hill Mall exit and drive 4.5 miles up the hill. Turn right at the light by the grocery store, and then take the first left. Turn into the driveway of the large tan house on the left, at 714 North Cedar.</p>
<p>Here is a heuristic for getting to someone’s house: Find the last letter we mailed you. Drive to the town in the return address. When you get to town, ask someone where our house is. Everyone knows us—someone will be glad to help you. If you can’t find anyone, call us from a public phone, and we’ll come get you.</p></blockquote>
<p>This kind of metaphors can be applied at many levels of software development, from architecture to GUI, relieving us from the need of knowing the internals of the system and therefore easing the understanding of the big picture.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/10/27/algorithm-vs-heuristic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving methods from one class to another</title>
		<link>http://blog.mourino.net/2011/07/16/moving-methods-from-one-class-to-another/</link>
		<comments>http://blog.mourino.net/2011/07/16/moving-methods-from-one-class-to-another/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 16:23:37 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=39</guid>
		<description><![CDATA[Not too often you need to move a method from one class to another, but sometimes you just do. You may be tempted to do something like this: >>> class A(object): ... def b(self): ... print('b') ... >>> A.b >>> class B(object): ... pass ... >>> B.b = A.b >>> B.b >>> b = B() [...]]]></description>
			<content:encoded><![CDATA[<p>Not too often you need to move a method from one class to another, but sometimes you just do. You may be tempted to do something like this:</p>
<p><code lang="python"><br />
>>> class A(object):<br />
...     def b(self):<br />
...         print('b')<br />
...<br />
>>> A.b<br />
<unbound method A.b><br />
>>> class B(object):<br />
...     pass<br />
...<br />
>>> B.b = A.b<br />
>>> B.b<br />
<unbound method A.b><br />
>>> b = B()<br />
>>> b.b<br />
<unbound method A.b><br />
>>> b.b()<br />
Traceback (most recent call last):<br />
  File "<stdin>", line 1, in <module><br />
TypeError: unbound method b() must be called with A instance as first argument (got nothing instead)<br />
</code></p>
<p>But as noted, it doesn&#8217;t work. In python even functions are objects, and A.b is an instance of your method. What you need is the class itself, the &#8220;raw&#8221; function:</p>
<p><code lang="python"><br />
>>> B.b = A.b.__func__<br />
>>> B.b<br />
<unbound method B.b><br />
>>> b.b()<br />
b<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/07/16/moving-methods-from-one-class-to-another/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[python] Verificador de documentos Uruguayos</title>
		<link>http://blog.mourino.net/2011/06/17/python-verificador-de-documentos-uruguayos/</link>
		<comments>http://blog.mourino.net/2011/06/17/python-verificador-de-documentos-uruguayos/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 16:44:34 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=15</guid>
		<description><![CDATA[El siguiente script valida el número de cédula de identidad Uruguaya. # -*- coding: utf-8 -*- import re import sys CI_RE = re.compile(r'\d') CI_MAGIC_NUMBERS = (4, 3, 6, 7, 8, 9, 2) def check(ci): _ci = CI_RE.findall(ci) _ci.reverse() counter = 0 for key, value in enumerate(_ci[1:]): counter += int(value) * CI_MAGIC_NUMBERS[key] counter %= 10 if [...]]]></description>
			<content:encoded><![CDATA[<p>El siguiente script valida el número de cédula de identidad Uruguaya.</p>
<p><code lang="python"><br />
# -*- coding: utf-8 -*-<br />
import re<br />
import sys</p>
<p>CI_RE = re.compile(r'\d')<br />
CI_MAGIC_NUMBERS = (4, 3, 6, 7, 8, 9, 2)</p>
<p>def check(ci):<br />
    _ci = CI_RE.findall(ci)<br />
    _ci.reverse()<br />
    counter = 0<br />
    for key, value in enumerate(_ci[1:]):<br />
        counter += int(value) * CI_MAGIC_NUMBERS[key]<br />
        counter %= 10<br />
    if (10 - counter) % 10 != int(_ci[0]):<br />
        return False<br />
    return True</p>
<p>if __name__ == '__main__':<br />
    if check(sys.argv[1]):<br />
        print('OK')<br />
    else:<br />
        print('ERROR')<br />
</code></p>
<p>Para utilizarlo correrlo de la siguiente forma:</p>
<p><code><br />
$ python validarci.py 1.23456-1<br />
</code></p>
<p>Ver también: <a href="http://blog.pablohoffman.com/script-numeros-cedula-uruguay">Script Numeros Cedula Uruguay</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/06/17/python-verificador-de-documentos-uruguayos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoiding circular imports</title>
		<link>http://blog.mourino.net/2011/06/11/avoiding-circular-imports/</link>
		<comments>http://blog.mourino.net/2011/06/11/avoiding-circular-imports/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 16:47:53 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.mourino.net/?p=4</guid>
		<description><![CDATA[Whenever you find yourself in a situation where two modules import each other, the easiest way out is to move one of the pieces of code to an external module. Example: secret.py from .models import User def get_key(): return '53cr37 k3y' def get_user_model(): return User models.py from .secret import get_key from hashlib import sha256 class [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever you find yourself in a situation where two modules import each other, the easiest way out is to move one of the pieces of code to an external module. Example:</p>
<p>secret.py<br />
<code lang="python"><br />
from .models import User</p>
<p>def get_key():<br />
    return '53cr37 k3y'</p>
<p>def get_user_model():<br />
    return User<br />
</code></p>
<p>models.py<br />
<code lang="python"><br />
from .secret import get_key<br />
from hashlib import sha256</p>
<p>class User(object):<br />
    """A user.<br />
    """</p>
<p>    def __init__(self, username, password):<br />
        self.username = username<br />
        self.password = sha256('%s&#038;&#038;%s' % (password, get_key())).hexdigest()<br />
</code></p>
<p>You may argue that this example doesn&#8217;t make much sense, and I must agree, but describes well enough the problem.</p>
<p>As you can see in the previous code we have 2 modules, secret.py and models.py both importing code from each other. What you should do in this case is move one of the imported bits onto a new module, for example:</p>
<p>secret.py<br />
<code lang="python"><br />
def get_key():<br />
    return '53cr37 k3y'<br />
</code></p>
<p>users.py<br />
<code lang="python"><br />
from .models import User</p>
<p>def get_user_model():<br />
    return User<br />
</code></p>
<p>Now models.py imports from secret.py and the new file users.py imports from models.py, while secret.py doesn&#8217;t import code at all. It could be described as:<br />
<code><br />
users &lt; models &lt; secret<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/06/11/avoiding-circular-imports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First post</title>
		<link>http://blog.mourino.net/2011/06/11/hello-world/</link>
		<comments>http://blog.mourino.net/2011/06/11/hello-world/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 14:31:12 +0000</pubDate>
		<dc:creator>tuxie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http:/?p=1</guid>
		<description><![CDATA[Past this point all you&#8217;ll find is an IndexError.]]></description>
			<content:encoded><![CDATA[<p>Past this point all you&#8217;ll find is an IndexError.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mourino.net/2011/06/11/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

