<?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>Shey's Rebellion &#187; programming</title>
	<atom:link href="http://www.sheysrebellion.net/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sheysrebellion.net/blog</link>
	<description>I sleep with pillows on my head.</description>
	<lastBuildDate>Fri, 22 Jan 2010 00:10:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dependency Injection</title>
		<link>http://www.sheysrebellion.net/blog/2010/01/18/dependency-injection/</link>
		<comments>http://www.sheysrebellion.net/blog/2010/01/18/dependency-injection/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 01:19:09 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Development and Design]]></category>
		<category><![CDATA[dependency injection]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=384</guid>
		<description><![CDATA[My previous discussion on Inversion of Control raised some questions so I want to take a step back and discuss Dependency Injection.  Dependency Injection is a pattern where software components (classes, methods or functions) are given their dependencies as parameters and these software components do not instantiate their dependencies directly.
Dependency Injection is an important [...]]]></description>
			<content:encoded><![CDATA[<p>My previous discussion on <a href="http://www.sheysrebellion.net/blog/2009/08/24/inversion-of-control-in-python/">Inversion of Control</a> raised some questions so I want to take a step back and discuss Dependency Injection.  Dependency Injection is a pattern where software components (classes, methods or functions) are given their dependencies as parameters and these software components do not instantiate their dependencies directly.</p>
<p>Dependency Injection is an important pattern to use when you wan to create classes that are easier to reuse and unit test.  Since the dependencies are external, they can be configured and maintained outside class or function and there&#8217;s no need to change the code in order to reuse it.  Also, when dependencies are injected into a class or a function it is possible to substitute a mock implementation of the dependency. In unit tests, mock objects are used as replacement for the real implementation, this helps isolate the functionality being tested.</p>
<p><strong>A simple example</strong></p>
<p>The following function has it&#8217;s dependencies, a list of numbers, passed to it, and since calculate_average only talks to a list of numbers it is easy to reuse.</p>
<pre class="brush: py">
def calculate_average(list_of_numbers):
  x = sum(list_of_numbers)
  return x/len(list_of_numbers)
</pre>
<p>Imagine a similar function which uses a database connection, retrieves a list of numbers then calculates the average.</p>
<pre class="brush: py">
def calculate_average():
  sql_query = "select numbers from table"
  list_of_numbers = db.query(sql_query)
  x = sum(list_of_numbers)
  return x/len(list_of_numbers)
</pre>
<p>This function is difficult to reuse because it depends on the database, future users of this function will have to either modify the function or create and maintain a database just to use it.  More importantly it&#8217;s difficult to test this function.  A test would require a database connection and a fixture to populate the database with data.</p>
<p>You should be thinking, but Shey, I would never do this with a simple function like this.  You&#8217;re right, you wouldn&#8217;t do this with a simple function, but as soon as calculate_average turns into a more complicated calculation such as calculate_value_at_risk we start instantiating or dependencies.</p>
<p><strong>A slightly less contrived example</strong></p>
<p>The BillingService class is responsible for charging your customers a fee.</p>
<pre class="brush: py">
class BillingService
  def initialize(credit_card_processor)
    self.processor = processor

  def charge(account, amount):
    if account.has_balance:
      result = processor.charge(account.cc_number, amount)
    if result == "success":
      account.deduct(amount)
</pre>
<p>Lets assume that Authorize.net is offering better rates than PayPal.  If the class accepts an implementation of a credit card processor as a dependency it is possible to switch to the authorize.net implementation of the credit card processor class without changing the BillingService class.  Similarly during unit testing, a mock implementation of a credit card processor can be used to alwasy return &#8220;success&#8221; and isolate the charge functionality of the BillingService.</p>
<pre class="brush: py">
class mock_credit_card_processor:
  def charge(cc_number, amount):
    return "success"

    def test_charge():
      bs = BillingService(mock_credit_card_processor)
      a = Account(cc_number="411111111111111", balance=300.00)
      bs.charge(a, 300.00)
      assert(a.balance == 0)
</pre>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2010%2F01%2F18%2Fdependency-injection%2F&amp;title=Dependency%20Injection" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2010%2F01%2F18%2Fdependency-injection%2F&amp;title=Dependency%20Injection" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2010%2F01%2F18%2Fdependency-injection%2F&amp;t=Dependency%20Injection" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2010%2F01%2F18%2Fdependency-injection%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2010%2F01%2F18%2Fdependency-injection%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2010/01/18/dependency-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moneytracking API, Ruby, Mash and HTTParty</title>
		<link>http://www.sheysrebellion.net/blog/2009/10/11/moneytracking-api-ruby-mash-and-httparty/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/10/11/moneytracking-api-ruby-mash-and-httparty/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 21:45:00 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[moneytracking]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/2009/10/11/moneytracking-api-ruby-mash-and-httparty/</guid>
		<description><![CDATA[Moneytrackin is a cool online accounting application that lets you track expenses and income, unlike other accounting applications it lets you add tags to each transactions. I love it!&#160; Tagging transactions makes it easier to track exactly where my money is going; not only can I see how much money I’ve spent on junk food [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.moneytrackin.com">Moneytrackin</a> is a cool online accounting application that lets you track expenses and income, unlike other accounting applications it lets you add tags to each transactions. I love it!&#160; Tagging transactions makes it easier to track exactly where my money is going; not only can I see how much money I’ve spent on junk food but also at which store, and all without having to explicitly create an account for that store.</p>
<p>Unfortunately Moneytracking has an annoying limitation which prevents you from tracking tags across accounts, so if you’re buying junk food with cash and credit tagging loses it appeal.&#160; Luckily, they provide an API which will allow us to easily get around the tagging limitation programmatically.&#160; </p>
<p>I can imagine some pretty cool analytics and infographics coming out of 6 months of data so I wrote <a href="http://code.google.com/p/moenytrackin/wiki/MoneyTrackin">Moneytrackin.rb</a>, a Ruby interface to the MoneyTrackin API.&#160; It exposes easy-to-use methods to interact with your Moneytrackin account. While it only implements the methods exposed by their API but I intend to add more functionality like tag searches across all accounts soon, imagine piping an amounte-weighted stream of tags to wordle!</p>
<p>With two gems, HTTParty and Mash, I was easily able to create the client interface.&#160; I included the HTTParty module within connection class and it gave it a &quot;get&quot; method that retrieves data over HTTP.&#160;&#160; Usage is simple:</p>
<pre class="csharpcode">response = self.<span class="kwrd">class</span>.<span class="kwrd">get</span>(self.<span class="kwrd">class</span>.base_uri + '/listProjects/')</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Then I passed the response to Mash which converts the XML response into a hash that acts more like a an object., it also also recursively descends down the response converting hashes into Mashes making it easy to get the transactions and the tags associated with them.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F10%2F11%2Fmoneytracking-api-ruby-mash-and-httparty%2F&amp;title=Moneytracking%20API%2C%20Ruby%2C%20Mash%20and%20HTTParty" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F10%2F11%2Fmoneytracking-api-ruby-mash-and-httparty%2F&amp;title=Moneytracking%20API%2C%20Ruby%2C%20Mash%20and%20HTTParty" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F10%2F11%2Fmoneytracking-api-ruby-mash-and-httparty%2F&amp;t=Moneytracking%20API%2C%20Ruby%2C%20Mash%20and%20HTTParty" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F10%2F11%2Fmoneytracking-api-ruby-mash-and-httparty%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F10%2F11%2Fmoneytracking-api-ruby-mash-and-httparty%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/10/11/moneytracking-api-ruby-mash-and-httparty/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install sqlite3 for RoR on Windows Vista</title>
		<link>http://www.sheysrebellion.net/blog/2009/09/19/install-sqlite3-for-ror-on-windows-vista/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/09/19/install-sqlite3-for-ror-on-windows-vista/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 05:47:56 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=378</guid>
		<description><![CDATA[SQLite is a great little embeddable database engine but the installation of the Ruby library is not obvious or straightforward on Windows XP or Vista.  To install SQLite for Ruby 1.8, perform the following steps:

download sqlitedll-3_6_18.zip,
copy the two files that are part of the archive to your Ruby bin directory;
run &#8220;gem install &#8211;version 1.2.3 sqlite3-ruby&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>SQLite is a great little embeddable database engine but the installation of the Ruby library is not obvious or straightforward on Windows XP or Vista.  To install SQLite for Ruby 1.8, perform the following steps:</p>
<ol>
<li>download <a style="color: #45735f;" href="http://www.sqlite.org/sqlitedll-3_6_18.zip">sqlitedll-3_6_18.zip</a>,</li>
<li>copy the two files that are part of the archive to your Ruby bin directory;</li>
<li>run &#8220;gem install &#8211;version 1.2.3 sqlite3-ruby&#8221; from the command prompt.</li>
</ol>
<p>Enjoy!</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F09%2F19%2Finstall-sqlite3-for-ror-on-windows-vista%2F&amp;title=Install%20sqlite3%20for%20RoR%20on%20Windows%20Vista" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F09%2F19%2Finstall-sqlite3-for-ror-on-windows-vista%2F&amp;title=Install%20sqlite3%20for%20RoR%20on%20Windows%20Vista" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F09%2F19%2Finstall-sqlite3-for-ror-on-windows-vista%2F&amp;t=Install%20sqlite3%20for%20RoR%20on%20Windows%20Vista" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F09%2F19%2Finstall-sqlite3-for-ror-on-windows-vista%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F09%2F19%2Finstall-sqlite3-for-ror-on-windows-vista%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/09/19/install-sqlite3-for-ror-on-windows-vista/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Inversion of Control in Python</title>
		<link>http://www.sheysrebellion.net/blog/2009/08/24/inversion-of-control-in-python/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/08/24/inversion-of-control-in-python/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 17:33:00 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Development and Design]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/2009/08/24/inversion-of-control-in-python/</guid>
		<description><![CDATA[Coming from a .NET background and having applied SOLID principles to software development, I was surprised by the lack of inversion of control containers for Python.
The few discussions I read online implied that Python doesn’t need an IoC framework because it is a dynamically typed language.  Dynamically typed languages eliminate the need to use interfaces, [...]]]></description>
			<content:encoded><![CDATA[<p>Coming from a .NET background and having applied <a href="http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx">SOLID principles</a> to software development, I was surprised by the lack of <a href="http://www.martinfowler.com/articles/injection.html">inversion of control containers</a> for Python.</p>
<p>The few discussions I read online implied that Python doesn’t need an IoC framework because it is a dynamically typed language.  Dynamically typed languages eliminate the need to use interfaces, they do not do away with the need for inversion of control.</p>
<p>IoC is used to decouple components of an application, remove direct dependencies so that replacing a component will not have a side effects on the rest of the system.  As <a href="http://pragdave.blogs.pragprog.com/pragdave/2004/11/transparent_inv.html">Dave Thomas explains</a></p>
<blockquote><p>a DI application is written as a set of loosely coupled components. These components contain no knitting code: nothing in the application code itself is responsible, for example, for making sure that the necessary objects somehow get an instance of the database connection. Instead, the components all run in a container. This container is given a description of the knitting to be done (typically using an XML file). The container then instantiates objects and sets them into components that need them</p></blockquote>
<p>I’m new to the language and there maybe a more “pythonic” way to handle inversion of control than using a container. Here is small and contrived example of inversion of control using <a href="http://code.google.com/p/pinsor/">Pinsor, a IoC container in Python</a>. Those coming from a .NET or Java background will find Pinsor easy to use, but slightly lacking in features.</p>
<script src="http://gist.github.com/172997.js"></script>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F24%2Finversion-of-control-in-python%2F&amp;title=Inversion%20of%20Control%20in%20Python" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F24%2Finversion-of-control-in-python%2F&amp;title=Inversion%20of%20Control%20in%20Python" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F24%2Finversion-of-control-in-python%2F&amp;t=Inversion%20of%20Control%20in%20Python" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F24%2Finversion-of-control-in-python%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F24%2Finversion-of-control-in-python%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/08/24/inversion-of-control-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Change point analysis in Python</title>
		<link>http://www.sheysrebellion.net/blog/2009/08/19/change-point-analysis-in-python/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/08/19/change-point-analysis-in-python/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 02:31:12 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[changepoint]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[pyton]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=361</guid>
		<description><![CDATA[With most of the paperwork done I&#8217;ve started to make use of my free time in Toronto.  In an effort to improve my Python programming I implemented a cummulative sum estimation based change point detection algorithm in Pyton based on an article by Dr. Wayne A. Taylor.  The changepoint project is available on Google code&#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>With most of the paperwork done I&#8217;ve started to make use of my free time in Toronto.  In an effort to improve my Python programming I implemented a cummulative sum estimation based change point detection algorithm in Pyton based on an <a href="http://www.variation.com/cpa/tech/changepoint.html#Procedure">article by Dr. Wayne A. Taylor</a>.  The <a href="http://code.google.com/p/changepoint/">changepoint project</a> is available on Google code&#8211; all comments are apprecaited.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F19%2Fchange-point-analysis-in-python%2F&amp;title=Change%20point%20analysis%20in%20Python" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F19%2Fchange-point-analysis-in-python%2F&amp;title=Change%20point%20analysis%20in%20Python" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F19%2Fchange-point-analysis-in-python%2F&amp;t=Change%20point%20analysis%20in%20Python" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F19%2Fchange-point-analysis-in-python%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F08%2F19%2Fchange-point-analysis-in-python%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/08/19/change-point-analysis-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Erlang Exercise: Implementing Talk with Distributed Erlang</title>
		<link>http://www.sheysrebellion.net/blog/2009/07/02/erlang-exercise-implementing-talk-with-distributed-erlang/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/07/02/erlang-exercise-implementing-talk-with-distributed-erlang/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 15:52:26 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=342</guid>
		<description><![CDATA[Here’s my solution for the Talk with Distributed Erlang exercise.
You can run the program by calling the start function, but first you must generate a cookie and start two named Erlang nodes using the following commands:

echo -n &#8220;dh32d8yhd8&#8243; &#62; erlang.cookie
erl -name Node1 -cookie
erl -name Node2 -cookie




Share and Enjoy:


	
	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>Here’s my solution for the <a href="http://www.erlang.org/course/exercises.html#talk" target="_blank">Talk with Distributed Erlang exercise</a>.</p>
<script src="http://gist.github.com/139295.js"></script>
<p>You can run the program by calling the start function, but first you must generate a cookie and start two named Erlang nodes using the following commands:</p>
<ol>
<li>echo -n &#8220;dh32d8yhd8&#8243; &gt; erlang.cookie</li>
<li>erl -name Node1 -cookie</li>
<li>erl -name Node2 -cookie</li>
</ol>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F07%2F02%2Ferlang-exercise-implementing-talk-with-distributed-erlang%2F&amp;title=Erlang%20Exercise%3A%20Implementing%20Talk%20with%20Distributed%20Erlang" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F07%2F02%2Ferlang-exercise-implementing-talk-with-distributed-erlang%2F&amp;title=Erlang%20Exercise%3A%20Implementing%20Talk%20with%20Distributed%20Erlang" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F07%2F02%2Ferlang-exercise-implementing-talk-with-distributed-erlang%2F&amp;t=Erlang%20Exercise%3A%20Implementing%20Talk%20with%20Distributed%20Erlang" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F07%2F02%2Ferlang-exercise-implementing-talk-with-distributed-erlang%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F07%2F02%2Ferlang-exercise-implementing-talk-with-distributed-erlang%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/07/02/erlang-exercise-implementing-talk-with-distributed-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AMQP Kool-Aid Part 1.5: RabbitMQ Benchmark</title>
		<link>http://www.sheysrebellion.net/blog/2009/06/24/amqp-kool-aid-part-15-rabbitmq-benchmark/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/06/24/amqp-kool-aid-part-15-rabbitmq-benchmark/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 18:46:55 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Development and Design]]></category>
		<category><![CDATA[AMQP]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[RabbitMQ]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=331</guid>
		<description><![CDATA[Introduction
As stock markets open, order management systems are flooded with new orders and it&#8217;s crucial that an OMS not miss prices or drop orders during this period.  The purpose of this initial benchmark is to simulate a flood of orders hitting the queue.
Benchmark
The benchmarking script sets up 10 queues, 10 producers and 10 consumers, each [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction<br />
</strong>As stock markets open, order management systems are flooded with new orders and it&#8217;s crucial that an OMS not miss prices or drop orders during this period.  The purpose of this initial benchmark is to simulate a flood of orders hitting the queue.</p>
<p><strong>Benchmark<br />
</strong>The benchmarking script sets up 10 queues, 10 producers and 10 consumers, each producer writes to a single queue and each consumer reads from that queue ie: p1 writes to q1 and c1 reads from q1 as fast at it can.  The time measured is the time it takes a message to travel from p1 to the queue and to be read by c1 and it was calculated by appending the timestamp to the message itself.</p>
<p>I chose to run a series of tests with message size varying from 35 bytes to 400 bytes and the message count varying from 50 messages to 100 messages in an attempt to visualize the broker&#8217;s behavior under varying conditions.</p>
<p>The benchmark was performed using a server running 2.8GHz Pentium D with 903464 kB RAM running on Kernel 2.6.18-128.1.10.el5 using RabbitMQ 1.5.5 and a machine with similar specifications as the client—both the producer and consumer run on the same machine.  The network is a typical Fast Ethernet with two switches separating the server and client machines.</p>
<p style="text-align: center;"><a href="http://www.sheysrebellion.net/blog/wp-content/uploads/2009/06/rabbitmq.png"><img class="aligncenter" style="border: 0pt none; display: inline;" title="RabbitMQ" src="http://www.sheysrebellion.net/blog/wp-content/uploads/2009/06/rabbitmq-thumb.png" border="0" alt="RabbitMQ" width="608" height="388" /></a></p>
<p align="justify">
<p align="justify"><strong>Conclusion<br />
</strong>Inconclusive! The numbers are very surprising I wasn&#8217;t expecting the message transfer times to be greater than .5 seconds under this load.  It&#8217;s possible that the <em>consumer</em> may not be able to keep up with flood of messages, if that&#8217;s the case than a consumer written in C# is needed.  What is obvious is that more tests  with a constant message size and a varying number of messages  are needed.</p>
<p align="justify">The standard deviation is also greater than I expected, so I plan on creating longer running tests and see if the broker falls into a steady state.  Finally, I also want to test with 50 messages per producer using 20 queues/producers instead of 10  and see how RabbitMQ responds.</p>
<p align="justify">I&#8217;m wondering what sort of performance others are experiencing—any and all feedback is greatly appreciated.</p>
<p align="justify"><strong>Postscript<br />
</strong>I intended on using C# to benchmark RabbitMQ but for want of time  I used a modified version of <a href="http://eventuallyconsistent.com/blog/">Colin Surprenant</a>&#8217;s <a href="http://github.com/sheysrebellion/bunnypunisher/tree/master">bunnypunisher</a> ruby script.  There&#8217;s a slightly outdated (and dirty) version of the script available on <a href="http://github.com/sheysrebellion/bunnypunisher/blob/6160b0d8e57f78bc6e0f361f6f52581b2afd6d6a/qpid_punisher.rb">github</a>.  I will upload the latest version along with the &#8220;launcher&#8221; tomorrow morning.</p>
<p>Kyle Burton at Asymmetrical View has a fairly comprehensive <a href="http://asymmetrical-view.com/2009/06/02/incanter-amqp-benchmark.html">comparison of RabbitMQ and Qpid</a>.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F24%2Famqp-kool-aid-part-15-rabbitmq-benchmark%2F&amp;title=AMQP%20Kool-Aid%20Part%201.5%3A%20RabbitMQ%20Benchmark" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F24%2Famqp-kool-aid-part-15-rabbitmq-benchmark%2F&amp;title=AMQP%20Kool-Aid%20Part%201.5%3A%20RabbitMQ%20Benchmark" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F24%2Famqp-kool-aid-part-15-rabbitmq-benchmark%2F&amp;t=AMQP%20Kool-Aid%20Part%201.5%3A%20RabbitMQ%20Benchmark" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F24%2Famqp-kool-aid-part-15-rabbitmq-benchmark%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F24%2Famqp-kool-aid-part-15-rabbitmq-benchmark%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/06/24/amqp-kool-aid-part-15-rabbitmq-benchmark/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Taking a sip of the AMQP Kool-Aid Part I</title>
		<link>http://www.sheysrebellion.net/blog/2009/06/21/taking-a-sip-of-the-amqp-kool-aid-part-i/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/06/21/taking-a-sip-of-the-amqp-kool-aid-part-i/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 18:28:47 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Development and Design]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[AMQP]]></category>
		<category><![CDATA[RabbitMQ]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/?p=297</guid>
		<description><![CDATA[Overview
Performance is vital in the world of stock trading, you can easily lose hundreds of thousands of dollars if the trading platform you’re using routes orders to the stock exchanges too slowly and you miss the your target price.
The order management system I work on uses IRC as the messaging middle ware&#8211; a message is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Overview</strong><br />
Performance is vital in the world of stock trading, you can easily lose hundreds of thousands of dollars if the trading platform you’re using routes orders to the stock exchanges too slowly and you miss the your target price.</p>
<p>The order management system I work on uses IRC as the messaging middle ware&#8211; a message is sent to a channel and another process reads and processes the message.  This gives us great flexibility, letting us write the user interface in .NET and the back-end server code in whichever language we choose and it also allows us to scale the system by moving processes to different machines.</p>
<p>But this setup has problems, if a message is missed by a process, there&#8217;s no easy to way to retrieve it and recent benchmarking showed that the latency of the messaging system spikes, unpredictably to 300 ms or more.  Initially IRC made sense but the requirements have grown and it’s clear a more robust solution which provides greater reliability, performance and scalability is needed.</p>
<p><strong>AMQP</strong><br />
The Advanced Message Queuing Protocol (AMQP) is an open standard, vendor neutral binary protocol for messaging middleware. AMQP features: messages, queuing and routing and it was designed by the financial industry to replace existing proprietary message queues.  It seems to be the Promised Land—the perfect replacement for IRC.</p>
<p>After a quick evaluation of messaging brokers, the best candidates appear to be RabbitMQ and Apache Qpid. Both support AMQP, seem to have low latency and have vendor support—Qpid in the form of RedHat MRG.  While both seem to be faster than IRC, I needed to be sure.</p>
<p>AMQP is more complicated than IRC and replacing the current messaging system won’t be easy. I wanted to create a benchmark that simulates the load we see in a production environment, but before I could create the test, I need to better understand what AMQP provides and the terminology it uses.</p>
<p><strong>AMQP Features</strong></p>
<p><em>Messages</em> are glorified strings which are published to an exchange. They consist of a header and a content body, while headers have several properties; you only need to know one to get started: the routing-key, a field used by exchanges to determine which queue the message will be routed to.</p>
<p><em></em><em>Queues</em> are where your messages wait until they are consumed.  Queues can be configured to let messages die if a consumer is not available, queues along with exchanges can be made durable.  Message can persists if the queue and the exchange are marked as durable and the message&#8217;s delivery mode is set to persistent.</p>
<p><em>Exchanges</em> the help the broker decide which queue to route your message to.  While they’re slated for removal in AMQP  1.0,  but they’re still important and difficult to ignore&#8211;  there are four types of exchanges:  Fanout, Direct, Topic and Header.</p>
<ul>
<li>Direct exchange: Use routing keys, messages sent to a direct exchange are routed to exchanges where the routing key matches exactly.</li>
<li>Topic exchange: A hierarchical exchange which also uses routing keys, routing keys are matched against a pattern, the hierarchy is established by separating keywords with the dot symbol.</li>
<li>Fanout Exchange: A 1:N exchange, any message sent to an exchange is sent to all queues bound to that exchange.</li>
</ul>
<p>A <em>Channel</em> is to AMQP what session is to HTTP, I&#8217;m not sure if that&#8217;s very accurate&#8211; all communication over a channel is stateful, and each instance of your program will have at least one channel.</p>
<p><strong>Conclusion</strong><br />
There’s a lot to digest, I spent the better part of the day reading <a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v1.6.0/rabbitmq-dotnet-client-1.6.0-user-guide.pdf">RabbitMQ’s .NET API Guide</a>.  In part two of this series I&#8217;ll walkthrough C# client and benchmark RabbitMQ.  As always, your feedback and comments are appreciated.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F21%2Ftaking-a-sip-of-the-amqp-kool-aid-part-i%2F&amp;title=Taking%20a%20sip%20of%20the%20AMQP%20Kool-Aid%20Part%20I" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F21%2Ftaking-a-sip-of-the-amqp-kool-aid-part-i%2F&amp;title=Taking%20a%20sip%20of%20the%20AMQP%20Kool-Aid%20Part%20I" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F21%2Ftaking-a-sip-of-the-amqp-kool-aid-part-i%2F&amp;t=Taking%20a%20sip%20of%20the%20AMQP%20Kool-Aid%20Part%20I" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F21%2Ftaking-a-sip-of-the-amqp-kool-aid-part-i%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F06%2F21%2Ftaking-a-sip-of-the-amqp-kool-aid-part-i%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/06/21/taking-a-sip-of-the-amqp-kool-aid-part-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Questioning ASP.NET MVC</title>
		<link>http://www.sheysrebellion.net/blog/2009/05/04/questioning-aspnet-mvc/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/05/04/questioning-aspnet-mvc/#comments</comments>
		<pubDate>Sun, 03 May 2009 20:09:24 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Development and Design]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/2009/05/04/questioning-aspnet-mvc/</guid>
		<description><![CDATA[ASP.NET MVC has always bothered me; even now I’m not sure exactly what bothers me, but it’s enough to make me question using .NET to develop web applications. No longer working at a .NET shop and having escaped from the realty distortion field I’ve pushed myself to revaluate languages and frameworks which I had ignored [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">ASP.NET MVC has always bothered me; even now I’m not sure exactly what bothers me, but it’s enough to make me question using .NET to develop web applications. No longer working at a .NET shop and having escaped from the realty distortion field I’ve pushed myself to revaluate languages and frameworks which I had ignored in the past.</p>
<p align="justify">Django, a Python framework for creating web applications which is loosely based on MVC architecture.&#160; In the two-three-odd hours I spent with <a href="http://www.instantdjango.com/">Instant Django</a> I realized that I’ve never had a compelling reason to develop web applications in ASP.NET and&#160; “I know C#” is not a not a reason to learn ASP.NET MVC.</p>
<p align="justify">Almost Immediately I noticed I wasn’t fighting the language, interpreted languages are much more compatible with the web development story, web application development with static languages is time consuming and tiresome.&#160; Within the first hour I was in love with the <a href="http://www.djangobook.com/en/2.0/">documentation</a>, not that I needed it *too* much, the different components fit well together and that’s fairly significant friction point for me. To do web development with ASP.NET MVC properly you need some sort of ORM, usually NHibernate, a dependency injection framework and 3rd party validators—I’m left wondering, isn’t this getting too complicated, where is my productivity?&#160; </p>
<p align="justify">By the second hour I’m sold, my gut tells me that Django is good and my brain is agreeing with my gut on this one. </p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F05%2F04%2Fquestioning-aspnet-mvc%2F&amp;title=Questioning%20ASP.NET%20MVC" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F05%2F04%2Fquestioning-aspnet-mvc%2F&amp;title=Questioning%20ASP.NET%20MVC" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F05%2F04%2Fquestioning-aspnet-mvc%2F&amp;t=Questioning%20ASP.NET%20MVC" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F05%2F04%2Fquestioning-aspnet-mvc%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F05%2F04%2Fquestioning-aspnet-mvc%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/05/04/questioning-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Programming Collective intelligence in Erlang</title>
		<link>http://www.sheysrebellion.net/blog/2009/04/20/programming-collective-intelligence-in-erlang/</link>
		<comments>http://www.sheysrebellion.net/blog/2009/04/20/programming-collective-intelligence-in-erlang/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 17:11:46 +0000</pubDate>
		<dc:creator>Sheheryar Sewani</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[datamining]]></category>

		<guid isPermaLink="false">http://www.sheysrebellion.net/blog/2009/04/20/programming-collective-intelligence-in-erlang/</guid>
		<description><![CDATA[Inspired by Matthew Podwysocki’s Functional Programming and Collective Intelligence post I decided to recreate some of the similarity algorithms discussed in the Programming Collective Intelligence in Erlang.
Collective Intelligence is a shared intelligence that emerges from the collaboration or competition amongst many individuals, it is used by online retailers such as Amazon.com and Netflix to recommend [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Inspired by Matthew Podwysocki’s <a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/03/30/functional-programming-and-collective-intelligence.aspx" target="_blank">Functional Programming and Collective Intelligence</a> post I decided to recreate some of the similarity algorithms discussed in the <a href="http://www.sheysrebellion.net/blog/2009/02/19/programming-collective-intelligence/">Programming Collective Intelligence</a> in Erlang.</p>
<p align="justify">Collective Intelligence is a shared intelligence that emerges from the collaboration or competition amongst many individuals, it is used by online retailers such as Amazon.com and Netflix to recommend books and movies.  Today we’ll use these algorithms to compare user preference, and in subsequent posts apply see how these algorithms are used in recommendation systems and clustering algorithms.</p>
<p align="justify">Before we continue, there are two unfamiliar concepts which we need to review: list Comprehensions and dictionaries.</p>
<p align="justify"><strong>List comprehensions</strong> are expressions (which are very common to functional programming languages) that allow you to create lists without having to use funs, maps, or filters. This helps you to write programs which are shorter and easier to debug. In Erlang, the syntax is:</p>
<pre>[ F(X) || X &lt;- L]</pre>
<p align="justify">which means, create a list of F(X) where F is a function and X is an element taken from the list L. Additionally, in Erlang we can use qualifiers to filter out elements of the list L.</p>
<p align="justify"><strong>Dictionaries </strong>(Hashes/Maps) are not directly supported by Erlang and to use them in your code you must use the <strong><a href="http://erlang.org/doc/man/dict.html" target="_blank">dict module</a></strong>. The module includes the function dict:from_list which converts a list of two element tuples into a dictionary; it also includes the function dict:fetch which takes the Key and the dictionary as an argument and returns the value which matches the key.</p>
<p><strong>Similarity</strong></p>
<p>Below is a list of movie ratings by user</p>
<table border="1" cellspacing="0" cellpadding="2" width="589">
<tbody>
<tr>
<td width="100" valign="top">
<p align="left">
</td>
<td width="85" valign="top">
<p align="left"><strong>Lady in The Water</strong></p>
</td>
<td width="78" valign="top">
<p align="left"><strong>Snakes on a Plane</strong></p>
</td>
<td width="55" valign="top">
<p align="left"><strong>Just My Luck</strong></p>
</td>
<td width="55" valign="top">
<p align="left"><strong>Superman Returns</strong></p>
</td>
<td width="101" valign="top">
<p align="left"><strong>You, me and Dupree</strong></p>
</td>
<td width="113" valign="top">
<p align="left"><strong>The Night Listener</strong></p>
</td>
</tr>
<tr>
<td width="100" valign="top"><strong>Lisa Rose</strong></td>
<td width="85" valign="top">2.5</td>
<td width="78" valign="top">3.5</td>
<td width="55" valign="top">3.0</td>
<td width="55" valign="top">3.5</td>
<td width="101" valign="top">2.5</td>
<td width="113" valign="top">3.0</td>
</tr>
<tr>
<td width="100" valign="top"><strong>Mick LaSalle</strong></td>
<td width="85" valign="top">3.0</td>
<td width="78" valign="top">4.0</td>
<td width="55" valign="top">2.0</td>
<td width="55" valign="top">3.0</td>
<td width="101" valign="top">2.0</td>
<td width="113" valign="top">3.0</td>
</tr>
<tr>
<td width="100" valign="top"><strong>Jack Mathews</strong></td>
<td width="85" valign="top">3.0</td>
<td width="78" valign="top">4.0</td>
<td width="55" valign="top">5.0</td>
<td width="55" valign="top"></td>
<td width="101" valign="top">3.5</td>
<td width="113" valign="top">3.0</td>
</tr>
<tr>
<td width="100" valign="top"><strong>Sheheryar</strong></td>
<td width="85" valign="top"></td>
<td width="78" valign="top">2.5</td>
<td width="55" valign="top"></td>
<td width="55" valign="top">3.0</td>
<td width="101" valign="top">3.0</td>
<td width="113" valign="top"></td>
</tr>
</tbody>
</table>
<p>which we can store in Erlang as a dictionary:</p>
<pre>  dict:from_list([
	{
	"Lisa Rose",
	dict:from_list( [{"Lady in the Water", 2.5},{"Snakes on a Plane", 3.5},
				 {"Just My Luck", 3.0},{"Superman Returns", 3.5},
				 {"You, Me and Dupree", 2.5},{"The Night Listener", 3.0}])
	},
	{"Mick LaSalle",
	dict:from_list( [{"Lady in the Water", 3.0},{"Snakes on a Plane", 4.0},
				 {"Just My Luck", 2.0},{"Superman Returns", 3.0},
				 {"You, Me and Dupree", 2.0},{"The Night Listener", 3.0}])
	},
	{"Jack Matthews",
	dict:from_list( [{"Lady in the Water", 3.0},{"Snakes on a Plane", 4.0},
				 {"Superman Returns", 5.0},{"You, Me and Dupree", 3.5},
				 {"The Night Listener", 3.0}])
	},
	{"Shey",
	dict:from_list( [{"Snakes on a Plane", 2.5},{"Superman Returns", 3.0},
				 {"You, Me and Dupree", 3.0}])}
	]).</pre>
<p align="justify">To determine how similar two users preferences are we need to compute a similarity score. An easy way to calculate similarity is to use the scaled <a href="http://en.wikipedia.org/wiki/Euclidean_distance" target="_blank">Euclidean Distance</a> formula which we learned back in high school geometry. The function returns a value between 0 and 1, where a value of 1 means that two people have identical tastes.</p>
<pre>sim_distance(List1, List2) <strong>when</strong> length(List1) /= 0, length(List1) == length(List1)  -&gt;
  Sum_of_squares = lists:sum([ math:pow(X-Y,2) || {X,Y} &lt;- lists:zip(List1,List2) ]),
  1.0 / (1.0 + math:sqrt(Sum_of_squares)).</pre>
<p align="justify">The function accepts two lists, each lists contains the user’s rating of a movie, where the <em>ith</em> element of each lists represents the user’s rating for the same movie. Note the use of the lists:zip function which takes two lists of equal length and returns one list of tuples with two elements each, where the first element of each tuple is taken from the first list and the second element is taken from corresponding element in the second list. Finally, the function also has two guard expressions that prevent the user from calling the function with empty lists or lists of unequal length.  Another simple distance metric is the <a href="http://en.wikipedia.org/wiki/Taxicab_geometry" target="_blank">Manhattan distance</a>, it represents the absolute differences between coordinates of a pair of objects:</p>
<pre>sim_manhattan(X,Y) when length(X) /= 0,  length(X) == length(Y)  -&gt;
  Sum = lists:sum([ abs(Xn-Yn) || {Xn,Yn} &lt;- lists:zip(X,Y)]),
  1.0/ (1.0 + Sum).</pre>
<p align="justify">In this scenario, a slightly better way to determine the similarity between two objects is to use a <a href="http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient" target="_blank">Pearson correlation coefficient</a>. The correlation coefficient is a measure of how well two sets of data fit on a straight line and it gives better results in when the data isn’t well normalized&#8211; for example, if critics’ movie rankings are routinely harsher than average. You can read about other other distance metrics for comparing items on <a href="http://en.wikipedia.org/wiki/Metric_(mathematics)#Examples" target="_blank">Wikipedia</a>.</p>
<pre>sim_pearson(X, Y) when length(X) == length(Y)  -&gt;
  Len = length(X),

  %% sum
  SumX = lists:sum(X),
  SumY = lists:sum(Y),

  %% sum of squares
  SumXSq=lists:sum([math:pow(N,2) || N &lt;- X]),
  SumYSq=lists:sum([math:pow(N,2) || N &lt;- Y]),

  %% sum of products
  Sum_products = lists:sum( [ A*B || {A,B} &lt;- lists:zip(X,Y)]),

  %% Calculate Pearson Score
  Numer = Sum_products - (SumX*SumY/Len),

  case math:sqrt( (SumXSq - math:pow(SumX,2) /Len) * (SumYSq - math:pow(SumY,2)/Len)) of
    0.0 -&gt;
      0.0;
    Denom -&gt;
      Numer/Denom %% Don't put a comma or semi-colon here
  end.</pre>
<p align="justify">A complete listing of the <a href="http://paste.lisp.org/display/78901">code</a> is available online; you can experiment with the different distance metrics using the main function, but due to some limitations of the command line interface, you’ll have to assign the function to a variable before passing it to the main function:</p>
<pre>1&gt; c(pci).
2&gt; SimPearson = fun(X,Y) -&gt; pci:sim_pearson(X,Y) end.
3&gt; pci:main("Mick LaSalle", "Lisa Rose", SimPearson).</pre>
<p align="justify">While this code is (mostly) functional, we haven’t taken advantage of Erlang’s distributed processes, soon we’ll explore the K-Means clustering algorithm which is very well suited to parallel implementations.</p>
<p align="justify">Your comments and Feedback are appreciated.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li><a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F04%2F20%2Fprogramming-collective-intelligence-in-erlang%2F&amp;title=Programming%20Collective%20intelligence%20in%20Erlang" title="del.icio.us"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F04%2F20%2Fprogramming-collective-intelligence-in-erlang%2F&amp;title=Programming%20Collective%20intelligence%20in%20Erlang" title="Reddit"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F04%2F20%2Fprogramming-collective-intelligence-in-erlang%2F&amp;t=Programming%20Collective%20intelligence%20in%20Erlang" title="Facebook"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F04%2F20%2Fprogramming-collective-intelligence-in-erlang%2F" title="Identi.ca"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" href="http://twitter.com/home?status=http%3A%2F%2Fwww.sheysrebellion.net%2Fblog%2F2009%2F04%2F20%2Fprogramming-collective-intelligence-in-erlang%2F" title="TwitThis"><img src="http://www.sheysrebellion.net/blog/wp-content/plugins/sociable/images/twitter.gif" title="TwitThis" alt="TwitThis" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sheysrebellion.net/blog/2009/04/20/programming-collective-intelligence-in-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
