<?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>a very omarish blog.</title>
	<atom:link href="http://blog.omarish.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.omarish.com</link>
	<description>My name is Omar Bohsali. I like to build things.</description>
	<lastBuildDate>Mon, 04 Mar 2013 18:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Intelligent or Diligent?</title>
		<link>http://blog.omarish.com/2013/03/iq-and-productivity/</link>
		<comments>http://blog.omarish.com/2013/03/iq-and-productivity/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 18:19:48 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.omarish.com/?p=339</guid>
		<description><![CDATA[Is it better to be intelligent or diligent? Put differently, should you wish that you had a higher IQ, or should you make sure you spend your time in a productive way? I&#8217;ve spent some time thinking through this and found a simple metaphor to financial investments. IQ is your principal investment and your ability to [...]]]></description>
			<content:encoded><![CDATA[<p>Is it better to be intelligent or diligent? Put differently, should you wish that you had a higher IQ, or should you make sure you spend your time in a productive way?</p>
<p>I&#8217;ve spent some time thinking through this and found a simple metaphor to financial investments. IQ is your principal investment and your ability to work hard is the investment&#8217;s growth rate.</p>
<p>Let&#8217;s compare two simple scenarios, both done over a 20 year time horizon:</p>
<p><span style="text-decoration: underline;">Scenario 1:</span> Intelligent &#8211; invest $10,000 at a 5% growth rate. You&#8217;re born with a high IQ and learn at a normal pace, growing intellectually 5% each year.</p>
<p><span style="text-decoration: underline;">Scenario 2:</span> Diligent &#8211; invest $2,500 at a 20% growth rate. You&#8217;re born with an average IQ (1/4 of that in Scenario 1) but are focused on self-growth so you spend your spare time doing things that enhance your abilities.</p>
<p>At the end of 20 years in scenario 1, your investment will be worth $26,533. At the end of 20 years in scenario 2, you end up with $95,844, which is $69,311 more than the final value of scenario 1.</p>
<p>Obviously the two are not zero sum so it would be optimal to have high IQ and high productivity, but in absence of both I think working hard regardless of where you start is the winning strategy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2013/03/iq-and-productivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tornado</title>
		<link>http://blog.omarish.com/2013/02/starting-to-use-tornado/</link>
		<comments>http://blog.omarish.com/2013/02/starting-to-use-tornado/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 01:55:01 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.omarish.com/?p=325</guid>
		<description><![CDATA[I&#8217;m starting to use tornado as my go-to framework for python web projects. After being a django user for 5+ years this is a pretty big  change for me. I like that it&#8217;s simple and gets in your way as little as possible. There&#8217;s something nice to be able to run a whole web application in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tornadoweb.org/static/tornado.png" alt="" /></p>
<p>I&#8217;m starting to use <a href="http://www.tornadoweb.org/">tornado</a> as my go-to framework for python web projects. After being a django user for 5+ years this is a pretty big  change for me. I like that it&#8217;s simple and gets in your way as little as possible. There&#8217;s something nice to be able to run a whole web application in a single file. Also being able to use python functions in the template layer saves so much time (bye bye <a href="https://docs.djangoproject.com/en/dev/howto/custom-template-tags/">templatetags</a>!).</p>
<p>Django is a great framework for larger projects that require certain features like an ORM, user auth, email. Anything that it doesn&#8217;t come with out of the box is available as a plugin ..</p>
<pre>➜  ~  pip search django | wc -l
    3696</pre>
<p>I imagine there are plenty of useful Tornado plugins that I&#8217;ll start using as the need arises. For example, I still haven&#8217;t found a nice way to handle forms. I&#8217;m pretty used to using django&#8217;s is_clean() and ModelForm patterns. WTForms seems like a good option that I&#8217;ll look into soon enough. Elixir looks like a cool ORM (thanks for the tip, <a href="http://bob.poekert.com/">Bob</a>).</p>
<p>Do you have any favorite open source tornado projects?</p>
<p>It&#8217;ll probably be a while before (if) we switch Priceonomics over to Tornado, but the temptation to do a full re-write sure is tempting <img src='http://blog.omarish.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2013/02/starting-to-use-tornado/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>App.net Contributions Over Time</title>
		<link>http://blog.omarish.com/2012/08/app-net-contributions-over-time/</link>
		<comments>http://blog.omarish.com/2012/08/app-net-contributions-over-time/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 15:21:21 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.omarish.com/?p=320</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.omarish.com/wp-content/uploads/2012/04/App_net-latest.png"><img class="aligncenter size-full wp-image-323" title="App.net Contributions" src="http://blog.omarish.com/wp-content/uploads/2012/04/App_net-latest.png" alt="" width="1684" height="915" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2012/08/app-net-contributions-over-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Susan Cain: The power of introverts</title>
		<link>http://blog.omarish.com/2012/04/susan-cain-the-power-of-introverts/</link>
		<comments>http://blog.omarish.com/2012/04/susan-cain-the-power-of-introverts/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 21:07:22 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=300</guid>
		<description><![CDATA[Great TED talk by Susan Cain on the power of introverts. For more, have a look at her recent book, Quiet: The Power of Introverts in a World That Can&#8217;t Stop Talking.]]></description>
			<content:encoded><![CDATA[<p>Great TED talk by Susan Cain on the power of introverts.</p>
<p><object width="526" height="374" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="bgColor" value="#ffffff" /><param name="flashvars" value="vu=http://video.ted.com/talk/stream/2012/Blank/SusanCain_2012-320k.mp4&amp;su=http://images.ted.com/images/ted/tedindex/embed-posters/SusanCain_2012-embed.jpg&amp;vw=512&amp;vh=288&amp;ap=0&amp;ti=1377&amp;lang=&amp;introDuration=15330&amp;adDuration=4000&amp;postAdDuration=830&amp;adKeys=talk=susan_cain_the_power_of_introverts;year=2012;theme=how_the_mind_works;event=TED2012;tag=business;tag=culture;tag=psychology;&amp;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><param name="src" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" /><param name="pluginspace" value="http://www.macromedia.com/go/getflashplayer" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><embed width="526" height="374" type="application/x-shockwave-flash" src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" allowFullScreen="true" allowScriptAccess="always" wmode="transparent" bgColor="#ffffff" flashvars="vu=http://video.ted.com/talk/stream/2012/Blank/SusanCain_2012-320k.mp4&amp;su=http://images.ted.com/images/ted/tedindex/embed-posters/SusanCain_2012-embed.jpg&amp;vw=512&amp;vh=288&amp;ap=0&amp;ti=1377&amp;lang=&amp;introDuration=15330&amp;adDuration=4000&amp;postAdDuration=830&amp;adKeys=talk=susan_cain_the_power_of_introverts;year=2012;theme=how_the_mind_works;event=TED2012;tag=business;tag=culture;tag=psychology;&amp;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" pluginspace="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" allowscriptaccess="always" /></object></p>
<p>For more, have a look at her recent book, <a href="http://www.amazon.com/gp/product/0307352145/ref=as_li_ss_tl?ie=UTF8&#038;tag=omarishcom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0307352145">Quiet: The Power of Introverts in a World That Can&#8217;t Stop Talking</a><img src="http://www.assoc-amazon.com/e/ir?t=omarishcom-20&#038;l=as2&#038;o=1&#038;a=0307352145" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2012/04/susan-cain-the-power-of-introverts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On The Edge of Chaos</title>
		<link>http://blog.omarish.com/2011/10/on-the-edge-of-chaos/</link>
		<comments>http://blog.omarish.com/2011/10/on-the-edge-of-chaos/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 18:59:17 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[ideas]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=285</guid>
		<description><![CDATA[via Creative Emergence]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" title="Chaos" src="http://creativeemergence.typepad.com/.a/6a00d8345599ab69e201310f99be1c970c-800wi" alt="On the edge of chaos." width="800" height="623" /><br />
<br />
<i><a href="http://creativeemergence.typepad.com/">via Creative Emergence</a></i></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/10/on-the-edge-of-chaos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dawson on &#8220;The Gains of Drudgery&#8221;</title>
		<link>http://blog.omarish.com/2011/09/dawson-on-the-gains-of-drudgery/</link>
		<comments>http://blog.omarish.com/2011/09/dawson-on-the-gains-of-drudgery/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 05:28:34 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[links]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=273</guid>
		<description><![CDATA[Came across an interesting post this morning that related to some thoughts I&#8217;ve been having about my own personal work ethic. It takes from a piece written by William James Dawson, called The Gains of Drudgery. I&#8217;ll paste the first paragraph here, the rest is after the fold. By drudgery, I mean work that in [...]]]></description>
			<content:encoded><![CDATA[<p>Came across an <a href="http://artofmanliness.com/2011/09/24/manvotional-the-gains-of-drudgery/">interesting post</a> this morning that related to some thoughts I&#8217;ve been having about my own personal work ethic. It takes from a piece written by William James Dawson, called <em>The Gains of Drudgery</em>. I&#8217;ll paste the first paragraph here, the rest is after the fold.</p>
<blockquote><p>By drudgery, I mean work that in itself is not pleasant, that has no immediate effect in stimulating our best powers, and that only remotely serves the purpose of our general advancement. Such a definition may not be perfect, but it expresses with reasonable accuracy what we usually understand by the term.</p></blockquote>
<p><span id="more-273"></span></p>
<p>Now, if this is what we mean by drudgery, it is clear that we are all drudges. We all have to do many things, day by day, which we would rather not do. Even in the callings that seem to present the most perfect correspondence between gifts and work, such as those of the writer or the artist, drudgery dogs the heels of all progress…We show some perception of these facts in our common sayings, that easy writing makes hard reading, and what costs a man little is usually worth little. But few of us have any adequate sense of the immense toil which lies behind the brilliant successes of the great artist or famous writer. And the same thing might be said of the lives of great statesmen, politicians, reformers, merchants, and memorable men in all walks of life. Examine such lives, and the amount of prolonged toil which lies behind all the glitter of public fame is enormous, and to the indolent even appalling. If any man of the Elizabethan period gives the impression of having achieved great things with a certain airy ease and instinctive facility of touch, it is Walter Raleigh. Yet it was of Raleigh that Elizabeth said, “he could toil terribly.” The same thing may be said of every great man, so that it is small wonder that we have learned to believe that genius itself is simply an infinite capacity for taking pains.</p>
<p>When a man grumbles about the drudgery of his lot, then I am entitled to conclude that he has not learned the discipline of work, and that it is native indolence rather than suppressed genius which chafes against the limitations of his environment. Browning, in his poem of The Statue and the Bust, has laid down the doctrine that it is a man’s wisdom to contend to the uttermost even for the meanest prize that may be within his reach, because by such strenuous contention manhood grows, and by the lack of it manhood decays.</p>
<p>The clerk who does not strive to be the best clerk in the office, the carpenter who is not emulous of being the best carpenter in the workshop, is not likely to achieve excellence in any other pursuit for which he imagines his superior talents better fitted….I have little faith in the youth who is always crying out against his condition, and telling an incredulous world what great things he could do if his lot were different. The boast of general talents for everything usually resolves itself into particular talents for nothing. The incompetent clerk, in nine cases out of ten, would be equally incompetent as writer, artist, or speaker. If I were adjured to help a youth to some sphere supposed to be better suited to his gifts, I should first of all need to be convinced that he had performed faithfully the duties of the inferior sphere in which he found himself. The superior talent always shows itself in the superior performance of inferior duties. It is the man who is faithful in little things to whom there is given authority over larger things. He who has never learned the art of drudgery is never likely to acquire the faculty of great and memorable work, since the greater a man is, the greater is his power of drudgery.</p>
<p>But the gains of drudgery are not seen only in the solid successes of life, but in their effect upon the man himself. Let me take in illustration a not infrequent case. Suppose a man gives up his youth to the struggle for some coveted degree, some honour or award of the scholarly life. It is very possible that when he obtains that for which he has struggled, he may find that the joy of possession is not so great as the joy of the strife. It is part of the discipline of life that we should be educated by disillusion; we press onward to some shining summit, only to find that it is but a bastion thrown out by a greater mountain, which we did not see, and that the real summit lies far beyond us still. But are we the worse for the struggle? No; we are manifestly the better, for by whatever illusion we have been led onward, it is at least clear that without the illusion we should not have stood as high as we do. So a man may either fail or succeed in gaining the prize which he covets; but he cannot help being the gainer in himself. He has not attained, but he has fitted himself for attaining. It is better to fail in achieving a great thing than to succeed in achieving a little one, and the struggle that fails is, in any case, to be preferred to the stolidity which never aspires. And why? Because the struggle is sure to develop certain great and noble qualities in ourselves. Thus, though such a man may not gain the prize he sought, he has gained a command over his chance desires, a discipline of thought, a power of patient application, a steadiness of will and purpose, which will stand him in good stead throughout whatever toils his life may know in the hidden years which lie before it. And even if he gain the prize he sought, the real prize is found not in a degree, a certificate, a brief taste of applause on a commemoration day, but in the deeper strength of soul, the wider range of wisdom, which the long discipline of unflagging effort has taught him. So true is this, that Lessing, who was among the wisest of thinkers, said, that if he had to choose between the attainment of truth and the search for truth, he would prefer the latter. The true gain is always in the struggle, not the prize. What we become must always rank as a far higher question than what we get.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/09/dawson-on-the-gains-of-drudgery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting Article from good.is on the &#8220;Information Arms Race&#8221;</title>
		<link>http://blog.omarish.com/2011/09/interesting-article-from-good-is-on-the-information-arms-race/</link>
		<comments>http://blog.omarish.com/2011/09/interesting-article-from-good-is-on-the-information-arms-race/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 21:42:46 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=261</guid>
		<description><![CDATA[[...] The rise of microtargeting is a function of new logarithms—and computers fast enough to process them—that are able to capture all this trash and turn it into gold. Over the years, the data-mining industry has become adept at recycling information about the websites we visit and the products we buy. Rumor has it that [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>[...] The rise of microtargeting is a function of new logarithms—and computers fast enough to process them—that are able to capture all this trash and turn it into gold. Over the years, the data-mining industry has become adept at recycling information about the websites we visit and the products we buy. Rumor has it that some high-end companies, including Omaha Steaks, can now make more money by selling their customer pedigrees to data-mining firms than they can from selling their product</p></blockquote>
<p>via <a href="http://www.good.is/post/the-information-arms-race">good.is</a>.</p>
<p>Interesting read. It&#8217;s a bit higher-level than I would have hoped, but it does a great job introducing some of the many ways that organizations are leveraging seemingly minute, uncorrelated data in ways that will add values to organizations.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/09/interesting-article-from-good-is-on-the-information-arms-race/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There exists a continuous rail service that goes between Moscow &amp; Vladivostock. It spans 9,259km.</title>
		<link>http://blog.omarish.com/2011/09/there-exists-a-continuous-rail-service-that-goes-from-moscow-to-vladivostock-it-spans-9259km/</link>
		<comments>http://blog.omarish.com/2011/09/there-exists-a-continuous-rail-service-that-goes-from-moscow-to-vladivostock-it-spans-9259km/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 21:36:31 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[quotes]]></category>
		<category><![CDATA[travel]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=249</guid>
		<description><![CDATA[And Google Maps knows about it. In fact, it recommends it if you ask for Public Transit directions between the aforementioned cities. View Larger Map Brilliant. In the words of Kurt Vonnegut, &#8221;bizarre travel plans are dancing lessons from God.&#8221; More info on the railway on Wikipedia.]]></description>
			<content:encoded><![CDATA[<p>And Google Maps knows about it. In fact, it recommends it if you ask for Public Transit directions between the aforementioned cities.</p>
<p><iframe width="600" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Moscow,+Russia&amp;daddr=Vladivostok,+Primorskiy+kray,+Russia&amp;hl=en&amp;geocode=FQrEUgMd4f89AinJsNRz_Eq1RjFMz1dXzNZEPQ%3BFUQfkgIddP_cBymF1ElSupyzXzE1fpbd1ARnGA&amp;sll=49.61071,84.726563&amp;sspn=152.500759,302.695312&amp;vpsrc=6&amp;dirflg=r&amp;ttype=dep&amp;date=09%2F27%2F11&amp;time=9:10pm&amp;noexp=0&amp;noal=0&amp;sort=def&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;start=0&amp;ll=50.736455,86.484375&amp;spn=89.240391,210.585938&amp;z=2&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Moscow,+Russia&amp;daddr=Vladivostok,+Primorskiy+kray,+Russia&amp;hl=en&amp;geocode=FQrEUgMd4f89AinJsNRz_Eq1RjFMz1dXzNZEPQ%3BFUQfkgIddP_cBymF1ElSupyzXzE1fpbd1ARnGA&amp;sll=49.61071,84.726563&amp;sspn=152.500759,302.695312&amp;vpsrc=6&amp;dirflg=r&amp;ttype=dep&amp;date=09%2F27%2F11&amp;time=9:10pm&amp;noexp=0&amp;noal=0&amp;sort=def&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;start=0&amp;ll=50.736455,86.484375&amp;spn=89.240391,210.585938&amp;z=2" style="color:#0000FF;text-align:left">View Larger Map</a></small></p>
<p>Brilliant. In the words of Kurt Vonnegut, &#8221;bizarre travel plans are dancing lessons from God.&#8221; More info on the railway on <a href="http://en.wikipedia.org/wiki/Trans-Siberian_Railway">Wikipedia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/09/there-exists-a-continuous-rail-service-that-goes-from-moscow-to-vladivostock-it-spans-9259km/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thin Python Cache Decorator</title>
		<link>http://blog.omarish.com/2011/09/thin-python-cache-decorator/</link>
		<comments>http://blog.omarish.com/2011/09/thin-python-cache-decorator/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 06:25:54 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=251</guid>
		<description><![CDATA[def cache&#40;func&#41;: &#34;&#34;&#34; A thin middleware that caches based on function name and arguments. &#34;&#34;&#34; def _inner&#40;*args, **kwargs&#41;: a_str = &#34;&#38;amp;&#34;.join&#40;&#91;str&#40;a&#41; or None for a in args&#93;&#41; kw_str = &#34;&#38;amp;&#34;.join&#40;&#91;&#34;%s=%s&#34; for key, val in kwargs.iteritems&#40;&#41;&#93;&#41; key_name = slugify&#40;&#34;%s:%s:%s&#34; % &#40;func.__name__, a_str, kw_str&#41;&#41; cached = cache.get&#40;key_name&#41; if not cached: cached = func&#40;*args, **kwargs&#41; cache.set&#40;key_name, cached&#41; return [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> cache<span style="color: black;">&#40;</span>func<span style="color: black;">&#41;</span>:
<span style="color: #483d8b;">&quot;&quot;&quot; A thin middleware that caches based on function name and arguments. &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> _inner<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
        a_str = <span style="color: #483d8b;">&quot;&amp;amp;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #008000;">None</span> <span style="color: #ff7700;font-weight:bold;">for</span> a <span style="color: #ff7700;font-weight:bold;">in</span> args<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        kw_str = <span style="color: #483d8b;">&quot;&amp;amp;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;%s=%s&quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key, val <span style="color: #ff7700;font-weight:bold;">in</span> kwargs.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        key_name = slugify<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s:%s:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>func.__name__, a_str, kw_str<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        cached = cache.<span style="color: black;">get</span><span style="color: black;">&#40;</span>key_name<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> cached:
            cached = func<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
            cache.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span>key_name, cached<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> cached
    <span style="color: #ff7700;font-weight:bold;">return</span> _inner</pre></div></div>

<p>This is designed with django in mind, but you can replace cache.set and cache.get with any cache cache framework of your choice. Also, I use slugify because many cache frameworks don&#8217;t like spaces in cache key names. <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#slugify">Slugify</a> replaces them with dashes.</p>
<p>Usage is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@cache
<span style="color: #ff7700;font-weight:bold;">def</span> expensive_method<span style="color: black;">&#40;</span>a,b=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>:
    ...</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/09/thin-python-cache-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Meditation</title>
		<link>http://blog.omarish.com/2011/09/on-meditation/</link>
		<comments>http://blog.omarish.com/2011/09/on-meditation/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 05:40:42 +0000</pubDate>
		<dc:creator>Omar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://omarish.com/?p=247</guid>
		<description><![CDATA[Third, meditation can help a man “be his own man” and feel comfortable in his own skin.  That constant stream of input we face each day often carries messages of what we’re supposed to think or feel.  Talking-heads spout off opinions as if they were facts. Advertisers try to convince us that buying such-and-such product [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Third, meditation can help a man “be his own man” and feel comfortable in his own skin.  That constant stream of input we face each day often carries messages of what we’re supposed to think or feel.  Talking-heads spout off opinions as if they were facts. Advertisers try to convince us that buying such-and-such product will make us feel more virile and manly. Meditation allows us to be alone with our own thoughts and discover what we really think about the world and ourselves.</p></blockquote>
<p>via <a href="http://artofmanliness.com/2011/09/07/a-primer-on-meditation/" target="_blank">Art of Manliness</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.omarish.com/2011/09/on-meditation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
