<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>No silver bullet</title>
	<atom:link href="http://facundoolano.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://facundoolano.wordpress.com</link>
	<description>facundoolano&#039;s rants on software development</description>
	<lastBuildDate>Tue, 14 Feb 2012 20:13:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='facundoolano.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>No silver bullet</title>
		<link>http://facundoolano.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://facundoolano.wordpress.com/osd.xml" title="No silver bullet" />
	<atom:link rel='hub' href='http://facundoolano.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Design patterns are no silver bullet</title>
		<link>http://facundoolano.wordpress.com/2012/02/12/design-patterns-are-no-silver-bullet-2/</link>
		<comments>http://facundoolano.wordpress.com/2012/02/12/design-patterns-are-no-silver-bullet-2/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 23:27:40 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GoF]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=196</guid>
		<description><![CDATA[Introduction Design patterns are probably one of the most misused and misunderstood programming techniques out there, and I argue this is because they&#8217;re studied out of the context in which they were conceived, or worse, because is assumed that this context never changes. This ultimately causes some particular set of patterns to be considered as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=196&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>Design patterns are probably one of the most misused and misunderstood programming techniques out there, and I argue this is because they&#8217;re studied out of the context in which they were conceived, or worse, because is assumed that this context never changes. This ultimately causes some particular set of patterns to be considered as a somewhat general tool whose use is a good programming practice.</p>
<p>This is not a critic to the Gang Of Four book[1], which I believe is one of the best books addressing object oriented software programming. The authors of that book were very aware of the consequences of the wrong use of the techniques they were introducing, and so they stated in its first pages[2].</p>
<p><strong>The context of a design pattern</strong></p>
<p>A design pattern is a general reusable solution to a commonly occurring problem <em>within a given context</em> in software design[3]; a set of descriptions of communicating objects and classes that are customized to solve a general design problem <em>in a particular context</em>[1]. Much of the misuse of design patterns comes from ignoring the context part.</p>
<p>If you change the problem domain or the programming paradigm or the language applied, then the set of appropriate patterns also changes. Indeed, since patterns are reusable, proved solutions to common programming problems, if a problem goes away by changing one of those variables, then the pattern <em>is no more</em>. Similarly, as some problems disappear, new ones arise when the context is changed[4]. A detailed study of this argument is made by Peter Norvig in his slides <em>Design patterns in dynamic languages</em>[5]. There he reaches the conclusion that most of GoF&#8217;s patterns are simpler or invisible in Lisp or Dylan.</p>
<p>Some argue that while the implementation gets simpler in some languages, the patterns are still there, so they&#8217;re still useful in the sense that they provide a vocabulary for programmers to describe the design. This might be true in some cases, but not in most. Usually, the higher the level of the language features, the higher the design abstractions and the lesser the need to refer to patterns that usually are foreign to the domain of those abstractions.</p>
<p>For example, in a statically typed language such as Java one might need to introduce interfaces or class hierarchies to achieve polymorphism, whereas in a dynamically typed one everything is polymorphic, the feature is taken for granted by the programmers and since it&#8217;s built-in, it&#8217;s not needed anymore to describe the design. Another example, more related to what&#8217;s commonly accepted as a design pattern, are iterators. In C++, when not using STL, one might find the need to introduce iterators as a part of the program design. In Java, where every standard data structure comes with its own iterator, one might use them a lot, but they stop being a part of the design worth discussing. Lastly, in Python, where the iterator implementation is completely hidden by the control and data structures, one might never even<em></em> see an iterator-related piece of code.</p>
<p><strong>Choosing a programming language</strong></p>
<p>This is part of a broader problem, but is directly related to the one I&#8217;m addressing here. Commonly in the software industry (but unfortunately in the academic community too) the people in charge of the design and architectural decisions on a software project don&#8217;t consider the language as a parameter of the solution. Sometimes they just pick the one they&#8217;re more comfortable with, but often this decision is made by management people based on non technical factors, such as programmer availability. Paul Graham puts it very clearly in one of his essays[6]:</p>
<blockquote><p>The pointy-haired boss miraculously combines two qualities that are common by themselves, but rarely seen together: (a) he knows nothing whatsoever about technology, and (b) he has very strong opinions about it.</p>
<p>Suppose, for example, you need to write a piece of software. The pointy-haired boss has no idea how this software has to work, and can&#8217;t tell one programming language from another, and yet he knows what language you should write it in. Exactly. He thinks you should write it in Java.</p>
<p>Why does he think this? Let&#8217;s take a look inside the brain of the pointy-haired boss. What he&#8217;s thinking is something like this. Java is a standard. I know it must be, because I read about it in the press all the time. Since it is a standard, I won&#8217;t get in trouble for using it. And that also means there will always be lots of Java programmers, so if the programmers working for me now quit, as programmers working for me mysteriously always do, I can easily replace them.</p>
<p>Well, this doesn&#8217;t sound that unreasonable. But it&#8217;s all based on one unspoken assumption, and that assumption turns out to be false. The pointy-haired boss believes that all programming languages are pretty much equivalent.</p></blockquote>
<p>I won&#8217;t get into how viable it is for the employee to disobey the manager&#8217;s bad decisions or how valid the manager&#8217;s point of view is. But as a programmer I too think that <em>you can&#8217;t let the suits make technical decisions for you.</em></p>
<p>When professors are closer to the the industry than to science, this too has an effect in their approach on teaching. They will tend to select as teaching languages those more widely used and (at least where I study) impose that choice thus creating a vicious cycle where the student never develops the need to compare and choose the language better suited for each job.</p>
<p>Be it by choice or by obligation, the  lack of the habit of choosing the programming language for each project causes the context to be considered as invariable. If the context is assumed static then the patterns for that context are the only patterns ever applied (ever taught for that matter), and so they end up looking universal or more relevant than others. The fact that most GoF patterns are never needed when programming in languages such as Python is seen by the naive as a shortcoming of the language rather than the opposite.</p>
<p><strong>Patterns smell funny</strong></p>
<p>Some programmers (specially those recently introduced to the technique) think that the more patterns it has, the better a design is. Or maybe a less extreme position is that given two ways of solving a problem, if one uses a known pattern, it&#8217;s better. This, I suppose, is based on the mentioned idea that patterns introduce a common vocabulary that lets them speak at a higher level. Also on the widespread belief that they are some sort <em>advanced programming technique</em>.</p>
<p>On the contrary, I think that a design that introduces much patterns smells funny, using the parlance of Refactoring (and Frank Zappa). Fowler and Beck argue that certain structures in code suggest the possibility of refactoring, and call those <em>bad smells</em>[7]; they don&#8217;t necessarily imply that the code is wrong, but it probably is.</p>
<p>In one hand, a pattern introduces foreign abstractions into the problem domain, increasing the design&#8217;s complexity. On the other, often making the design more flexible<em> in one specific direction</em>, it does so by sacrificing flexibility in the others. This tends to be a recipe for disaster when programmers believe they can predict how a system may evolve in the long run. Graham holds a similar position[6]:</p>
<blockquote><p>When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I&#8217;m using abstractions that aren&#8217;t powerful enough&#8211; often that I&#8217;m generating by hand the expansions of some macro that I need to write.</p></blockquote>
<p>He is off course, speaking from the standpoint of a Lisp programmer. Indeed, if we accept the idea that patterns  come to overcome the lack of  a certain language feature, most patterns are presumably needed because of the absence of macros. Still, there are many contexts in which using Lisp might not be the best technical decision, so we should apply a more general principle.</p>
<p>First we should abandon the idea that patterns improve the design of software, and use them only when they are really needed, this is, when there&#8217;s no simple solution to a problem with the current abstractions of our domain. Second, we should be aware of the proliferation of patterns, since it might be a sign that the language (or architecture) we are using is not the right tool for the job. <strong>And be prepared to leave the tool when necessary</strong>.</p>
<p>[1] Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Design Patterns: Elements of Reusable Object-Oriented software.<br />
[2] <em>Design patterns should not be applied indiscriminately. Often they achieve flexibility and variability by introducing additional levels of indirection, and that can complicate a design and/or cost you some performance. A design pattern should only be applied when the flexibility it affords is actually needed.</em><br />
[3] <a href="http://en.wikipedia.org/wiki/Software_design_pattern">Software design pattern</a>.<br />
[4] <em>Despite the book&#8217;s size, the design patterns in it capture only a fraction of what an expert might know. It doesn&#8217;t have any patterns dealing with concurrency or distributed</em> <em>programming or real-time programming. It doesn&#8217;t have any application domain-specific patterns. It doesn&#8217;t tell you how to build user interfaces, how to write device drivers, or how to use an object-oriented database. Each of these areas has its own patterns, and it would be worthwhile for someone to catalog those too.</em><br />
(&#8230;)<br />
<em>The choice of programming language is important because it influences one&#8217;s point of view. Our patterns assume Smalltalk/C++-level language features, and that choice determines what can and cannot be implemented easily. If we assumed procedural languages, we might have included design patterns called &#8220;Inheritance,&#8221; &#8220;Encapsulation,&#8221; and &#8220;Polymorphism.&#8221; Similarly, some of our patterns are supported directly by the less common object-oriented languages. CLOS has multi-methods, for example, which lessen the need for a pattern such as Visitor. In fact, there are enough differences between Smalltalk and C++ to mean that some patterns can be expressed more easily in one language than the other.</em><br />
[5] Peter Norvig, <a href="http://norvig.com/design-patterns/">Design Patterns in Dynamic Languages</a>.<br />
[6] Paul Graham, <a href="http://www.paulgraham.com/icad.html">Revenge of the Nerds</a>.<br />
[7] Martin Fowler, Refactoring: Improving the Design of Existing Code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/196/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/196/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/196/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=196&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2012/02/12/design-patterns-are-no-silver-bullet-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>First impressions on (Common) Lisp</title>
		<link>http://facundoolano.wordpress.com/2012/01/31/first-impressions-on-common-lisp/</link>
		<comments>http://facundoolano.wordpress.com/2012/01/31/first-impressions-on-common-lisp/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 04:12:06 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[common lisp]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[practical common lisp]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=225</guid>
		<description><![CDATA[Because it&#8217;s good to learn a new Language, because lispers seem convinced that it&#8217;s the most powerful language ever, and because it&#8217;s supposed to be some sort of programming religious experience[1], I decided to give Lisp a try. Since I had sincere hopes of end up using it on professional projects, after looking around I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=225&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because it&#8217;s good to learn a new Language, because lispers seem convinced that it&#8217;s the most powerful language ever, and because it&#8217;s supposed to be some sort of programming religious experience[1], I decided to give Lisp a try.</p>
<p>Since I had sincere hopes of end up using it on professional projects, after looking around I leaned towards Common Lisp, and particularly the book <em>Practical Common Lisp</em> by Peter Seibel. After the first 9 chapters, I&#8217;m somewhat disappointed. I&#8217;m guessing this is partly because of my high expectations and partly because most of lisp&#8217;s &#8220;cool&#8221; features are getting less and less uncommon as languages advance[2]. These are my first impressions.</p>
<p><strong>It&#8217;s not readable</strong>. Strangely enough I don&#8217;t mind all the parentheses nor the prefix notation; I get that they&#8217;re part of what makes Lisp so powerful and actually got used to it pretty quickly. Still, the language is overall pretty cryptic, even for things that could with no effort be a lot clearer (<em>t</em>/<em>nil</em> instead of <em>true</em>/<em>false</em>?). It might not be for experienced Lisp programmers, but, well, if it&#8217;s readable only for the experienced, then it&#8217;s not readable.</p>
<p>Some examples from the first chapters of the book:</p>
<p><pre class="brush: clojure; gutter: false; toolbar: false;">
(format t &quot;~{~{~a:~10t~a~%~}~%~}&quot; *db*)
</pre></p>
<p>and:</p>
<p><pre class="brush: clojure; gutter: false; toolbar: false;">
(defmacro where (&amp;rest clauses)
  `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))
</pre></p>
<p>Suddenly Perl isn&#8217;t looking that bad.</p>
<p><strong>The operators set is huge. </strong>That&#8217;s not good news for me. I like languages that have a small, orthogonal, easy-to-remember set of built-in operators, and good libraries built on top of them. This is the case of C and Python, and not of Lisp, which seems to have loads of built-in operators, between special operators, functions and macros. In the first chapters of the book, every bit of code introduces a couple of new ones. This not only makes it hard to keep track of them, but without seeing a thorough reference, I have no idea on what to <em>expect</em> to be available as a built-in and what I&#8217;m supposed to write myself.</p>
<p>From what I read, that small core is there somewhere, but at least this books makes it look like it&#8217;s too low level to get anything done with it, and instead uses the macros built on top of it.</p>
<p><strong>&#8230;and it&#8217;s not orthogonal.</strong> There seems to be way too many operators for the same purposes but with slightly different behaviors. The most evident case of this is the equality: <em>=</em>, <em>CHAR=</em>, <em>EQ</em>, <em>EQL</em>, <em>EQUAL</em>, and <em>EQUALP</em>. Seriously?</p>
<p><strong>&#8230;and some names are really, really bad.</strong> <em>MACROEXPAND-1</em>, <em>LET</em> and <em>LET*</em> (a common pattern for slightly different operators), <em>Y-OR-N-P</em>, etc.</p>
<p><strong>It&#8217;s not intuitive. </strong>As a consequence of the previous points, it gets really hard to guess my way through a piece of code; instead I have to look up most operators. Anytime a new operator was introduced in the book, it worked different from what I expected.<strong><br />
</strong></p>
<p><strong>Macros look promising.</strong> They certainly do; after catching just a glimpse of what can be done with them, macros look like a powerful tool that one can get quickly used to, and will miss in other languages. I particularly enjoy the way they&#8217;re used in the book as the driving technique to constantly refactor code, built bottom-up.<strong><br />
</strong></p>
<p>I&#8217;m aware that most of this issues would go away after some time using the language, but taking in account the downside of being not so widely used as other languages (meaning less documentation, less libraries, less users, etc.) so far it&#8217;s not looking like one I&#8217;d use for more than one or two projects. It might make sense for me to check out some other Lisp dialects, like Scheme or Clojure.</p>
<p>[1] Eric Raymond, <a href="http://www.catb.org/~esr/faqs/hacker-howto.html">How To Become A Hacker</a>.<br />
[2] Paul Graham, <a href="http://www.paulgraham.com/icad.html">Revenge Of The Nerds</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=225&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2012/01/31/first-impressions-on-common-lisp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>ifile.it API wrapper for Python</title>
		<link>http://facundoolano.wordpress.com/2012/01/02/ifile-it-api-wrapper-for-python/</link>
		<comments>http://facundoolano.wordpress.com/2012/01/02/ifile-it-api-wrapper-for-python/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 01:31:21 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ifile.it]]></category>
		<category><![CDATA[poster package]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=180</guid>
		<description><![CDATA[Here&#8217;s a Python wrapper I&#8217;ve made to upload files to the ifile.it servers using their API. The code sends the files using the poster package.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=180&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a Python wrapper I&#8217;ve made to upload files to the <a href="http://ifile.it/">ifile.it</a> servers using their <a href="http://code.google.com/p/ifileit/">API</a>. The code sends the files using the <a href="http://atlee.ca/software/poster/">poster package</a>.</p>
<p><pre class="brush: python; gutter: false; toolbar: false; wrap-lines: false;">
'''
Wrapper for the ifile.it API. Uses the poster api.
'''
import urllib2
import json
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib

class Ifileit(object):
    &quot;&quot;&quot; Wrapper class for the ifile.it API. &quot;&quot;&quot;
    
    UPOLOADED_FILE_URL = 'http://ifile.it/{ukey}'
    GET_UPLOAD_URL = 'http://ifile.it/api-fetch_upload_url.api'
    FETCH_API_KEY_URL = 'https://secure.ifile.it/api-fetch_apikey.api'
    PING_URL = 'http://ifile.it/api-ping.api'
    
    USER = ''
    PASSWORD = ''
    API_KEY = ''
    
    @classmethod
    def ping(cls):
        &quot;&quot;&quot; Returns True if the ifile.it server is up. &quot;&quot;&quot;
        
        response = cls._open_and_check(cls.PING_URL)
        return response.get('message', '') == 'pong'
    
    @classmethod
    def upload(cls, the_file):
        &quot;&quot;&quot; 
        Uploads the_file to the ifile.it server. It should be a file-like 
        object as required by poster. 
        &quot;&quot;&quot;
        
        #Needed by poster
        register_openers()
    
        post_data = {'Filedata' : the_file}
        post_data.update(cls._get_akey())
        datagen, headers = multipart_encode(post_data)
        
        request = urllib2.Request(cls._determine_upload_url(), 
                                                    datagen, headers)
        response = cls._open_and_check(request) 
        
        return cls.UPOLOADED_FILE_URL.format(ukey=response['ukey'])
    
    @classmethod
    def _determine_upload_url(cls):
        &quot;&quot;&quot; Gets the upload url from ifile.it API. &quot;&quot;&quot;
        
        return cls._open_and_check(cls.GET_UPLOAD_URL)['upload_url']
    
    @classmethod
    def _open_and_check(cls, url, data=None):
        &quot;&quot;&quot; 
        Opens the given url string or Request object and checks for the status
        parameter in the response.  If it's 'ok' returns a dict with the 
        response. otherwise raises IfileitApiError.
        
        Data should be a dictionary of POST arguments or None for a GET request.
        &quot;&quot;&quot;
        
        if data:
            data = urllib.urlencode(data)
        
        response = json.loads(urllib2.urlopen(url, data).read())
    
        if response['status'] != 'ok':
            raise IfileitApiError()
        
        return response
    
    @classmethod
    def _get_akey(cls):
        &quot;&quot;&quot; 
        If the user info is set, return the akey parameter for the POST API 
        calls. Otherwise returns an empty dict.
        &quot;&quot;&quot;
        
        if cls.USER and cls.PASSWORD:
            if not cls.API_KEY:
                response = cls._open_and_check(cls.FETCH_API_KEY_URL, 
                                               {'username' : cls.USER,
                                                'password' : cls.PASSWORD})
                cls.API_KEY = response['akey']
            
            return {'akey' : cls.API_KEY }
        
        return {}

class IfileitApiError(Exception):
    pass
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=180&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2012/01/02/ifile-it-api-wrapper-for-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>Python doesn’t treat me like I’m stupid</title>
		<link>http://facundoolano.wordpress.com/2011/11/03/python-doesn%e2%80%99t-treat-me-like-i%e2%80%99m-stupid/</link>
		<comments>http://facundoolano.wordpress.com/2011/11/03/python-doesn%e2%80%99t-treat-me-like-i%e2%80%99m-stupid/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 00:56:39 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=142</guid>
		<description><![CDATA[I don&#8217;t know how it works worldwide, but here in Argentina, most programmers not only use Java, but are also convinced that Java is the best language available if you can do without C/C++ efficiency, and therefore don&#8217;t bother to learn other languages. There&#8217;s no such concept as the &#8220;programmer toolbox&#8221;. And this is not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=142&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how it works worldwide, but here in Argentina, most programmers not only use Java, but are also convinced that Java is the best language available if you can do without C/C++ efficiency, and therefore don&#8217;t bother to learn other languages. There&#8217;s no such concept as the &#8220;programmer toolbox&#8221;. And this is not enforced only by the Software Industry (where non technical issues, like programmer availability come to play[1]), but sadly by a noticeable part of the academic community.</p>
<p>There&#8217;s a fact that I think makes this situation worse, and is that Java is a pretty dated language. What I mean is there are too different problems;  The first one is that programmers don&#8217;t bother to study other languages, so they use one tool to solve all problems. This is indeed a big issue, but more related to engineering and science than to programming. The second one is that there clearly are better languages to do what Java is supposed to do best: general purpose object oriented programming, and if you may, web applications back-end programming (which is what most programmers end up doing here). And those better languages are not obscure novelties as some like to suggest, but languages that have been around as long as Java has. Ruby and Python are the examples I&#8217;m most familiar with, but there are others, notably lisp.</p>
<p>I don&#8217;t know about any Java programmer that having tried a higher level language such as Python, wanted to go back to using Java. Bruce Eckel <span class="st">—</span>who wrote the books that are used for reference on Java and C++ in the programming courses that teach object-oriented programming at my college<span class="st">—</span>  noticed almost 10 years ago that sticking to Java was a huge waste of programmer&#8217;s time. A lot has been written about the advantages of Python over Java; a specially concise example are Eckel&#8217;s slides <em>Why I love Python</em>[2]<em>.</em> I also like a couple of screencasts by Sean Kelly, that focus more on web development (where Java is specially useless)[3].</p>
<p>I&#8217;m not interested in repeating all those points; most of them are related to language features like dynamic typing or native types. Some of them can be overcome by enhancing the language with new features, and this is what Java designers have been doing: they have been patching bad language design decisions ever since it first came out.</p>
<p>But there&#8217;s one particular aspect that I think defines <em>on principle</em> why Python is a better language than Java, and it won&#8217;t change no matter what features are added or removed. And it is the philosophy behind the language, the way they think about the programmer. Quoting Eckel: Java treats programmers like they are stupid, Python doesn&#8217;t.</p>
<p>Java design and libraries consistently make a huge effort making it difficult for a programmer to do <em>bad things</em>. If a feature was a potential means for a dumb programmer to make bad code, they would take away the feature altogether. And what&#8217;s worse, at times they even used it in the language implementation but prohibited the programmer to do so[4]. Paul Graham remarkably pointed this[5] as a potential flaw of Java before actually trying the language:</p>
<blockquote><p>Like the creators of sitcoms or junk food or package tours, Java&#8217;s designers were consciously designing a product for people not as smart as them.</p></blockquote>
<p>But this approach is an illusion; no matter how hard you try, you can&#8217;t <em>always </em>keep  bad programmers from writing bad programs. Java is a lousy replacement to the learning of algorithms and good programming practices.</p>
<p>The implications of this way of thinking are not limited to language features. The design decisions of the underlying language have a great effect on the programmer&#8217;s idiosyncrasy. It&#8217;s common to see Java designs and patterns that make an unnecessary effort in prohibiting potential bad uses of the resulting code, again not trusting the programmer&#8217;s judgment, wasting time and putting together very rigid structures.</p>
<p>The bottom line is that by making it hard for stupid programmers to do bad stuff, Java really gets in the way of smart programmers trying to make good programs. Python on the other hand, is focused on making it <em>extremely</em> easy to program well[6]. It gives you the choice; If you want to do crappy code is your responsibility.</p>
<p>[1] Paul Graham, <a href="http://www.paulgraham.com/icad.html">Revenge of the Nerds</a>.<br />
[2] Bruce Eckel, <a href="http://www.slideshare.net/didip/why-i-love-python">Why I love Python</a>. The points are extended in <a href="http://www.artima.com/intv/aboutme.html">these</a> interviews.<br />
[3] Sean Kelly, <a href="http://www.archive.org/details/SeanKellyRecoveryfromAddiction">Recovery from addiction</a>, <a href="http://video.google.com/videoplay?docid=6297126166376226181">Better web app development</a>.<br />
[4] Bruce Eckel, <a href="http://www.artima.com/intv/prodperf2.html">The Zen of Python</a>.<br />
[5] Paul Graham, <a href="http://www.paulgraham.com/javacover.html">Java&#8217;s Cover</a>.<br />
[6] Tim Peters, <a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Python</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=142&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/11/03/python-doesn%e2%80%99t-treat-me-like-i%e2%80%99m-stupid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>Check if the connection is secure in django with nginx and gunicorn</title>
		<link>http://facundoolano.wordpress.com/2011/10/16/check-if-the-connection-is-secure-in-django-with-nginx-and-gunicorn/</link>
		<comments>http://facundoolano.wordpress.com/2011/10/16/check-if-the-connection-is-secure-in-django-with-nginx-and-gunicorn/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 19:25:01 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[gunicorn]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=124</guid>
		<description><![CDATA[I&#8217;m serving a django application both through http and https, and since it uses Orbited (which listens to different ports for each type of connection), I needed a way to tell from my templates (from a template context processor to be exact) if the client was using http or https. Using just request.is_secure wouldn&#8217;t work, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=124&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m serving a django application both through http and https, and since it uses Orbited (which listens to different ports for each type of connection), I needed a way to tell from my templates (from a template context processor to be exact) if the client was using http or https.</p>
<p>Using just <a href="https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.is_secure" target="_blank">request.is_secure</a> wouldn&#8217;t work, since my project is served by gunicorn through a nginx proxy_pass, and by default, django can&#8217;t tell if its being served on a secure connection.</p>
<p>I don&#8217;t know if it&#8217;s the best way to do it, but this is how I managed to solve it. First I added the line:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
proxy_set_header X-Forwarded-Protocol https;
</pre></p>
<p>In the nginx configuration, on the server that uses ssl. Then, I modified the configuration of gunicorn, <a href="http://gunicorn.org/configure.html#secure-scheme-headers" target="_blank">as suggested</a> in the website, with the setting:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
secure_scheme_headers={'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-SSL': 'on'}
</pre></p>
<p>Lastly, from my context processor, I checked the request headers to tell if the connection is http or https:</p>
<p><pre class="brush: python; gutter: false; toolbar: false;">
def is_secure(request):
    return ('HTTP_X_FORWARDED_PROTOCOL' in request.META and 
        request.META['HTTP_X_FORWARDED_PROTOCOL'] == 'https')
</pre></p>
<p>And that&#8217;s it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=124&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/10/16/check-if-the-connection-is-secure-in-django-with-nginx-and-gunicorn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ is rubbish: some notes</title>
		<link>http://facundoolano.wordpress.com/2011/10/09/c-is-rubbish-some-notes/</link>
		<comments>http://facundoolano.wordpress.com/2011/10/09/c-is-rubbish-some-notes/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 01:47:46 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=72</guid>
		<description><![CDATA[Again, I&#8217;ve been forced to use C++. As in all my previous experiences with the language, it&#8217;s a major pain in the ass. I came to the conclusion that C++ is a programming language which no one can ever master; no matter how long you use it, after six months off of it you forget [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=72&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Again, I&#8217;ve been forced to use C++. As in all my previous experiences with the language, it&#8217;s a major pain in the ass. I came to the conclusion that C++ is a programming language which no one can ever master; no matter how long you use it, after six months off of it you forget everything you knew, because it&#8217;s just too big and completely counterintuitive.</p>
<p>Someday I might take the time to explain more profoundly why I hate (I&#8217;m using the word <em>hate</em> here) C++. For now I&#8217;ll just make some notes.</p>
<p><strong>I&#8217;ve been forced many times to use it, and no one could ever give me a good reason why</strong>. I believe such reason does not exist. If you want to do low level, system level or whatever you want to call it programming, C will do. While it lacks the facilities of more recent languages (and lisp), making it a doubtful choice for general purpose programming when efficiency is not the primary concern, I found C to be a really simple and clean language. It&#8217;s not at all hard to keep the primary feature set and libraries in your head.</p>
<p>C++ on the other hand is huge. You need to google constantly to do the most simple things, and what&#8217;s worse, you <em>should</em> do it, because there are a lot of things that just don&#8217;t work in the obvious ways. This is specially true when working with files.</p>
<p>All the advantages of object-orientedness quickly fade away when you see yourself dealing over and over with obscure syntax errors on classes that are a hundred lines long way before they do any real work. The real advantage of object oriented programming is the way it helps to think and structure your programs, and you don&#8217;t need classes or inheritance to accomplish that.</p>
<p><strong>C++ is so bad that makes Java look good.</strong> I don&#8217;t like Java. I think it&#8217;s too verbose and lacks several features I expect from a high level language, most of its <em>advanced</em> techniques (design patterns, reflection, xml frameworks) being just patches for those absences. But all in all, Java is a language that makes sense. C++ is not. </p>
<p><strong>It&#8217;s backwards compatible with C</strong>. Seriously Stroustrup? What on earth were you thinking?</p>
<p><strong>The compiler never helps</strong>. The error messages never make sense, and in most cases ignoring them is the healthier choice.</p>
<p><strong>C++ Strings suck</strong>. They suck so hard that they&#8217;re not a built-in type, they&#8217;re not even used in the libraries, so you have to use stuff like c_str().</p>
<p><strong>Streams suck</strong>. The syntax is weird, they&#8217;re just too many of them, I seem to recall there was some diamond inheritance weirdness going on over here&#8230; I&#8217;d rather stick to C files.</p>
<p><strong>STL sucks</strong>. The iterators are error-prone and tedious to use. You have to write a lot to use most of the methods of the containers, even for basic stuff, ending up with code like:</p>
<p><pre class="brush: cpp; gutter: false; toolbar: false;">
    for (map&lt;string, string&gt;::iterator it = myMap.begin(); it
            != myMap.end(); it++) {
        string key = it-&gt;first;
        string value = it-&gt;second;
        //...
    }
</pre></p>
<p><strong>Don&#8217;t even get me started on templates</strong>.</p>
<p><strong>Whether you use them or not, namespaces are a pain in the ass</strong>. If you do use them, the code gets confusing and annoying to write (and it&#8217;s easier to get compiler errors when you forget to specify the namespace). If you don&#8217;t use them in your code you still need to add the <em>using namespace std</em> bit everywhere or you get syntax errors that as usual don&#8217;t point the problem.</p>
<p><strong>Why are there references?</strong> One can&#8217;t consistently use either references or pointers, you are forced to mix them in certain contexts [1].</p>
<p><strong>The language is not consistent</strong>. An example: you instantiate classes in the stack like:</p>
<p><pre class="brush: cpp; gutter: false; toolbar: false;">
    MyClass myObject(arg1, arg2);
</pre></p>
<p>But what if your class has a constructor that takes no arguments? You might expect it to work like this:</p>
<p><pre class="brush: cpp; gutter: false; toolbar: false;">
    MyClass myObject();
</pre></p>
<p>But no, the <em>correct</em> way is omitting the parenthesis:</p>
<p><pre class="brush: cpp; gutter: false; toolbar: false;">
    MyClass myObject;
</pre></p>
<p>You might find yourself wondering for half an hour why your program won&#8217;t compile for things like this.</p>
<p><strong>Methods are not virtual by default</strong>. Premature optimization is the root of all evil. </p>
<p><strong>It&#8217;s copy-paste oriented</strong>. Code duplication is trouble. In C++, the standard way to code a class is  to copy all the method prototypes from the .h to the .cpp file, adding the MyClass:: bit. Even with just a couple of getters and setters, theres a whole lot of typing and copying. This is not only tedious, but one of the places where more errors occur. And remember, the compiler speaks its own language.</p>
<p><strong>You can&#8217;t refactor</strong>. Unit testing frameworks are awkward to use and setup. Creating a class and making it compile is so hard that most of the time you stick to add an if.</p>
<p>[1] <a href="http://www.paploo.net/programming/rant_01.shtml">http://www.paploo.net/programming/rant_01.shtml</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=72&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/10/09/c-is-rubbish-some-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>Open Library and the beauty of Python</title>
		<link>http://facundoolano.wordpress.com/2011/09/23/open-library-and-the-beauty-of-python/</link>
		<comments>http://facundoolano.wordpress.com/2011/09/23/open-library-and-the-beauty-of-python/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 12:47:27 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Open Library]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=44</guid>
		<description><![CDATA[I&#8217;m currently working on a books site, so I recently was in the need to interact with the Open Library&#8217;s APIs, specifically to retrieve a book&#8217;s cover based on its ISBN. The API puts a limit on how many cover requests an IP can do when looking by ISBN, but not if you look by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=44&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a books site, so I recently was in the need to interact with the <a href="http://openlibrary.org/developers/api">Open Library&#8217;s APIs</a>, specifically to retrieve a book&#8217;s cover based on its ISBN. The API puts a limit on how many cover requests an IP can do when looking by ISBN, but not if you look by the OLID (Open Library book id), so I decided to see how hard it was to get a book&#8217;s OLID once I got its ISBN.</p>
<p>It&#8217;s useful every once in a while to recall how hard it was to accomplish certain things on certain cluttered and rigid languages, and how easy it is when you can use something as powerful as Python<a id="refX" href="#X"><sup>1</sup></a>. Well, I ended up with something like:</p>
<p><pre class="brush: python; gutter: false; toolbar: false;">
import urllib2
import json

URL = 'http://openlibrary.org/api/books?bibkeys=ISBN:{isbn}&amp;format=json&amp;jscmd=data'

def get_olid(isbn):

    response = urllib2.urlopen(URL.format(isbn=isbn))
    js_dict = json.loads(response.read())
    key = 'ISBN:{isbn}'.format(isbn=isbn)
    if js_dict.has_key(key):
        return js_dict[key]['identifiers']['openlibrary'][0]
</pre></p>
<p>But the real beauty of Python this time was not the clearness or succinctness of the code, nor how useful the libraries were, but rather how easy it was to figure out how to use those libraries. Just checked the function signatures on the online documentation (I could have used the help function, but I like the docs better), and started to play with them on the shell until I got the result I expected. It even saved me the time to read thoroughly the OL reference, since I could see in the shell the contents of the response they are sending me on each call.</p>
<p><a id="X" href="#"></a>1. Yes, there are no silver bullets, but there are some real good bullets and some real bad bullets for each job, and I find Python to be a great general purpose bullet <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=44&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/09/23/open-library-and-the-beauty-of-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying a django project on nginx with gunicorn</title>
		<link>http://facundoolano.wordpress.com/2011/09/23/deploying-a-django-project-on-nginx-with-gunicorn/</link>
		<comments>http://facundoolano.wordpress.com/2011/09/23/deploying-a-django-project-on-nginx-with-gunicorn/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 03:22:41 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[gunicorn]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=14</guid>
		<description><![CDATA[Back when I started  working with django, one of the things that I found was sort of difficult to do was deploying a project, as suggested by the documentation, using apache and mod_wsgi (and previously with mod_python), at least when it came to serve several projects and its media at the same server. Doing all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=14&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Back when I started  working with django, one of the things that I found was sort of difficult to do was deploying a project, as <a href="https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/">suggested by the documentation</a>, using apache and mod_wsgi (and previously with mod_python), at least when it came to serve several projects and its media at the same server. Doing all those things with <a href="http://wiki.nginx.org/">nginx</a> and <a href="http://gunicorn.org/">gunicorn</a> is shockingly easy.</p>
<p>To add a new site on nginx I just touch a new file in the /etc/nginx/sites-enabled, with the contents:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
server {
    listen 80;
    server_name myserver.com;

    location / {
        proxy_pass http://127.0.0.1:8888;
    }
}
</pre></p>
<p>Now, supposing I want to have acces and error logs, and serve my site&#8217;s and the admin site&#8217;s media, I would add some lines to the server:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
access_log /var/www/django/myproject/access.log;
error_log /var/www/django/myproject/error.log;

location /media {
    root /var/www/django/myproject;
}

location /admin_media {
    alias /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media;
}
</pre></p>
<p>Where /media and /admin_media are the MEDIA_URL and ADMIN_MEDIA_PREFIX pointed by my settings.py. That is, I have a media folder in my project root directory and the admin media is served directly from the django installation.</p>
<p>To actually run my django site on http://127.0.0.1:8888 I create a gunicorn configuration file in my project root (where manage.py is located):</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
bind = &quot;127.0.0.1:8888&quot;
workers = 3
</pre></p>
<p>Assuming I named the file gunicorn.conf.py, gunicorn is run from the same directory doing:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
gunicorn_django -c gunicorn.conf.py -D
</pre></p>
<p>And that&#8217;s it.</p>
<p>When the code is updated, there&#8217;s no need to restart nginx; instead, gunicorn is restarted (not so prettily) with:</p>
<p><pre class="brush: plain; gutter: false; toolbar: false;">
kill -HUP &lt;main gunicorn process id&gt;
</pre></p>
<p>To serve multiple sites, just use differents ports (8888 in the example) in each one&#8217;s configuration file.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=14&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/09/23/deploying-a-django-project-on-nginx-with-gunicorn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello World</title>
		<link>http://facundoolano.wordpress.com/2011/09/22/hello-world-2/</link>
		<comments>http://facundoolano.wordpress.com/2011/09/22/hello-world-2/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 23:59:41 +0000</pubDate>
		<dc:creator>facundoolano</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://facundoolano.wordpress.com/?p=5</guid>
		<description><![CDATA[Now, this is a proper first post for my blog.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=5&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now, this is a proper first post for my blog.</p>
<p><pre class="brush: python; gutter: false; toolbar: false;">

print &quot;Hello blogging world!&quot;

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/facundoolano.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/facundoolano.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/facundoolano.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=facundoolano.wordpress.com&amp;blog=27767226&amp;post=5&amp;subd=facundoolano&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://facundoolano.wordpress.com/2011/09/22/hello-world-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb094e370f805c3a768de1b5f88c9dfd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">facundoolano</media:title>
		</media:content>
	</item>
	</channel>
</rss>
