<?xml version="1.0" encoding="UTF-8"?>
<feed
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:thr="http://purl.org/syndication/thread/1.0"
  xml:lang="en"
   >
  <title type="text">Daniel Nouri's Blog</title>
  <subtitle type="text">Adventures in hi-py</subtitle>

  <updated>2012-04-19T07:57:56Z</updated>
  <generator uri="http://blogofile.com/">Blogofile</generator>

  <link rel="alternate" type="text/html" href="http://danielnouri.org/notes" />
  <id>http://danielnouri.org/notes/feed/atom/</id>
  <link rel="self" type="application/atom+xml" href="http://danielnouri.org/notes/feed/atom/" />
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Climate Science - The Forbidden Topics]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2012/03/18/climate-science---the-forbidden-topics" />
    <id>http://danielnouri.org/notes/2012/03/18/climate-science---the-forbidden-topics</id>
    <updated>2012-03-18T14:00:00Z</updated>
    <published>2012-03-18T14:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Environment" />
    <category scheme="http://danielnouri.org/notes" term="Media" />
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Economy" />
    <summary type="html"><![CDATA[Climate Science - The Forbidden Topics]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2012/03/18/climate-science---the-forbidden-topics"><![CDATA[<div class="document">
<p>The following is an excerpt from the book <strong>Newspeak in the 21st
Century</strong> by David Edwards and David Cromwell of <a class="reference external" href="http://www.medialens.org/">Media Lens</a> published in 2009 by Pluto Press.  You
can find out <a class="reference external" href="http://www.medialens.org/bookshop/newspeak.php">more about the book and buy it here</a>.</p>
<hr class="docutils" />
<p>In 2006, an explosive front-page article in the <em>Independent</em> was
titled: <a class="reference external" href="http://www.independent.co.uk/environment/earths-ecological-debt-crisis-mankinds-borrowing-from-nature-hits-new-record-419279.html">&quot;Earth's ecological debt crisis: mankind's 'borrowing' from
nature hits new record.&quot;</a>
Martin Hickman, the newspaper's consumer affairs correspondent,
explained the results of a study featured in the story:</p>
<blockquote>
Evidence is mounting that rapid population growth and rising living
standards among the Earth's six billion inhabitants are putting an
intolerable strain on nature. For the first time an organisation — a
British think-tank — has sought to pinpoint how quickly man is using
the global resources of farming land, forests, fish, air and energy.</blockquote>
<p>By analysing data from the US academic group Global Footprint Network,
the think-tank has worked out the day each year when &quot;humanity starts
eating the planet&quot;.  Just like a company bound for bankruptcy, the
world started falling into ecological debt on October 9 that year.
Hickman explained: &quot;Problems, affecting everything from the seabed to
the stratosphere, range from carbon dioxide emissions to the
destruction of rainforests to the intensification of agriculture&quot;.
The crisis Hickman was describing could hardly be more serious:
humanity really is devouring the planet's life-support systems.  And
yet, typically for mainstream reporting, Hickman's analysis of the
causes behind the crisis was lost in unsupported, clichéd assertions
about &quot;rapid population growth&quot; and global &quot;rising living standards&quot;.
It is not just that &quot;mankind&quot; is &quot;'borrowing' from nature&quot;, as Hickman
claimed — the problem is rooted in a particular form of politics
controlled by wealthy elites.</p>
<p>Consider some of the key issues that <em>should</em> be at the heart of any
analysis of the looming catastrophe under discussion.  And consider
how inclusion of these issues is all but inconceivable in any
corporate newspaper.  These issues include:</p>
<ol class="arabic simple">
<li>The inherently biocidal, indeed psychopathic, logic of corporate
capitalism, structurally locked into generating maximised revenues
in minimum time at minimum cost.  As corporations are legally
<em>obliged</em> to maximise profits for shareholders, it is in fact
illegal for corporations to prioritise the welfare of people and
planet above private profits.  How can this simple fact of
entrenched corporate immorality not be front and centre in any
discussion of the industrial destruction of global life-support
systems?</li>
<li>The proven track record of big business in promoting catastrophic
consumption regardless of the consequences for human and
environmental health.  Whether disregarding the links between smoke
and cancer, junk food and obesity, Third World exploitation and
human suffering, oil exploration and lethal climate change, factory
farming and animal suffering, high salt consumption and illness,
corporations have consistently subordinated human and animal
welfare to short-term profits.</li>
<li>The relentless corporate lobbying of government to shape policies
to promote and protect private power.</li>
<li>The billions spent by the advertising industry to promote consumer
products and services, creating artificial 'needs', with children
an increasing target.</li>
<li>The collusion between powerful companies, investors and state
planners to install compliant dictators in client states around the
world.</li>
<li>The extensive use of loans and tied aid that ensnare poor nations in
webs of debt, ensuring that the West retains control of their
resources, markets and development.</li>
<li>The deployment of threats, bribery and armed force against
countries that attempt to pursue self-development, rather than
economic or strategic planning sanctioned by 'the international
community'.</li>
<li>The lethal role of the corporate media in promoting the
planet-devouring aims of private power.</li>
</ol>
<p>In a powerful book titled <em>The Decline of Capitalism</em>, economist Harry
Shutt explains how the current system ensures &quot;the wasteful diversion
of economic value added into the pockets of the small minority who
also (through their disproportionate wealth) exercise largely
unaccountable political power&quot;.  As Shutt rightly concludes, global
capitalism is &quot;too dysfunctional to be tolerable in a civilised
society&quot;.  Forty years ago, Martin Luther King called for &quot;a radical
restructuring of the architecture of American society&quot;.  He observed:
&quot;Global capitalism is much more concerned with expanding the domain of
market relations than with, say, establishing democracy, expanding
elementary education, or enhancing the social opportunities of
society's underdogs.&quot;  Indeed, King increasingly questioned capitalism
towards the end of his life: an aspect of his inspirational speeches
that tends to be ignored by establishment commentators who are
otherwise keen to praise him.  He associated domestic racial and
social inequality with US imperialism and social disparity abroad,
denouncing what he called &quot;the triple evils that are interrelated&quot;:
&quot;racism, economic exploitation, and war&quot;.  In one speech, he said:</p>
<blockquote>
A nation that will keep people in slavery for 244 years will
'thingify' them - make them things.  Therefore they will exploit
them, and poor people generally, economically.  And a nation that
will exploit economically will have to have foreign investments and
everything else, and will have to use its military might to protect
them.  All of these problems are tied together.</blockquote>
<p>King decried the &quot;evils that are rooted deeply in the whole structure
of society&quot; which had &quot;systematic rather than superficial flaws&quot;.  He
concluded that &quot;radical reconstruction of society itself is the real
issue to be faced&quot;.  But this deep problem, facing anyone hoping for
genuine action to combat the environmental crisis, is beyond the pale
of mainstream thought and public debate.</p>
<p>Ecologist Franz Broswimmer put it this way: &quot;At its very core, the
prevailing capitalist ethos and liberal word view of the modern
industrial era remain expansionary and imperial, involving a
calculated form of indifference to the social and ecological order.&quot;
The social insanity of this capitalist-fuelled expansionism leads to
'inverted priorities', to adopt the phrase used by the social
scientist Immanuel Wallerstein.  Hence, dominant features of the
economy include a trillion-dollar global arms budget, depletion of the
planet's natural resources and a deepening economic apartheid between
rich and poor.  These features are, in the words of eco-feminist Mary
Mellor: &quot;not the neutral decisions of a market; they are the
priorities of powerful people in powerful nations, mostly men whose
gender, race, and class interests drive the capitalist political
economic system and its worldwide system of accumulation and
deprivation&quot;.  It is simply not possible to understand, far less to
address, the crises facing us without understanding these issues.
But, of course, they are simply &quot;not of this world&quot; from the
perspective of mainstream corporate news reporting and commentary.</p>
<p>These are compelling, evidence-based arguments that are buried beneath
the complacent clichés favoured by even the best newspapers.  We have
sketched them only in the briefest detail here - the point is they are
hardly ever discussed at all.</p>
<p><a class="reference external" href="http://www.medialens.org/bookshop/newspeak.php"><img alt="Newspeak in the 21st Century" src="http://www.medialens.org/bookshop/media/newspeak_cover.jpg" /></a></p>
</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[How to write an add-on for the Kotti CMS]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/11/30/how-to-write-an-add-on-for-the-kotti-cms" />
    <id>http://danielnouri.org/notes/2011/11/30/how-to-write-an-add-on-for-the-kotti-cms</id>
    <updated>2011-11-30T14:00:00Z</updated>
    <published>2011-11-30T14:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Python" />
    <category scheme="http://danielnouri.org/notes" term="Web" />
    <category scheme="http://danielnouri.org/notes" term="Pyramid" />
    <category scheme="http://danielnouri.org/notes" term="Programming" />
    <summary type="html"><![CDATA[How to write an add-on for the Kotti CMS]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/11/30/how-to-write-an-add-on-for-the-kotti-cms"><![CDATA[<div class="document">
<p>This <strong>screencast</strong> guides you through the process of creating an
add-on for the <a class="reference external" href="http://pypi.python.org/pypi/Kotti">Kotti content management system</a>.  In this tutorial we'll <strong>write
a simple commenting system</strong> in 21 minutes in <em>real-time</em>.</p>
<p>You'll be guided through:</p>
<ul class="simple">
<li>Installing Kotti itself</li>
<li>Creating your own Kotti add-on (a Python package)</li>
<li>Configuring your Kotti site to include your add-on</li>
</ul>
<iframe width="640" height="480" src="http://www.youtube-nocookie.com/embed/GC3tw6Tli54?rel=0" frameborder="0" allowfullscreen></iframe><p>(Click here <a class="reference external" href="http://danielnouri.org/notes/2011/11/30/how-to-write-an-add-on-for-the-kotti-cms/">if you don't see the video</a>.)</p>
<div class="section" id="where-to-go-from-here">
<h3>Where to go from here</h3>
<ul class="simple">
<li>Read Kotti's <a class="reference external" href="http://kotti.readthedocs.org">documentation on readthedocs.org</a></li>
<li>Try Kotti on the <a class="reference external" href="http://kottidemo.danielnouri.org">demo server</a></li>
<li>Find Kotti <a class="reference external" href="http://pypi.python.org/pypi/Kotti">releases on PyPI</a></li>
<li>Find Kotti's <a class="reference external" href="http://github.com/Pylons/Kotti">source on GitHub</a></li>
<li>Look at the source of two Kotti add-ons:<ul>
<li><a class="reference external" href="https://github.com/dnouri/kotti_twitter">kotti_twitter</a> adds a Twitter box</li>
<li><a class="reference external" href="https://github.com/dnouri/kotti_calendar">kotti_calendar</a> adds a calendar content type and events</li>
</ul>
</li>
</ul>
</div>
</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Nato's war crimes in Sirte]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/10/03/nato's-war-crimes-in-sirte" />
    <id>http://danielnouri.org/notes/2011/10/03/nato's-war-crimes-in-sirte</id>
    <updated>2011-10-03T19:00:00Z</updated>
    <published>2011-10-03T19:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Libya" />
    <summary type="html"><![CDATA[Nato's war crimes in Sirte]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/10/03/nato's-war-crimes-in-sirte"><![CDATA[
<p>
The National Transitional Council of Libya (NTC) announced on Friday a two-day truce in the conflict over the war-torn city of Sirte, with the alleged intent of allowing civilians to escape safely. Since then, the NTC violated their self-imposed truce in the worst way possible, namely by <a href="http://www.theaustralian.com.au/the-red-cross-delivers-medical-kits-body-bags-to-the-besieged-town-of-sirte-libya/story-fn7ycml4-1226155730689">shelling the city's main hospital</a> <em>while</em> a team of the International Committee of the Red Cross (ICRC) was visiting.
</p>

<p>
Citizens fleeing Sirte on Saturday <a href="http://www.irishtimes.com/newspaper/breaking/2011/1002/breaking51.html">told Reuters</a> they knew nothing of the ceasefire, and that the shelling by NTC forces had not stopped. <a href="http://www.nato.int/cps/en/natolive/news_71994.htm">NATO also continued its attacks</a> on the city throughout the weekend.
</p>

<p>
The NTC's siege of Sirte started over a month ago, when rebel leaders said that they hoped to <a href="http://www.telegraph.co.uk/news/worldnews/africaandindianocean/libya/8728752/Libya-crisis-Rebel-leaders-hoping-to-starve-Gaddafi-stronghold-of-Sirte-into-submission.html">"starve into submission"</a> the city, and cut off the city's electricity, water and supplies. Since then, Sirte has also seen daily NATO bombings and heavy artillery shelling by NTC forces. People fleeing Sirte on Sunday <a href="http://www.bbc.co.uk/news/mobile/world-africa-15141177">said</a> that they had to leave because they were "caught between Nato bombings and shelling by rebels," with NATO "bombing at random and often hitting civilian buildings."
</p>

<p>
The Telegraph talked to people fleeing the city who said that Nato bombing and more recently, the attacks by the NTC had turned Sirte into a <a href="http://www.telegraph.co.uk/news/worldnews/africaandindianocean/libya/8802302/Gaddafi-loyalists-stranded-as-battle-for-Sirte-rages.html">"living hell"</a>. An elderly lady shouted: "They are killing our children. Why are they doing this? For what? Life was good before!"
</p>

<p>
A Pakistani migrant worker who fled Sirte <a href="http://www.google.com/hostednews/afp/article/ALeqM5gFzmkHhiUt9Svv9K7eIHFiRTE0Zw?docId=CNG.b8d311ad4223657f5870feb8a7ea6ba2.71">said</a>: "Nato struck one big building, Imarat Tamim, two days ago, with 12 or 13 bombs. [...] The whole building with nearly 600 flats is razed to the ground now."
</p>

<div style="float: right; padding-left: 1em;">
<a href="http://www.youtube.com/watch?v=tlZdlUX9u_c"><img src="http://danielnouri.org/media/sirte-hospital.png" title="Sirte hospital"></img></a>
</div>

<p>
<a href="http://danielnouri.org/notes/2011/09/17/nato-bombs-residential-buildings-in-libya/">Videos</a> that emerged out of Sirte a week ago show <a href="http://www.youtube.com/user/42alfatah#p/u">bombed out civilian homes, schools, a radio station, and a big number of casualties</a>, among them many women and children.
</p>

<p>
The ICRC described the humanitarian situation in Sirte as very critical after they visited the city's main Ibn Sina hospital last weekend. The aid workers reported that the hospital lacks water, electricity, and basic medical supplies. A <a href="http://in.reuters.com/article/2011/10/03/idINIndia-59668820111003">hospital doctor told Reuters</a> that he saw "a child of 14 die on the operating table because the power went out during the operation."
</p>

<p>
Moreover, the ICRC reported that the hospital was in fact attacked by the NTC while their team was visiting. Hichem Khadhraoui from the ICRC said that "several rockets landed within the hospital buildings while [they] were there." From the AFP report:
</p>

<blockquote>
<p>
After the ICRC team went in, National Transitional Council fighters launched a ferocious attack with rockets, anti-tank cannons and machine gun fire from a position less than a kilometre from the hospital. Gaddafi loyalists responded with mortar and sniper fire.
</p>
<p>
"We were surprised" that the attack took place while the Red Cross team was visiting, Mr Khadhraoui said, adding that they had "contacted all parties to say we were going in."
</p>
</blockquote>

<p>
<strong>Update</strong>: <a href="http://www.eurasiareview.com/05102011-libya-nato-and-ntc-forces-bomb-sirte-hospital/">According to the ICRC</a>, the hospital was hit various times by NATO and NTC bombings. <a href="http://www.presstv.ir/detail/203060.html">Press TV reports</a> on Oct 6 that NATO has carried out a new round of airstrikes against Libya, targeting a hospital in the northern town of Sirte.
</p>

<p>
Bill Van Auken writes in a recent article titled <a href="http://www.wsws.org/articles/2011/sep2011/liby-s29.shtml">Mass killing and humanitarian disaster in NATO siege of Sirte</a>:
</p>

<blockquote>
<p>
At the time, the US and its NATO allies claimed that intervention was required to halt a supposedly imminent massacre of civilians in the eastern city of Benghazi. Since then, the NATO bombings and the civil war fomented by the Western powers have claimed far more lives than were ever threatened by the Gaddafi regime.
</p>

<p>
Now this resolution is being invoked to justify NATO and the militias it supports carrying out in Sirte precisely the kind of murderous siege against a civilian population that the US and the European imperialist powers pretended to be preventing.
</p>
</blockquote>

<p>
<a href="https://twitter.com/#!/SeumasMilne/status/120439210300813313">Seumas Milne</a> described NATO's self-proclaimed "mission to protect civilians" in Libya a "charade."
</p>

<p>
TeleSUR's Diego Marín is in Sirte and reports that the Red Cross confirmed that the city's main hospital was bombed by NATO. He also witnessed how the NTC actively hindered the Red Cross from reaching the city:
</p>
<p>
<iframe width="640" height="360" src="http://www.youtube-nocookie.com/embed/DkWhNvu8EQM?rel=0" frameborder="0" allowfullscreen></iframe>
</p>

<p>
CNN has actual footage of the Red Cross convoy being forced by rebel gunfire to turn around:
</p>
<p>
<iframe width="640" height="360" src="http://www.youtube-nocookie.com/embed/AwmX07cgsd0?rel=0" frameborder="0" allowfullscreen></iframe>
</p>

<p>
  Further reading:
</p>
<ul>
  <li><a href="http://wsws.org/articles/2011/oct2011/liby-o04.shtml">NATO assault on Sirte inflicts more Libyan civilian casualties</a>, Patrick O'Connor (World Socialist Web Site), Oct 4</li>
  <li><a href="http://danielnouri.org/notes/category/libya/">Related blog posts</a></li>
</ul>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Nato bombs residential buildings in Libya]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/09/17/nato-bombs-residential-buildings-in-libya" />
    <id>http://danielnouri.org/notes/2011/09/17/nato-bombs-residential-buildings-in-libya</id>
    <updated>2011-09-17T23:00:00Z</updated>
    <published>2011-09-17T23:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Libya" />
    <summary type="html"><![CDATA[Nato bombs residential buildings in Libya]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/09/17/nato-bombs-residential-buildings-in-libya"><![CDATA[

    <p>
      Two videos uploaded today, Sep 17, show an apartment building
      and a hotel damaged by <a
      href="http://danielnouri.org/notes/2011/09/16/nato-continues-its-air-strikes-in-libya/">Nato
      bombing</a> in the Libyan city of Sirte:
    </p>

    <p>
      <iframe width="560" height="315" src="http://www.youtube-nocookie.com/embed/1KracDg6yac?rel=0" frameborder="0" allowfullscreen></iframe>

      <iframe width="560" height="315" src="http://www.youtube-nocookie.com/embed/PFu3ew5XT-Q?rel=0" frameborder="0" allowfullscreen></iframe>
    </p>

    <p>
      Another video from inside the besieged city of Sirte. The first
      part of this video is from Sep&nbsp;16, the second part starting
      at 1:51 is from Sep&nbsp;7:
    </p>

    <p>
       <em>Warning: graphic</em>
    </p>

    <p>
      <iframe width="560" height="315" src="http://www.youtube-nocookie.com/embed/jKrmfgLoQto?rel=0" frameborder="0" allowfullscreen></iframe>
    </p>

    <p>
      NATO writes in their report that they attacked on Sep 16 in
      Sirte: <em>5 command &amp; control nodes, 3 radars, 4 armed
      vehicles and 8 air missile systems</em>.
    </p>

    <p>
      It's <a
      href="http://www.foreignpolicyjournal.com/2011/08/13/natos-massacre-at-majer-libya/">not</a>
      the <a href="http://www.fair.org/articles/hammond-propaganda.html">first time</a> that <a
      href="http://stopwarcrimes.wordpress.com/2011/08/10/civilian-casualties-in-surman/">NATO
      attacked civilian buildings</a> to later explain that the
      buildings had been re-purposed militarily.
    </p>

    <p>
      <a
      href="http://af.reuters.com/article/libyaNews/idAFL5E7K22IO20110902?pageNumber=2">On
      Sep 2 already, Reuters reported</a> that electricity and water
      in the pro-Gaddafi town of Bani Walid had been cut off by NATO
      rebels.  Also, most pro-Gaddafi fighters in Bani Walid were
      reported to be civilian volunteers.
    </p>

    <p>
      <a href="http://www.youtube.com/watch?v=rxcTrPIyNPU">A Sep 16
      teleSUR report</a> explains how the NATO rebel siege and
      blockade of Bani Walid and Sirte have resulted in critical
      humanitarian situations.
    </p>

    <p>
      Sadly, <a
      href="http://members5.boardhost.com/medialens/msg/1316341487.html">hardly
      any of this information</a> makes it into our mainstream media.
      See also:
      <ul>
        <li>
          <a href="http://in.reuters.com/article/2011/09/17/idINIndia-59399720110917">NATO air strikes kill 354 in Sirte - Gaddafi's spokesman</a>, Alexander Dziadosz (Reuters), Sep 17
        </li>
        <li>
          <a href="http://www.reuters.com/article/2011/09/17/us-libya-sirte-scene-idUSTRE78G1ZN20110917">Civilians join Gaddafi fighters to defend hometown</a>, Alexander Dziadosz (Reuters), Sep 17
        </li>
        <li>
          <a href="http://news.xinhuanet.com/english2010/world/2011-09/18/c_131144896.htm">Libya conflict drags on in Bani Walid, Sirte</a>, Xinhua, Sep 17
        </li>
        <li>
          <a href="http://www.telegraph.co.uk/news/worldnews/africaandindianocean/libya/8728752/Libya-crisis-Rebel-leaders-hoping-to-starve-Gaddafi-stronghold-of-Sirte-into-submission.html">Rebel leaders hoping to starve Gaddafi stronghold of Sirte into submission</a>, Rob Crilly (The Telegraph), Aug 28
        </li>
        <li>
          <a href="http://rickrozoff.wordpress.com">STOP Nato - rickrozoff.wordpress.com</a>
        </li>
        <li>
          <a href="http://humanrightsinvestigations.org/2011/09/17/nato-bombing-sirte-guernica/">NATO bombing of Sirte: the new Guernica</a>, Human rights investigations, Sep 17
        </li>
      </ul>
    </p>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Nato continues its air strikes in Libya]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/09/16/nato-continues-its-air-strikes-in-libya" />
    <id>http://danielnouri.org/notes/2011/09/16/nato-continues-its-air-strikes-in-libya</id>
    <updated>2011-09-16T23:00:00Z</updated>
    <published>2011-09-16T23:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Libya" />
    <summary type="html"><![CDATA[Nato continues its air strikes in Libya]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/09/16/nato-continues-its-air-strikes-in-libya"><![CDATA[

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/js/highcharts.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/js/modules/exporting.js"></script>


<script type="text/javascript">
 
		var chart;
		jQuery(document).ready(function() {
			
			// define the options
			var options = {
 
				chart: {
					renderTo: 'highcharts-container'
				},
				
				title: {
					text: 'NATO sorties in Libya'
				},
				
				subtitle: {
					text: 'Source: www.nato.int'
				},
				
				xAxis: {
					type: 'datetime',
					tickInterval: 2 * 7 * 24 * 3600 * 1000, // two weeks
					tickWidth: 0,
					gridLineWidth: 1,
					labels: {
						align: 'left',
						x: 3,
						y: -3 
					}
				},
				
				yAxis: [{ // left y axis
					title: {
						text: null
					},
					labels: {
						align: 'left',
						x: 3,
						y: 16,
						formatter: function() {
							return Highcharts.numberFormat(this.value, 0);
						}
					},
					showFirstLabel: false
				}, { // right y axis
					linkedTo: 0,
					gridLineWidth: 0,
					opposite: true,
					title: {
						text: null
					},
					labels: {
						align: 'right',
						x: -3,
						y: 16,
						formatter: function() {
							return Highcharts.numberFormat(this.value, 0);
						}
					},
					showFirstLabel: false
				}],
				
				legend: {
					align: 'left',
					verticalAlign: 'top',
					y: 20,
					floating: true,
					borderWidth: 0
				},
				
				tooltip: {
					shared: true,
					crosshairs: true
				},
				
				plotOptions: {
					series: {
						cursor: 'pointer',
						point: {
							events: {
								click: function() {
									hs.htmlExpand(null, { 
										pageOrigin: {
											x: this.pageX, 
											y: this.pageY
										},
										headingText: this.series.name,
										maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) +':<br/> '+ 
											this.y +' visits',
										width: 200
									});
								}
							}
						},
						marker: {
							lineWidth: 1
						}
					}
				},
				
				series: [{
					name: 'All sorties'
				}, {
					name: 'Strike sorties'
				}]
			}
			
			// Load data asynchronously using jQuery. On success, add the data
			// to the options and initiate the chart.
			// http://api.jquery.com/jQuery.get/
			jQuery.get('http://danielnouri.org/files/nato-sorties-libya.tsv', null, function(tsv) {
				var lines = [],
					date,
					
					// set up the two data series
					allSorties = [],
					strikeSorties = [];
					
				try {
				// split the data return into lines and parse them
				tsv = tsv.split(/\n/g);
				jQuery.each(tsv, function(i, line) {
                  if (i == 0) return;
 
                  line = line.split(/\t/);
                  date = Date.parse(line[0] +' UTC');
						
                  allSorties.push([
                    date,
                    parseInt(line[1], 10)
                  ]);
                  
                  strikeSorties.push([
                    date, 
                    parseInt(line[2], 10)
                  ]);
				});
				} catch (e) { alert(e.message) }

				options.series[0].data = allSorties;
				options.series[1].data = strikeSorties;
				
				chart = new Highcharts.Chart(options);
			});
			
		});
	</script>

    
    <p>
      Despite the declared <a
      href="http://landdestroyer.blogspot.com/2011/09/libya-v-day-3-weeks.html">"victory"</a>
      and the fall of the Gaddafi regime in late August, NATO
      continues to conduct daily air strikes across Libya.
    </p>

    <div id="highcharts-container">
    </div>

    <p>
      "All sorties" is the daily number of individual aircraft that
      NATO flew into Libya.  "Strike sorties" is the number of
      warplanes that drop bombs and missiles.
    </p>

    <p>
      Since the beginning of the NATO operation on Mar 31, a total of
      22,817 sorties, including 8,560 strike sorties, have been
      conducted.
    </p>

    <p>
      The chart is based on data published by NATO, and it will be
      regularly updated.  You may download and reuse the chart freely
      using the download icon in the top-right corner.  You may also
      want to download the <a
      href="http://danielnouri.org/files/nato-sorties-libya.tsv">raw
      data in TSV format</a>.
    </p>

    <p>
      Related: here is a map of sixteen cities that NATO attacked
      <strong>between Aug 22 and Sep 16</strong>:
    </p>

    <iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?msa=0&amp;msid=213967417765534898093.0004ad124ea1e4d9f7b77&amp;ie=UTF8&amp;t=m&amp;vpsrc=6&amp;ll=29.554345,16.940918&amp;spn=9.16795,14.0625&amp;z=6&amp;output=embed"></iframe>

    <p>
      I'm also hosting an <a
      href="http://danielnouri.org/jana-news.ly/">archive of 854
      articles</a> from the Libyan state news agency's website
      www.jana-news.ly, some of which contain detailed accounts of
      Nato attacks.  The site was <a href="http://jana-news.ly">shut
      down</a> last week.
    </p>

    <p>
      <strong>Update Sep 16:</strong> <a
      href="http://twitter.com/drebha">@drebha</a> sent me this link
      to <a
      href="https://docs.google.com/spreadsheet/ccc?authkey=CPeKjPMB&key=0Aq-FnOoJcl-ndG9KUHFFNDgyNENWRW5TTUl6QnFDcXc&hl=en_US&authkey=CPeKjPMB#gid=3">an
      online spreadsheet that also has the number of sorties, along
      with many more details</a> extracted from NATO's documents.
    </p>

    <p>
      See also: <a href="http://danielnouri.org/notes/2011/09/17/nato-bombs-residential-buildings-in-libya/">Nato bombs residential buildings in Libya</a>
    </p>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Cluster bombs hypocrisy]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/04/17/cluster-bombs-hypocrisy" />
    <id>http://danielnouri.org/notes/2011/04/17/cluster-bombs-hypocrisy</id>
    <updated>2011-04-17T12:00:00Z</updated>
    <published>2011-04-17T12:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Libya" />
    <summary type="html"><![CDATA[Cluster bombs hypocrisy]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/04/17/cluster-bombs-hypocrisy"><![CDATA[<div class="document">
<div class="figure">
<img alt="http://danielnouri.org/media/Stop_cluster_bombs_march.jpg" src="http://danielnouri.org/media/Stop_cluster_bombs_march.jpg" />
<p class="caption">Ban Advocates from Afghanistan and Ethiopia demonstrating outside
of the Convention on Cluster Munitions conference in Dublin.  <a class="reference external" href="http://en.wikipedia.org/wiki/File:Stop_cluster_bombs_march.jpg">image source</a></p>
</div>
<p>On Friday, <a class="reference external" href="http://www.hrw.org/en/news/2011/04/15/libya-cluster-munitions-strike-misrata">Human Rights Watch reported</a> that the Libyan army had
used cluster bombs in residential areas in the city of Misrata.</p>
<p>Some the of the newspaper articles I read about this story mentioned
that there's a treaty between more than a hundred states that have
agreed to ban cluster bombs.</p>
<p>Why ban cluster bombs?  One reason is that they have a very broad area
of effect, often harming civilians in attacks.  Another is that they
contain up to a hundred bomblets that may fail to explose initially
but remain live and explode when handled, thus posing a risk similar
to landmines.</p>
<p><a class="reference external" href="http://en.wikipedia.org/wiki/Cluster_bombs#Threat_to_civilians">Wikipedia</a>
explains that</p>
<blockquote>
98% of 13,306 recorded cluster munitions casualties that are
registered with Handicap International are civilians, while 27% are
children.</blockquote>
<p>The Convention on Cluster Munitions (CCM) that bans cluster bombs was
adopted in 2008.  And indeed, over a hundred states have since signed
the treaty, though 52 of those still have to ratify. <a class="footnote-reference" href="#id10" id="id1">[1]</a></p>
<p>However, a number of countries have opposed the treaty.  These are
mostly the same countries that produce and stockpile significant
numbers of cluster munition.  They include the United States, Israel,
Russia, China, India, Pakistan and Brazil.  Libya has also not signed
the treaty.</p>
<p>In defense of their opposition of the ban, the US said that cluster
munitions had a &quot;clear military utility in combat&quot; and that they
actually cause less harm to civilians than some other weapons.  But
that's certainly nonsense.  The United Nations estimate that around
40% of cluster bomblets fired by the Israeli Defense Forces in the
2006 Lebanon war failed to explode on impact. <a class="footnote-reference" href="#id11" id="id2">[2]</a></p>
<p>From Wikipedia:</p>
<blockquote>
Given that each cluster bomb can contain hundreds of bomblets and be
fired in volleys, even a small failure rate can lead each strike to
leave behind hundreds or thousands of [unexploded ordnances]
scattered randomly across the strike area.  For example, after the
2006 Israel-Lebanon conflict, UN experts have estimated that as many
as one million unexploded bomblets may contaminate the hundreds of
cluster munition strike sites in Lebanon.</blockquote>
<p>It's also estimated that, today, around 300 Vietnamese die annually
from exploding bomblet duds that date back to the Vietnam war
(1955-1975).</p>
<p>The United States do not only decide to continue producing deadly
cluster bombs which are exported to many countries in the world.  They
also continue to use them themselves, as recently as 2006 in Iraq.
<a class="reference external" href="http://www.stopclustermunitions.org/">stopclustermunitions.org</a> has
<a class="reference external" href="http://www.stopclustermunitions.org/the-problem/countries/">four maps</a> that
detail affected countries (36), users of cluster bombs (15), producers
(34), and stockpilers of cluster munitions (85).</p>
<p>The four most common users of cluster bombs counted by the number of
wars they used them in are:</p>
<ul class="simple">
<li>the United States: 9 wars (since 1965)</li>
<li>Israel: 5 wars (since 1973)</li>
<li>Russia: 4 wars (since 1979)</li>
<li>the United Kingdom: 4 wars (since 1982)</li>
</ul>
<p>As you can see, the US and UK are among the biggest users of these
horrible weapons.  Yet these same countries are at the forefront of
those accusing Libya of atrocities against civilians, and demanding
its leader Muammar Gaddafi to step down.  And the recent Human Rights
Watch about the alleged use of cluster bombs by the Libyan army in
Misrata report supports these accusations.</p>
<p>A former head of the UK's armed forces, Lord Dannatt, was <a class="reference external" href="http://www.guardian.co.uk/world/2011/apr/16/gaddafi-forces-intensify-attacks-misrata">quoted
yesterday</a>
with regard to the cluster bomb finding:</p>
<blockquote>
If we thought that Gaddafi had lost the moral right to rule this
country a month ago, he has lost it in the last 24 hours, that's for
sure.</blockquote>
<p>Following his logic, the UK government has long lost its 'moral right'
to rule.  Or maybe what Dannatt means is it that it's morally
acceptable when it's the British military that drops cluster bombs on
Arab civilian areas.</p>
<p>There isn't, however, much evidence to this cluster bombs story.
Since the beginning of the protests, the mainstream media has been
constantly pumping out similar accusations, and many of these already
turned out to be false.  John Pilger notes in his <a class="reference external" href="http://www.johnpilger.com/articles/david-cameron-s-gift-of-war-and-racism-to-them-and-us">article from 6th
April</a>:</p>
<blockquote>
Statements by western officials and media that a &quot;deranged and
criminal Colonel Gaddafi&quot; is planning &quot;genocide&quot; against his own
people still await evidence.</blockquote>
<p>Libyan government spokesman Moussa Ibrahim strongly denied the use of
cluster bombs: &quot;Absolutely no.  We can't do this. Morally, legally, we
can't do this.&quot;  He continued to say that &quot;the evidence would remain
for days and weeks, and we know the international community is coming
en masse to our country soon&quot;. <a class="footnote-reference" href="#id12" id="id3">[3]</a></p>
<p>A few days before the cluster bomb incident, the Libyan authorities
invited a Red Cross team to Misrata to assess the situation.  Also,
Libya has asked for a UN fact finding mission in the past, which has
now started since about a week. <a class="footnote-reference" href="#id13" id="id4">[4]</a></p>
<p>There is similarities here with the lead-up to the US-led invasion of
Iraq in 2003.</p>
<p>Before the war in Iraq, a UN fact finding mission led by Hans Blix
went to Iraq to find if there was indeed any &quot;weapons of mass
destruction&quot; (WMD), the threat of which were used by the US and UK as
a justification for their invasion.</p>
<p>Blix and his team praised a &quot;proactive&quot; Iraqi cooperation, yet they
did not find any WMD, until they were quickly shut out of Iraq by the
US when the war started. <a class="footnote-reference" href="#id14" id="id5">[5]</a> <a class="footnote-reference" href="#id15" id="id6">[6]</a></p>
<p>In an interview on BBC TV in February 2004, Blix accused the US and
British governments of dramatising the threat of weapons of mass
destruction in Iraq, in order to strengthen the case for the war
against the regime of Saddam Hussein.  Ultimately, no stockpiles of
weapons of mass destruction were found. <a class="footnote-reference" href="#id16" id="id7">[7]</a></p>
<div class="figure">
<img alt="http://danielnouri.org/media/Powell_UN_Iraq_presentation,_alleged_Aluminum_Tube_for_Uranium_Enrichment.jpg" src="http://danielnouri.org/media/Powell_UN_Iraq_presentation,_alleged_Aluminum_Tube_for_Uranium_Enrichment.jpg" />
<p class="caption">Colin Powell's February 2003 UN meeting presentation slide showing
an alleged Iraqi-ordered Aluminum Tube for Uranium
Enrichment. <a class="reference external" href="http://en.wikipedia.org/wiki/File:Powell_UN_Iraq_presentation,_alleged_Aluminum_Tube_for_Uranium_Enrichment.jpg">image</a></p>
</div>
<div class="section" id="update-april-21-2011">
<h3>Update April 21, 2011</h3>
<p>A week ago, The Boston Globe wrote: <a class="footnote-reference" href="#id17" id="id8">[8]</a></p>
<blockquote>
<p>Evidence is now in that President Barack Obama grossly exaggerated
the humanitarian threat to justify military action in Libya. The
president claimed that intervention was necessary to prevent a
&quot;bloodbath&quot; in Benghazi, Libya’s second-largest city and last rebel
stronghold.</p>
<p>But Human Rights Watch has released data on Misurata, the
next-biggest city in Libya and scene of protracted fighting,
revealing that Moammar Khadafy is not deliberately massacring
civilians but rather narrowly targeting the armed rebels who fight
against his government.</p>
</blockquote>
<p>An independent group called the &quot;British Civilians for Peace in Libya&quot;
that visited Western Libya for a week on a fact finding mission, comes
to a similar conclusion.  In their interim report they say they &quot;are
concerned that western media outlets are failing in their duty to
report on the conflict truthfully.&quot; <a class="footnote-reference" href="#id18" id="id9">[9]</a> See the <a class="reference external" href="http://news.sky.com/skynews/Home/World-News/Video-Libya-British-Group-Sees-No-Evidence-Of-Gaddafi-Forces-Using-Violence-In-Western-Libya/Article/201104315975021">Sky News article</a>
from April 19, 2011.</p>
<table class="docutils footnote" frame="void" id="id10" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td><a class="reference external" href="http://www.stopclustermunitions.org/treatystatus/">108 states on board the Convention on Cluster Munitions</a>, Convention on Cluster Munitions official website</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id11" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td><a class="reference external" href="http://www.haaretz.com/news/idf-commander-we-fired-more-than-a-million-cluster-bombs-in-lebanon-1.197099">IDF commander: We fired more than a million cluster bombs in Lebanon</a>, HAREETZ.com, 12 Sep 2006</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id12" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td><a class="reference external" href="http://english.aljazeera.net/news/africa/2011/04/201141741541217692.html">Battles for Libyan cities rage on</a>, Al Jazeera English, 17 Apr 2011</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id13" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id4">[4]</a></td><td><a class="reference external" href="http://www.google.com/hostednews/canadianpress/article/ALeqM5ioILVELHXLCSeEMuksrwzhb85zZA?docId=6502612">UN says its Libya human rights abuses investigation will cover all sides involved in fight</a>, The Associated Press, 8 Apr 2011</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id14" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[5]</a></td><td><a class="reference external" href="http://un.org/apps/news/storyAr.asp?NewsID=6383&amp;Cr=iraq&amp;Cr1=inspect">Blix welcomes accelerated cooperation by Iraq, but says unresolved issues remain</a>, United Nations official website, 7 Mar 2003</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id15" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id6">[6]</a></td><td><a class="reference external" href="http://edition.cnn.com/2003/US/06/12/blix.interview.cnna/">Blix takes Washington to task</a>, CNN.com, 12 June 2003</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id16" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id7">[7]</a></td><td><a class="reference external" href="http://news.bbc.co.uk/2/hi/uk_news/politics/3469821.stm">Blix doubts on Iraq intelligence</a>, BBC News, 8 Feb 2004</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id17" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id8">[8]</a></td><td><a class="reference external" href="http://articles.boston.com/2011-04-14/bostonglobe/29418371_1_rebel-stronghold-civilians-rebel-positions">False pretense for war in Libya?</a>, The Boston Globe, 14 Apr 2011</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id18" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id9">[9]</a></td><td><a class="reference external" href="http://franknatter.wordpress.com/2011/04/19/british-citizens-for-peace-in-libya-interim-report/">British Citizens for Peace in Libya – Interim Report</a>, Straight Talk, 19 Apr 2011</td></tr>
</tbody>
</table>
</div>
</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Pyramid is too damn easy - a success story]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/03/16/pyramid-is-too-damn-easy---a-success-story" />
    <id>http://danielnouri.org/notes/2011/03/16/pyramid-is-too-damn-easy---a-success-story</id>
    <updated>2011-03-16T21:00:00Z</updated>
    <published>2011-03-16T21:00:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Python" />
    <category scheme="http://danielnouri.org/notes" term="Web" />
    <category scheme="http://danielnouri.org/notes" term="Pyramid" />
    <category scheme="http://danielnouri.org/notes" term="Programming" />
    <summary type="html"><![CDATA[Pyramid is too damn easy - a success story]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/03/16/pyramid-is-too-damn-easy---a-success-story"><![CDATA[<div class="document">
<p><strong>Note</strong>: This isn't a programming tutorial. If you're looking for a
tutorial because you want to learn Pyramid on your own, head over to
the <a class="reference external" href="http://docs.pylonsproject.org/projects/pyramid/dev/#tutorials">Tutorials section</a> in the offical Pyramid docs.</p>
<p>Recently, the <a class="reference external" href="http://www.uc.pt/en">University of Coimbra</a> in Portugal rolled out a shiny
new collection of web apps for students and staff.  Users can now
access through a single platform:</p>
<ul class="simple">
<li>their email account</li>
<li>a personalized calendar</li>
<li>a homepage app where they can manage their own online presence</li>
<li>their profile, as it's stored in the uni's <em>LDAP</em>, which they can
update</li>
<li>a central panel to manage subscriptions to all <a class="reference external" href="http://www.gnu.org/software/mailman/index.html">Mailman</a> mailing
lists available to them</li>
<li>a help desk application that integrates with the <a class="reference external" href="http://en.wikipedia.org/wiki/Request_Tracker">Request Tracker</a>
ticket-tracking system</li>
<li>an application to access documents in the <a class="reference external" href="http://en.wikipedia.org/wiki/KnowledgeTree">KnowledgeTree</a> document
management system</li>
</ul>
<img alt="http://danielnouri.org/media/uc-apps-menu.png" src="http://danielnouri.org/media/uc-apps-menu.png" />
<p>The apps are demoed (rather quickly) in this Portuguese language
video.  Skip to <tt class="docutils literal">1:23</tt> to see them in action:</p>
<object id="newsletter-uc-fevereiro-nova-imagem-web-311-player" type="application/x-shockwave-flash" data="http://ucv.ci.uc.pt/ucv/scripts/third-party/jw_player/player.swf" width="560" height="339"><param name="movie" value="http://ucv.ci.uc.pt/ucv/scripts/third-party/jw_player/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="image=http%3A%2F%2Fucv.ci.uc.pt%2Fucv%2Fimages%2Fmedia%2F314l.jpg&amp;file=http%3A%2F%2Fucv.ci.uc.pt%2Fucv%2Ffiles%2F311-newsletter-uc-fevereiro-nova-imagem-web.mp4&amp;autostart=False&amp;provider=video" /></object><p>(Click here <a class="reference external" href="http://danielnouri.org/notes/2011/03/16/pyramid-is-too-damn-easy---a-success-story/">if you don't see the video</a>.)</p>
<p>Mario José Bernardes, the project coordinator, draws a diagram that
visualizes the different components involved under the hood:</p>
<img alt="http://danielnouri.org/media/uc-apps-diagram.png" src="http://danielnouri.org/media/uc-apps-diagram.png" />
<p>And what you can see here is in fact implemented as a <em>WSGI pipeline</em>.
The three boxes <tt class="docutils literal">AP1</tt> to <tt class="docutils literal">AP3</tt> at the bottom are the WSGI apps.
In front of that we have <tt class="docutils literal">PA</tt> which is a <a class="reference external" href="http://docs.repoze.org/who/1.0/">repoze.who</a> based
middleware that provides user authentication and <a class="reference external" href="http://en.wikipedia.org/wiki/Single_sign-on">single sign-on</a>
through <a class="reference external" href="http://shibboleth.internet2.edu">Shibboleth</a> and LDAP.  And at the top there is a <a class="reference external" href="http://packages.python.org/Deliverance/">Deliverance</a>
middleware that provides the look &amp; feel as well as the header and
footer for all pages, including the menu to navigate between the apps.</p>
<img alt="http://danielnouri.org/media/uc-apps-pipeline.png" src="http://danielnouri.org/media/uc-apps-pipeline.png" />
<p>Now what's really remarkable about this project, apart from its
brilliant execution, is that it was developed mostly in-house by a
small team of developers and admins, most of who hardly knew Python
before they started the project.</p>
<p>How did they end up using Python and Pyramid?</p>
<p>The university is a long-time <a class="reference external" href="http://www.infrae.com/products/silva">Silva</a> user, using it for their public
website for four years now, and they're very happy with it.  They knew
that they like Python and wanted to use it to solve more problems.</p>
<p>And that's when I got involved.  Back in December '09, I was asked to
do two Python tutorial sessions with three days each.  The trainees
were the in-house developers and most of them complete Python newbies.
So the first half of the tutorial was an introduction to Python from
the ground up and the second half explained WSGI, Paste and Pyramid
(which was still <em>repoze.bfg</em> back then).</p>
<p>In parallel to the training sessions, we put our heads together to
think about how a Python implementation of their envisioned web apps
portal could look like.  Back home from Portugal, I went ahead and
wrote some of the core utilities and one example app that could be
used as a reference point for programmers writing other apps.</p>
<p>And then it happened: After I delivered the first app, things got
<em>very</em> silent.  I stopped getting calls, no more emails, not even a
single postcard!  ... until I realized: the team didn't need me
anymore.  <strong>Python and Pyramid were too damn easy!</strong> My days as a
consultant would soon be counted. :-)</p>
<div class="section" id="lessons-learned">
<h3>Lessons learned</h3>
<ul class="simple">
<li>Don't teach Pyramid, you'll become useless soon</li>
<li>Instead recommend hard-to-learn frameworks, or better yet,
vendor-tied and hard-to-install black boxes</li>
<li>Find a new job quick before more people find out about Pyramid</li>
</ul>
<p>Seriously, what more important metric do we have for choosing one
framework over another if not that: <strong>How long does it take your team
to learn it and be productive with it?</strong></p>
</div>
<div class="section" id="who-did-it">
<h3>Who did it</h3>
<p>These guys rocked <a class="reference external" href="http://apps.uc.pt">apps.uc.pt</a>: Mario José Bernardes, Valentim
Branquinho, João Santos, Hugo Branquinho, Pedro Pinheiro, Pedro
Almeida and myself.</p>
</div>
</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[A jQuery find that also finds the root element]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element" />
    <id>http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element</id>
    <updated>2011-03-14T12:50:00Z</updated>
    <published>2011-03-14T12:50:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="jQuery" />
    <category scheme="http://danielnouri.org/notes" term="Web" />
    <category scheme="http://danielnouri.org/notes" term="Python" />
    <category scheme="http://danielnouri.org/notes" term="JavaScript" />
    <category scheme="http://danielnouri.org/notes" term="Programming" />
    <summary type="html"><![CDATA[A jQuery find that also finds the root element]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element"><![CDATA[<div class="document">
<p><a class="reference external" href="http://api.jquery.com/find/">jQuery's find method</a> is arguably the most used method in jQuery
applications.  Yet, when using <tt class="docutils literal">.find()</tt> recently, I found out that
it makes a rather weird exception for root element(s) of a document,
that is, it ignores them.</p>
<p>Consider this example from the comments in the <tt class="docutils literal">find</tt> API:</p>


<div class="pygments_murphy"><pre><span class="kd">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;&lt;div id=&quot;one&quot;&gt;&lt;div id=&quot;two&quot;&gt;&lt;/div&gt;&lt;/div&gt;&#39;</span><span class="p">).</span><span class="nx">find</span><span class="p">(</span><span class="s2">&quot;#one&quot;</span><span class="p">);</span>
</pre></div>



<p><tt class="docutils literal">el</tt> will be empty here, because <tt class="docutils literal">&lt;div <span class="pre">id=&quot;one&quot;&gt;</span></tt> is the root
element.  It would work if the element were nested inside, say,
another <tt class="docutils literal">div</tt>.</p>
<p><a class="reference external" href="http://danielnouri.org/notes/2011/03/13/an-ajax-page-update-mini-tutorial/">In a recent project</a> that uses <tt class="docutils literal">.find()</tt> to apply <em>progressive
enhancement</em> to parts of the page that have been updated through Ajax,
this became a pain.</p>
<p>Consider this success callback function that</p>
<ul class="simple">
<li>replaces parts of the page with updated content from the server</li>
<li>re-enables Ajax forms on the updated content</li>
</ul>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">enableAjaxForms</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">));</span>
<span class="p">}</span>

<span class="kd">function</span> <span class="nx">enableAjaxForms</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">node</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s2">&quot;form.ajax&quot;</span><span class="p">).</span><span class="nx">ajaxForm</span><span class="p">({</span>
        <span class="nx">success</span><span class="o">:</span> <span class="nx">success</span>
    <span class="p">});</span>
<span class="p">}</span>
</pre></div>



<p>As long as the server returns a document with a form that's <em>not the
root element</em>, this will work.  But when we return HTML that has a
form element as the root, our <tt class="docutils literal">enableAjaxForms</tt> function will
silently fail to find the form:</p>


<div class="pygments_murphy"><pre><span class="nt">&lt;form</span> <span class="na">class=</span><span class="s">&quot;ajax&quot;</span><span class="nt">&gt;</span> <span class="c">&lt;!-- form.ajax is root, .find() won&#39;t find it --&gt;</span>
  <span class="nt">&lt;div&gt;</span> ... <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/form&gt;</span>
</pre></div>



<p><strong>What do?</strong> There's another function in jQuery that filters on the
root elements.  It's called <a class="reference external" href="http://api.jquery.com/filter/">.filter()</a> and finds <em>only</em> the root
elements.  So this will work:</p>


<div class="pygments_murphy"><pre><span class="kd">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;&lt;div id=&quot;one&quot;&gt;&lt;div id=&quot;two&quot;&gt;&lt;/div&gt;&lt;/div&gt;&#39;</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="s2">&quot;#one&quot;</span><span class="p">);</span>
</pre></div>



<p>To get the results we want, we need to combine <tt class="docutils literal">.filter()</tt> and
<tt class="docutils literal">.find()</tt>.  We don't care whether the element we're looking for is
at the root or not.</p>
<p>So here's a rather simple implementation of a <tt class="docutils literal">jQuery.find2</tt> method
that'll return both root and child elements as the result of our
query:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">find2</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">selector</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="nx">selector</span><span class="p">).</span><span class="nx">add</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">selector</span><span class="p">));</span>
<span class="p">};</span>
</pre></div>



<p>And finally, this is how you would use it.  That is, just like you use
<tt class="docutils literal">.find()</tt> really:</p>


<div class="pygments_murphy"><pre><span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="s1">&#39;&lt;div class=&quot;one&quot;&gt;&lt;div class=&quot;one&quot;&gt;&lt;/div&gt;&lt;/div&gt;&#39;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">el</span> <span class="o">=</span> <span class="nx">html</span><span class="p">.</span><span class="nx">find2</span><span class="p">(</span><span class="s2">&quot;.one&quot;</span><span class="p">);</span> <span class="c1">// will match both divs</span>
</pre></div>



</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[An Ajax page update mini-tutorial]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/03/13/an-ajax-page-update-mini-tutorial" />
    <id>http://danielnouri.org/notes/2011/03/13/an-ajax-page-update-mini-tutorial</id>
    <updated>2011-03-13T13:30:00Z</updated>
    <published>2011-03-13T13:30:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="jQuery" />
    <category scheme="http://danielnouri.org/notes" term="Web" />
    <category scheme="http://danielnouri.org/notes" term="Pyramid" />
    <category scheme="http://danielnouri.org/notes" term="Kotti" />
    <category scheme="http://danielnouri.org/notes" term="Python" />
    <category scheme="http://danielnouri.org/notes" term="JavaScript" />
    <category scheme="http://danielnouri.org/notes" term="Programming" />
    <summary type="html"><![CDATA[An Ajax page update mini-tutorial]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/03/13/an-ajax-page-update-mini-tutorial"><![CDATA[<div class="document">
<p>Most <em>Ajax</em> applications need to update parts of the DOM or perform
some other action after they receive a response for their <em>XHR
requests</em>.</p>
<p>This tutorial describes an approach that'll allow you to handle these
updates in a unified way, <strong>minimzing code duplication and lines of
JavaScript code</strong>.</p>
<p>(If you're looking at this through your RSS reader, you might want to
<a class="reference external" href="http://danielnouri.org/notes/2011/03/13/an-ajax-page-update-mini-tutorial/">head over to my blog</a> for some synyax highlighting.)</p>
<p>With <a class="reference external" href="http://jquery.com/">jQuery</a>, Ajax functions will typically use a success callback
function to give the user some feedback or update parts of the page
when the response comes in.  A very simple success callback function
for an Ajax <tt class="docutils literal">POST request</tt> could look like this:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">()</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s2">&quot;Successfully saved.&quot;</span><span class="p">)</span> <span class="p">};</span>
</pre></div>



<p>We could then pass this success function to <tt class="docutils literal">$.post()</tt>:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="s1">&#39;/mypage&#39;</span><span class="p">,</span> <span class="p">{</span><span class="nx">somedata</span><span class="p">},</span> <span class="nx">success</span><span class="p">);</span>
</pre></div>



<p>Another success handler for a <tt class="docutils literal">GET request</tt> could update parts of
the page with HTML sent back from the server:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;div#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">};</span>
</pre></div>



<p>In this case, what our server would put in the response would be only
the <tt class="docutils literal">&lt;div&gt;</tt> we're interested in:</p>


<div class="pygments_murphy"><pre>&lt;div id=&quot;content&quot;&gt;...some content that&#39;s to be updated...&lt;/div&gt;
</pre></div>



<p>jQuery comes with an Ajax function called <a class="reference external" href="http://api.jquery.com/load/">.load()</a> that has an
implicit success handler which does exactly the same thing:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;div#content&#39;</span><span class="p">).</span><span class="nx">load</span><span class="p">(</span><span class="s1">&#39;/mynewcontent&#39;</span><span class="p">,</span> <span class="p">{</span><span class="nx">somedata</span><span class="p">});</span>
</pre></div>



<p>Alternatively, and because we're lazy, our server could respond to our
XHR request by returning the whole HTML page.  We could then extract
and update only the bits that we're interested in:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#message&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#content&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>



<p>This will pick elements <tt class="docutils literal">#message</tt> and <tt class="docutils literal">#content</tt> from the
incoming HTML and replace the old contents of those containers on the
page.  The HTML response for this could look something like this:</p>


<div class="pygments_murphy"><pre><span class="nt">&lt;html&gt;</span>
  ...
  <span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;message&quot;</span><span class="nt">&gt;</span>Successfully saved.<span class="nt">&lt;/div&gt;</span>
  ...
  <span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;content&quot;</span><span class="nt">&gt;</span>...some content that&#39;s to be updated...<span class="nt">&lt;/div&gt;</span>
  ...
<span class="nt">&lt;/html&gt;</span>
</pre></div>



<p>So far, so good.</p>
<div class="section" id="problem">
<h3>Problem</h3>
<p>Now imagine that in our application we're using some fancy
notifications plug-in that displays messages as a nice pop-up.  This
is useful when working with Ajax since it'll guarantee that the user
actually sees the notification even when they have scrolled way to the
bottom of the page.  Typically, we'd have some code to turn the
contents of <tt class="docutils literal">&lt;div <span class="pre">id=&quot;message&quot;&gt;</span></tt> into a pop-up in our <em>document
ready handler</em>:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">displayNotification</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">));</span>
<span class="p">});</span>
</pre></div>



<p>What's the problem with this?  Well, when we update our <tt class="docutils literal">&lt;div
<span class="pre">id=&quot;message&quot;&gt;</span></tt> through Ajax, the notifications pop-up won't display.
This is because the <em>document ready handler</em> is not triggered for mere
updates to the page.</p>
<p>We need to add a call to <tt class="docutils literal">displayNotification</tt> to our Ajax success
callback from before to make notifications work for the HTML that we
inject dynamically:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#message&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#content&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">displayNotification</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>



<p>Then imagine that you're using more <em>progressive enhancement</em> to turn
<tt class="docutils literal">&lt;ul&gt;</tt> list elements elements with a class <tt class="docutils literal">dropdown</tt> into a
dropdowns.  Again, we need to add a bit of code to both our success
handler <em>and</em> to the document ready handler:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">displayNotification</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">));</span>
    <span class="nx">makeDropdowns</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;ul.dropdown&quot;</span><span class="p">));</span> <span class="c1">// new!</span>
<span class="p">});</span>

<span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#message&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#content&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">displayNotification</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">));</span>
    <span class="nx">makeDropdowns</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;ul.dropdown&quot;</span><span class="p">,</span> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">)));</span> <span class="c1">// new!</span>
<span class="p">}</span>
</pre></div>



<p>Notice how the newly added call to <tt class="docutils literal">makeDropdowns</tt> in <tt class="docutils literal">function
success</tt> passes on only <tt class="docutils literal">ul.dropdown</tt> elements inside <tt class="docutils literal">#content</tt>,
that is, only the dropdown lists that were injected just now:</p>


<div class="pygments_murphy"><pre><span class="nx">makeDropdowns</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;ul.dropdown&quot;</span><span class="p">,</span> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">)));</span>
</pre></div>



<p>By passing only the element that's changed we avoid having to somehow
remember in <tt class="docutils literal">function makeDropdowns</tt> which lists were already turned
into dropdowns and which not.  These takes quite some burden off of
these functions.</p>
<p>The problem that emerges as we add these more and more enhancement
functions like <tt class="docutils literal">makeDropdowns</tt> and <tt class="docutils literal">displayNotification</tt> is that
we keep adding slightly different code to both our document ready
handler and to a number of success handlers that we might have created
in our app.  This sort of duplication of code is bad.  Let's try to
generalize a bit more.</p>
</div>
<div class="section" id="solution">
<h3>Solution</h3>
<p>Let's first create a unified interface for handlers like
<tt class="docutils literal">displayNotification</tt> and <tt class="docutils literal">makeDropdowns</tt>.  All of these should
have the form:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">handler</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// do our progressive enhancement here, but only inside node</span>
<span class="p">}</span>
</pre></div>



<p>As discussed before, we decide to pass in only the <tt class="docutils literal">node</tt> that has
changed.  The individual handlers can then apply their enhancements
only to the updated parts of the page.  We'll then create an array of
handlers so that later, when the DOM has been updated, we can call the
handlers one by one:</p>


<div class="pygments_murphy"><pre><span class="kd">var</span> <span class="nx">node_changed_handlers</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Array</span><span class="p">();</span>
<span class="nx">node_changed_handlers</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">displayNotification</span><span class="p">);</span>
<span class="nx">node_changed_handlers</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">makeDropdowns</span><span class="p">);</span>

<span class="kd">function</span> <span class="nx">node_changed</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// call handlers with &#39;node&#39; one by one</span>
    <span class="nx">$</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">node_changed_handlers</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="p">{</span> <span class="nx">func</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">});</span>
  <span class="p">}</span>
</pre></div>



<p>We can now go back to our document ready handler and to our success
handlers and simplify them substantially:</p>


<div class="pygments_murphy"><pre><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">node_changed</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;html&#39;</span><span class="p">));</span>
<span class="p">});</span>

<span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#message&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">((</span><span class="s2">&quot;#content&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">));</span>
    <span class="nx">node_changed</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#message&quot;</span><span class="p">));</span>
    <span class="nx">node_changed</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>



<p>No longer do we now need to change the code of both of these whenever
we add a new handler to <tt class="docutils literal">node_changed_handlers</tt>.  That's good.</p>
<p>Still, writing individual success handlers for all sorts of different
actions and Ajax requests, of which there are usually many in a modern
web app, is cumbersome.  Ideally, our success handler and the server
could use some <strong>more intelligent protocol</strong> that would allow us to
reuse the same success callback function for all our application's
Ajax requests.  In short, we want a success handler that we can use
for all our Ajax needs.</p>
<p>In order to achieve this, we add a little bit more information to the
HTML that is returned from the server and processed in our handlers.
We add a class <tt class="docutils literal"><span class="pre">ajax-replace</span></tt> to all those elements that need to be
updated in the page.  Here's the example from before with the class
added:</p>


<div class="pygments_murphy"><pre><span class="nt">&lt;html&gt;</span>
  ...
  <span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;message&quot;</span> <span class="na">class=</span><span class="s">&quot;ajax-replace&quot;</span><span class="nt">&gt;</span>Successfully saved.<span class="nt">&lt;/div&gt;</span>
  ...
  <span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;content&quot;</span> <span class="na">class=</span><span class="s">&quot;ajax-replace&quot;</span><span class="nt">&gt;</span> ... some updated content ... <span class="nt">&lt;/div&gt;</span>
  ...
<span class="nt">&lt;/html&gt;</span>
</pre></div>



<p>We can now strip out the bit in our success handler that looks for
specific ids and generalize it to this:</p>


<div class="pygments_murphy"><pre><span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
    <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.ajax-replace&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
        <span class="kd">var</span> <span class="nx">selector</span> <span class="o">=</span> <span class="s2">&quot;#&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
        <span class="nx">$</span><span class="p">(</span><span class="nx">selector</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
        <span class="nx">node_changed</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="nx">selector</span><span class="p">));</span>
    <span class="p">});</span>
<span class="p">}</span>
</pre></div>



<p>How does this work exactly?  It looks for all elements in the server
response's HTML with the class <tt class="docutils literal"><span class="pre">ajax-replace</span></tt> (line 3) and replaces
elements with a corresponding id <em>in the current DOM</em> (lines 4 and 5).
It then calls all <em>node changed handlers</em> with the newly added element
(line 6).</p>
<p>Voila!  What we have here is a very powerful and simple success
handler that's reusable for all our Ajax requests.</p>
</div>
<div class="section" id="demo">
<h3>Demo</h3>
<p>I've recently added Ajax forms and Growl-like notifications (using
the <a class="reference external" href="http://plugins.jquery.com/project/jquery-toastmessage-plugin">jquery-toastmessage-plugin</a>) to the <a class="reference external" href="http://pypi.python.org/pypi/Kotti">Kotti CMS</a>, a user-friendly
light-weight CMS that I'm building on top of <a class="reference external" href="http://pylonsproject.org/">Pyramid</a> and jQuery.</p>
<p><a class="reference external" href="https://github.com/Pylons/Kotti/blob/master/kotti/static/kotti.js">Take a look at Kotti's JavaScript code</a>, which implements just the
approach I've presented here.  In particular, take a look at
<tt class="docutils literal">function messages</tt> and <tt class="docutils literal">function dropdowns</tt> which correspond to
the two handlers described in this tutorial.</p>
<p>To see this code in action, log in to the <a class="reference external" href="http://kottidemo.danielnouri.org/&#64;&#64;move">Kotti demo server</a> with
the username <em>owner</em> and password <em>secret</em> and try the reorder form.</p>
</div>
</div>
]]></content>
  </entry>
  <entry>
    <author>
      <name></name>
      <uri>http://danielnouri.org/notes</uri>
    </author>
    <title type="html"><![CDATA[Libya is different]]></title>
    <link rel="alternate" type="text/html" href="http://danielnouri.org/notes/2011/03/02/libya-is-different" />
    <id>http://danielnouri.org/notes/2011/03/02/libya-is-different</id>
    <updated>2011-03-02T15:33:00Z</updated>
    <published>2011-03-02T15:33:00Z</published>
    <category scheme="http://danielnouri.org/notes" term="Politics" />
    <category scheme="http://danielnouri.org/notes" term="Libya" />
    <summary type="html"><![CDATA[Libya is different]]></summary>
    <content type="html" xml:base="http://danielnouri.org/notes/2011/03/02/libya-is-different"><![CDATA[<div class="document">
<p>The situation in Libya is very different to that of other Middle
East and North African countries in revolt.  Yet, the <strong>public
opinion likes to put Libya into the same box</strong>.</p>
<p>Today, Libyan leader <a class="reference external" href="http://www.youtube.com/watch?v=b2aF2nK84dQ">Gaddafi addressed on TV</a> the <a class="reference external" href="http://en.wikipedia.org/wiki/2011_Libyan_uprising">recent
developments in Libya</a>.</p>
<p>You may think of the Libyan government and its eccentric leader
however you want.  But if you believe that Libya's uprising is similar
to those in revolting neighbouring countries, then you're wrong.</p>
<p>What's happening in Libya is a civil war.  Rebels are armed and they
strategically capture cities and oil fields.  This is very different
to the peaceful demonstrations of millions of people that we've seen
in images from Cairo.</p>
<p>A look at Libya's history and current state reveals that the situation
in Libya is much different to that of neighbouring countries.</p>
<p>Libya is today arguably one of the most independent states of
post-colonial Africa.  It is widely accepted that Libya's welfare
system is one of the best on the continent.  <a class="reference external" href="http://en.wikipedia.org/wiki/History_of_Libya_under_Gaddafi#Petroleum_politics">From Wikipedia</a>:</p>
<blockquote>
During the 1970s, the government succeeded in making major
improvements in the general welfare of its citizens. By the 1980s
Libyans enjoyed much improved housing and education, comprehensive
social welfare services, and general standards of health that were
among the highest in Africa.</blockquote>
<p>(1969 is when Gaddafi came to power.)</p>
<p>In the <a class="reference external" href="http://en.wikipedia.org/wiki/Human_Development_Index">Human Development Index</a>, Libya is the only African state
that reaches 0.75 points.  It's the only green spot on the African
continent for 2010:</p>
<img alt="http://danielnouri.org/media/hdi-worldmap-2010.png" src="http://danielnouri.org/media/hdi-worldmap-2010.png" />
<p>In 1971, Libya kicked out British Petroleum.  During the 70s, the
state gained control of 70% of its oil production.  State revenues
from oil export more than quadrupled as the oil prices went up three
times.  And the <a class="reference external" href="http://countrystudies.us/libya/55.htm">benefitors were to a large extend the people of
Libya</a>.</p>
<p>Compare this to countries like <a class="reference external" href="http://www.guardian.co.uk/business/2010/dec/08/wikileaks-cables-shell-nigeria-spying">Nigera, where Shell has lots of
influence on the government and gets the best deals</a>, at the cost of
lots of suffering.  There, welfare is virtually non-existant.  Or take
<a class="reference external" href="http://www.huffingtonpost.com/2011/02/28/wikileaks-saudi-royal-wel_n_829097.html">Saudi Arabia, where the oil revenues also benefit only a few</a>.</p>
<p>And then countries like Nigeria that are practically in foreign hand
and follow capitalist agendas are the ones that are opposed to the
idea of an <a class="reference external" href="http://en.wikipedia.org/wiki/United_States_of_Africa">United States of Africa</a>, which is Gaddafi's Pan-African
effort with the goal of freeing more of Africa's countries from what
is effectively colonialism in disguise.  Surely, the recent
developments in Libya will be a setback for these efforts.  (See also
<a class="reference external" href="http://en.wikipedia.org/wiki/Neocolonialism">Neocolonialism</a>.)</p>
<p>NB: I'm not saying that Gaddafi is or is not unjustly using force
against the people of Libya.  That I can't assess.  I'm merely trying
to put things into perspective. <a class="footnote-reference" href="#id2" id="id1">[1]</a></p>
<p>In his TV appearance today, Gaddafi argued that there were no peaceful
protests in Libya, as there were in Egypt or Tunisia.  He said that
the opposition forces are militants, and that they're are stragically
targeting for the country's oil fields.</p>
<p><strong>Update</strong>.  See also:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.guardian.co.uk/world/2011/feb/24/libya-rebels-control-gaddafi-oilfields">Libya rebels isolate Gaddafi, seizing cities and oilfields</a></li>
<li><a class="reference external" href="http://www2.ohchr.org/english/bodies/hrcouncil/docs/16session/A-HRC-16-15.pdf">a United Nations Human Rights Council report on Libya from January 2011</a></li>
<li><a class="reference external" href="http://news.bbc.co.uk/2/hi/programmes/newsnight/9418922.stm">a BBC interview with Noam Chomsky from 8 March 2011 on the situation in the Arab world</a></li>
</ul>
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>As it turns out, most claims of Gaddafi's human rights abuses turned out to be fabrications.  See <a class="reference external" href="http://articles.boston.com/2011-04-14/bostonglobe/29418371_1_rebel-stronghold-civilians-rebel-positions">False pretense for war in Libya? [boston.com]</a>, <a class="reference external" href="http://www.independent.co.uk/news/world/africa/amnesty-questions-claim-that-gaddafi-ordered-rape-as-weapon-of-war-2302037.html">Amnesty questions claim that Gaddafi ordered rape as weapon of war [independent.co.uk]</a> and <a class="reference external" href="http://www.counterpunch.org/2011/08/31/the-top-ten-myths-in-the-war-against-libya/">The Top Ten Myths in the War Against Libya [counterpunch.org]</a>.</td></tr>
</tbody>
</table>
</div>
]]></content>
  </entry>
</feed>

