

<?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>Cody A. Ray</title>
	<atom:link href="http://codyaray.com/feed" rel="self" type="application/rss+xml" />
	<link>http://codyaray.com</link>
	<description>Design. Technology. Sustainability. Education. Entrepreneurship.</description>
	<lastBuildDate>Wed, 07 Dec 2011 01:51:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PyYAML using easy_install on Mac OS X (Lion)</title>
		<link>http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion</link>
		<comments>http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion#comments</comments>
		<pubDate>Wed, 07 Dec 2011 01:50:13 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1273</guid>
		<description><![CDATA[Tried to install pyyaml today but got a couple nasty errors. $ sudo easy_install pyyaml Searching for pyyaml Reading http://pypi.python.org/simple/pyyaml/ Reading http://pyyaml.org/wiki/PyYAML Best match: PyYAML 3.10 Downloading http://pyyaml.org/download/pyyaml/PyYAML-3.10.zip Processing PyYAML-3.10.zip Running PyYAML-3.10/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8Co0C6/PyYAML-3.10/egg-dist-tmp-FYdiLy build/temp.macosx-10.7-intel-2.7/check_libyaml.c:2:18: error: yaml.h: No such file or directory build/temp.macosx-10.7-intel-2.7/check_libyaml.c: In function ‘main’: build/temp.macosx-10.7-intel-2.7/check_libyaml.c:5: error: ‘yaml_parser_t’ undeclared &#40;first use in [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Tried to install pyyaml today but got a couple nasty errors.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> easy_install  pyyaml
Searching <span style="color: #000000; font-weight: bold;">for</span> pyyaml
Reading http:<span style="color: #000000; font-weight: bold;">//</span>pypi.python.org<span style="color: #000000; font-weight: bold;">/</span>simple<span style="color: #000000; font-weight: bold;">/</span>pyyaml<span style="color: #000000; font-weight: bold;">/</span>
Reading http:<span style="color: #000000; font-weight: bold;">//</span>pyyaml.org<span style="color: #000000; font-weight: bold;">/</span>wiki<span style="color: #000000; font-weight: bold;">/</span>PyYAML
Best match: PyYAML <span style="color: #000000;">3.10</span>
Downloading http:<span style="color: #000000; font-weight: bold;">//</span>pyyaml.org<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>pyyaml<span style="color: #000000; font-weight: bold;">/</span>PyYAML-<span style="color: #000000;">3.10</span>.zip
Processing PyYAML-<span style="color: #000000;">3.10</span>.zip
Running PyYAML-<span style="color: #000000;">3.10</span><span style="color: #000000; font-weight: bold;">/</span>setup.py <span style="color: #660033;">-q</span> bdist_egg <span style="color: #660033;">--dist-dir</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>easy_install-8Co0C6<span style="color: #000000; font-weight: bold;">/</span>PyYAML-<span style="color: #000000;">3.10</span><span style="color: #000000; font-weight: bold;">/</span>egg-dist-tmp-FYdiLy
build<span style="color: #000000; font-weight: bold;">/</span>temp.macosx-<span style="color: #000000;">10.7</span>-intel-<span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">/</span>check_libyaml.c:<span style="color: #000000;">2</span>:<span style="color: #000000;">18</span>: error: yaml.h: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory
build<span style="color: #000000; font-weight: bold;">/</span>temp.macosx-<span style="color: #000000;">10.7</span>-intel-<span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">/</span>check_libyaml.c: In <span style="color: #000000; font-weight: bold;">function</span> ‘main’:
build<span style="color: #000000; font-weight: bold;">/</span>temp.macosx-<span style="color: #000000;">10.7</span>-intel-<span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">/</span>check_libyaml.c:<span style="color: #000000;">5</span>: error: ‘yaml_parser_t’ undeclared <span style="color: #7a0874; font-weight: bold;">&#40;</span>first use <span style="color: #000000; font-weight: bold;">in</span> this <span style="color: #000000; font-weight: bold;">function</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
...
lipo: can<span style="color: #ff0000;">'t open input file: /var/tmp//ccxDQipT.out (No such file or directory)</span></pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">libyaml is not found or a compiler error: forcing <span style="color: #660033;">--without-libyaml</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">if</span> libyaml is installed correctly, you may need to
 specify the option <span style="color: #660033;">--include-dirs</span> or uncomment and
 modify the parameter include_dirs <span style="color: #000000; font-weight: bold;">in</span> setup.cfg<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Fortunately, after piecing together a couple posts, the fix is easy. Use the following command to install PyYAML.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> python <span style="color: #660033;">-m</span> easy_install pyyaml</pre></div></div>

<p>We must install this way because the problem is a bug in an Python&#8217;s setuptools. Its been fixed in later versions, but for now this did the trick for me.</p>
<h3>Resources</h3>
<ul>
<li>http://pyyaml.org/ticket/186</li>
<li>http://pyyaml.org/ticket/94</li>
<li>http://andreasjacobsen.com/2008/10/10/using-python-setuptools-on-the-mac/</li>
</ul>
<div class="shr-publisher-1273"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Start-Up Crash on Mac OS X Lion</title>
		<link>http://codyaray.com/2011/11/eclipse-start-up-crash-on-mac-os-x-lion</link>
		<comments>http://codyaray.com/2011/11/eclipse-start-up-crash-on-mac-os-x-lion#comments</comments>
		<pubDate>Fri, 25 Nov 2011 04:57:53 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1268</guid>
		<description><![CDATA[Today, I was working from my parent&#8217;s home in Arkansas where we don&#8217;t have broadband, so my Mac was offline. I tried to start Eclipse and it just popped a dialog mentioning a log file with no other message. After a bit of searching the errors in the log, Stack Overflow came to the rescue. just [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today, I was working from my parent&#8217;s home in Arkansas where we don&#8217;t have broadband, so my Mac was offline. I tried to start Eclipse and it just popped a dialog mentioning a log file with no other message.</p>
<p>After a bit of searching the errors in the log, <a title="InetAddress.getLocalHost resolution on OS X when offline" href="http://stackoverflow.com/questions/7892609/inetaddress-getlocalhost-resolution-on-osx-lion-when-offline">Stack Overflow came to the rescue</a>.</p>
<p style="padding-left: 30px;">just add an alias for localhost to the network interface:</p>
<pre style="padding-left: 30px;"><code>sudo ifconfig en0 alias 127.0.0.1</code></pre>
<p>That&#8217;s all you have to do, really.</p>
<div class="shr-publisher-1268"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/11/eclipse-start-up-crash-on-mac-os-x-lion/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lost Your Kindle? Email A Last-Ditch Note to the Finder/Thief.</title>
		<link>http://codyaray.com/2011/09/lost-your-kindle-email-a-last-ditch-note-to-the-finderthief</link>
		<comments>http://codyaray.com/2011/09/lost-your-kindle-email-a-last-ditch-note-to-the-finderthief#comments</comments>
		<pubDate>Tue, 20 Sep 2011 04:38:50 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1264</guid>
		<description><![CDATA[About a week ago, I lost my Kindle. This makes me sad. After tracking it on security cameras until it left the film of vision (left in cart at grocery store), I&#8217;ve devised a last ditch effort. Remember that convenience method of emailing documents to your kindle? Well, I&#8217;ve just created a PDF pleading for its [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>About a week ago, I lost my Kindle. This makes me sad. After tracking it on security cameras until it left the film of vision (left in cart at grocery store), I&#8217;ve devised a last ditch effort. Remember that convenience method of emailing documents to your kindle? Well, I&#8217;ve just created a PDF pleading for its return, including my contact info. Will it work? Maybe not, but it can&#8217;t hurt either. You can do this yourself.</p>
<ol>
<li>Write a &#8220;please return my Kindle&#8221; note in MS Word. I used size 20 font, all caps, and short sentences. <span id="more-1264"></span>After my first pleading sentences<br />
PLEASE RETURN MY KINDLE. I MISS IT. ☹<br />
I included my address, phone, and email to maximize the opportunity for contact. (I live in a building with card access and the building manager&#8217;s office by the entry, so I&#8217;m not overly concerned with security here.) I even listed a location next to the grocery store it was left in as a potential drop off location. Lastly, I offered a small finders fee if it helps to incentivize them.</li>
<li>Save as (or print-to) PDF with filename &#8220;PLEASE RETURN MY KINDLE.&#8221; My assumption is that this will be the title as it appears in the Kindle itself.</li>
<li>Email to your name@free.kindle.com with the subject &#8220;convert&#8221;. This will convert it to Kindle format for easier reading, i.e., no need to do zoom/positioning to get the best view of the text. Make it as easy as possible for them to return, if they have any intention of doing so.</li>
</ol>
<p style="text-align: left;">I&#8217;ll let you know if it works. In the meantime, <em><strong>if you try this, let me know the results (if any).</strong></em></p>
<div class="shr-publisher-1264"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/09/lost-your-kindle-email-a-last-ditch-note-to-the-finderthief/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simple REST API Testing Setup using Vows.js, Tobi, and Node.js</title>
		<link>http://codyaray.com/2011/09/simple-rest-api-testing-setup-using-vows-js-tobi-and-node-js</link>
		<comments>http://codyaray.com/2011/09/simple-rest-api-testing-setup-using-vows-js-tobi-and-node-js#comments</comments>
		<pubDate>Sun, 18 Sep 2011 07:48:15 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1236</guid>
		<description><![CDATA[I&#8217;m learning so many new things at BrightTag! Among them, I&#8217;m helping develop a new service in node.js. After piecing together a few articles online about using node for asynchronous testing of REST services, I thought I&#8217;d share the testing setup I&#8217;d settled on, in case it can help you. The setup is written for vowsjs [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I&#8217;m learning so many new things at BrightTag! Among them, I&#8217;m helping develop a new service in node.js. After piecing together a <a title="Vows.js" href="http://vowsjs.org/" target="_blank">few</a> <a title="REST API Testing using Vows, Tobi, and Node" href="http://stackoverflow.com/questions/6918697/rest-api-testing-using-vows-tobi-and-node-js" target="_blank">articles</a> <a title="Testing REST APIs with Learnboost's Tobi + Vows.js" href="http://vilimpoc.org/blog/2011/01/19/testing-rest-api-with-learnboosts-tobi-vows-js/#comments" target="_blank">online</a> about using node for asynchronous testing of REST services, I thought I&#8217;d share the testing setup I&#8217;d settled on, in case it can help you. The setup is written for vowsjs and can easily be tailored to your situation. I&#8217;ve tried to make heavy use of asynchronization, macros, and contextualized requests. In the case below, I was integration-testing an oauth security middleware (simplified here for, well, simplicity).<span id="more-1236"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> vows <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'vows'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    assert <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'assert'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    should <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'should'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    tobi <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tobi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    http <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> HOST <span style="color: #339933;">=</span> <span style="color: #3366CC;">'localhost'</span><span style="color: #339933;">,</span>
    PORT <span style="color: #339933;">=</span> <span style="color: #CC0000;">8087</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> suite <span style="color: #339933;">=</span> vows.<span style="color: #660066;">describe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'My API Security'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    browser <span style="color: #339933;">=</span> tobi.<span style="color: #660066;">createBrowser</span><span style="color: #009900;">&#40;</span>PORT<span style="color: #339933;">,</span> HOST<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> client <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  get<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> header<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    browser.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> headers<span style="color: #339933;">:</span> header <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  post<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> header<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    browser.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> body<span style="color: #339933;">:</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> headers<span style="color: #339933;">:</span> header <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #006600; font-style: italic;">//Send a request and check the response status.</span>
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #003366; font-weight: bold;">function</span> respondsWith<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    topic<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// Get the current context's name, such as &quot;POST / access_token&quot;</span>
      <span style="color: #006600; font-style: italic;">// and split it at the spaces.</span>
      <span style="color: #003366; font-weight: bold;">var</span> req    <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">context</span>.<span style="color: #000066;">name</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ +/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// [&quot;POST&quot;, &quot;/&quot;, &quot;access_token&quot;]</span>
          method <span style="color: #339933;">=</span> req<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          <span style="color: #006600; font-style: italic;">// &quot;post&quot;</span>
          path   <span style="color: #339933;">=</span> req<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>                        <span style="color: #006600; font-style: italic;">// &quot;/&quot;</span>
          token  <span style="color: #339933;">=</span> req<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>                        <span style="color: #006600; font-style: italic;">// &quot;access_token&quot;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">var</span> header <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'Authorization'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Bearer '</span> <span style="color: #339933;">+</span> token <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// Perform the contextual client request,</span>
      <span style="color: #006600; font-style: italic;">// with the above method and path.</span>
      client<span style="color: #009900;">&#91;</span>method<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> header<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">callback</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Create and assign the vows to the context.</span>
&nbsp;
  context<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'should respond with a '</span> <span style="color: #339933;">+</span> <span style="color: #000066;">status</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span>
         <span style="color: #339933;">+</span> http.<span style="color: #660066;">STATUS_CODES</span><span style="color: #009900;">&#91;</span><span style="color: #000066;">status</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> assertStatus<span style="color: #009900;">&#40;</span>res.<span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  errorMessage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>error <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'out errors'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">' an &quot;'</span><span style="color: #339933;">+</span>error<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; error'</span><span style="color: #339933;">;</span>
  context<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'should respond with'</span> <span style="color: #339933;">+</span> errorMessage<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> assertHeaders<span style="color: #009900;">&#40;</span>res.<span style="color: #660066;">error</span><span style="color: #339933;">,</span> res.<span style="color: #660066;">errorDescription</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> context<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> assertStatus<span style="color: #009900;">&#40;</span>code<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>res<span style="color: #339933;">,</span> $<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    res.<span style="color: #660066;">should</span>.<span style="color: #660066;">have</span>.<span style="color: #000066;">status</span><span style="color: #009900;">&#40;</span>code<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> assertHeaders<span style="color: #009900;">&#40;</span>error<span style="color: #339933;">,</span> errorDescription<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>res<span style="color: #339933;">,</span> $<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>error <span style="color: #339933;">||</span> errorDescription<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      res.<span style="color: #660066;">should</span>.<span style="color: #660066;">have</span>.<span style="color: #660066;">header</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'www-authenticate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      header <span style="color: #339933;">=</span> oauth.<span style="color: #660066;">parseAuthenticationHeader</span><span style="color: #009900;">&#40;</span>res.<span style="color: #660066;">headers</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'www-authenticate'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> error.<span style="color: #660066;">should</span>.<span style="color: #660066;">equal</span><span style="color: #009900;">&#40;</span>header.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>errorDescription<span style="color: #009900;">&#41;</span> errorDescription.<span style="color: #660066;">should</span>.<span style="color: #660066;">equal</span><span style="color: #009900;">&#40;</span>header.<span style="color: #660066;">error_description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      res.<span style="color: #660066;">should</span>.<span style="color: #660066;">not</span>.<span style="color: #660066;">have</span>.<span style="color: #660066;">property</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'www-authenticate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
suite.<span style="color: #660066;">addBatch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">'GET /resource/1 authorized'</span><span style="color: #339933;">:</span> respondsWith<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'GET /resource/1 un@vth0riz3d'</span><span style="color: #339933;">:</span> respondsWith<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">401</span><span style="color: #339933;">,</span> error<span style="color: #339933;">:</span> <span style="color: #3366CC;">'invalid_token'</span><span style="color: #339933;">,</span> errorDescription<span style="color: #339933;">:</span> <span style="color: #3366CC;">'The access token is invalid'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'GET /resource/1 expired'</span><span style="color: #339933;">:</span> respondsWith<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">401</span><span style="color: #339933;">,</span> error<span style="color: #339933;">:</span> <span style="color: #3366CC;">'invalid_token'</span><span style="color: #339933;">,</span> errorDescription<span style="color: #339933;">:</span> <span style="color: #3366CC;">'The access token is expired'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">'GET /resource/1 insufficient'</span><span style="color: #339933;">:</span> respondsWith<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">403</span><span style="color: #339933;">,</span> error<span style="color: #339933;">:</span> <span style="color: #3366CC;">'insufficient_scope'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
suite.<span style="color: #003366; font-weight: bold;">export</span><span style="color: #009900;">&#40;</span>module<span style="color: #009900;">&#41;</span></pre></div></div>

<p>This pattern is nice because adding new tests is a real piece of cake now that we have the contextualized request macro, and this macro pattern is easy to tailor to your situation. It also demonstrates how to set two contexts, which was left &#8220;to the reader&#8221; on the <a title="Vows Guide" href="http://vowsjs.org/#-macros">vows guide</a>. You can even imagine adding more vows and assertions, such as one that checks the body content, into the macro, as I&#8217;ve done in the real case.</p>
<p><em><strong>Can you refactor or modify this to make it cleaner still? Let me know in the comments.</strong></em></p>
<div class="shr-publisher-1236"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/09/simple-rest-api-testing-setup-using-vows-js-tobi-and-node-js/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Delete Lines Matching Regular Expression From Multiple Files</title>
		<link>http://codyaray.com/2011/08/delete-lines-matching-regular-expression-from-multiple-files</link>
		<comments>http://codyaray.com/2011/08/delete-lines-matching-regular-expression-from-multiple-files#comments</comments>
		<pubDate>Thu, 18 Aug 2011 15:27:52 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1203</guid>
		<description><![CDATA[Today, I had to remove 650 instances of a line matching a certain pattern scattered across 145 different XML files. Not a pleasant task. (If you&#8217;re wondering, I&#8217;m deprecating a field in the XML DTD and wished to remove all current instances). Just to save you all the searching and debugging, here is the final [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today, I had to remove 650 instances of a line matching a certain pattern scattered across 145 different XML files. Not a pleasant task. (If you&#8217;re wondering, I&#8217;m deprecating a field in the XML DTD and wished to remove all current instances).</p>
<p>Just to save you all the searching and debugging, here is the final form and my notes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-rl</span> <span style="color: #ff0000;">'^&lt;pattern&gt;$'</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> .bak <span style="color: #ff0000;">'/^&lt;pattern&gt;$/d'</span></pre></div></div>

<p><span id="more-1203"></span><br />
Note a difference in the regex as used in <tt>grep</tt> and <tt>sed</tt>: in <tt>sed</tt>, the parenthesis are escaped, like <tt>\(.*\)</tt>, as are forward slashes which delimit the regex, like <tt>\/</tt>. However, since you&#8217;re just deleted an entire line, parenthesis probably shouldn&#8217;t be needed.</p>
<p>For bonus points, you can count the number of instances of a  pattern scattered across a number of files using</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-rc</span> <span style="color: #ff0000;">'^&lt;pattern&gt;$'</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{sum += $1} END {print sum}'</span></pre></div></div>

<p>And to finish it off, here&#8217;s a real live example!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-rl</span> <span style="color: #ff0000;">'^.*&lt;length&gt;(.*)&lt;/length&gt;\w*$'</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> .bak <span style="color: #ff0000;">'/^.*&lt;length&gt;\([0-9]*\)&lt;\/length&gt;\w*$/d'</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-rc</span> <span style="color: #ff0000;">'^.*&lt;length&gt;(.*)&lt;/length&gt;\w*$'</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{sum += $1} END {print sum}'</span></pre></div></div>

<div class="shr-publisher-1203"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/08/delete-lines-matching-regular-expression-from-multiple-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Service Learning</title>
		<link>http://codyaray.com/2011/08/service-learning</link>
		<comments>http://codyaray.com/2011/08/service-learning#comments</comments>
		<pubDate>Tue, 09 Aug 2011 15:21:45 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Education]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1169</guid>
		<description><![CDATA[Today, I stumbled upon the last article that I helped push through for Drexel Smart House before graduation. True to form and philosophy, this article is espousing an educational paradigm called &#8220;service learning.&#8221; This piece appeared in the Bridge (iSchool publication) and focuses on an HCI course by one of my favorite Drexel professors and personal mentors, Dr. [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today, I stumbled upon the last article that I helped push through for <a title="Drexel Smart House" href="http://drexelsmarthouse.com" target="_blank">Drexel Smart House</a> before graduation. True to form and philosophy, this article is espousing an educational paradigm called &#8220;service learning.&#8221; This piece appeared in the <em>Bridge</em> (iSchool publication) and focuses on an HCI course by one of my favorite Drexel professors and personal mentors, Dr. Jennifer Rode.</p>
<p style="text-align: center;"><a href="http://codyaray.com/downloads/2011/08/DSH-Article-on-Service-Learning.pdf"><img class="aligncenter size-large wp-image-1171" title="DSH Article on Service Learning Spread" src="http://codyaray.com/downloads/2011/08/DSH-Article-on-Service-Learning-Spread-1024x640.png" alt="DSH Spread in the Bridge" width="465" height="290" /></a></p>
<p style="text-align: center;"><a href="http://codyaray.com/downloads/2011/08/DSH-Article-on-Service-Learning.pdf">Get a PDF version for easier reading</a></p>
<p>I&#8217;m looking forward to seeing where the amazing new leadership team takes this project. I left at the most exciting time for DSH, but I&#8217;m excited to do whatever I can as an alumni to see this project, and all of the ideals and philosophies that it represents, flourish.</p>
<p>&nbsp;</p>
<div class="shr-publisher-1169"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/08/service-learning/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Graduated!</title>
		<link>http://codyaray.com/2011/08/graduated</link>
		<comments>http://codyaray.com/2011/08/graduated#comments</comments>
		<pubDate>Thu, 04 Aug 2011 02:21:20 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1154</guid>
		<description><![CDATA[Yayy!! A big thank you to all my family, friends, mentors, and supporters who have helped me at various points along the way. You&#8217;ve all helped fashion a great experience for this poor Southern boy, and I hope that you&#8217;ll allow me to help you in turn, whenever the time arises.]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>
<a href='http://codyaray.com/2011/08/graduated/img_3003' title='IMG_3003'><img width="150" height="150" src="http://codyaray.com/downloads/2011/08/IMG_3003-150x150.jpg" class="attachment-thumbnail" alt="IMG_3003" title="IMG_3003" /></a>
<a href='http://codyaray.com/2011/08/graduated/img_0304' title='IMG_0304'><img width="150" height="150" src="http://codyaray.com/downloads/2011/08/IMG_0304-150x150.jpg" class="attachment-thumbnail" alt="IMG_0304" title="IMG_0304" /></a>
</p>
<p>Yayy!! A big thank you to all my family, friends, mentors, and supporters who have helped me at various points along the way. You&#8217;ve all helped fashion a great experience for this poor Southern boy, and I hope that you&#8217;ll allow me to help you in turn, whenever the time arises.</p>
<div class="shr-publisher-1154"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/08/graduated/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: Cell Phone Bill Analysis</title>
		<link>http://codyaray.com/2011/07/case-study-cell-phone-bill-analysis</link>
		<comments>http://codyaray.com/2011/07/case-study-cell-phone-bill-analysis#comments</comments>
		<pubDate>Wed, 27 Jul 2011 17:31:34 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Case Studies]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1116</guid>
		<description><![CDATA[Have you ever looked at the long list of calls on your phone bill, and wished there were a better way to see who all you&#8217;ve spoken with and other related information? Like some of you, I&#8217;m a data junkie, and I sure did. For now, I&#8217;m an AT&#38;T customer. Like most modern phone companies, [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Have you ever looked at the long list of calls on your phone bill, and wished there were a better way to see who all you&#8217;ve spoken with and other related information? Like some of you, I&#8217;m a data junkie, and I sure did. For now, I&#8217;m an AT&amp;T customer. Like most modern phone companies, AT&amp;T makes your call history available for download from their website in CSV format. Using a <a title="Cody A. Ray's Phone Stats script" href="https://github.com/codyaray/att_phone_stats">simple script</a>, we can transform this long ugly list of numbers into something more meaningful.</p>
<p style="text-align: left;"><a href="http://codyaray.com/downloads/2011/07/CallStats.png"><img class="aligncenter size-large wp-image-1133" title="CallStats" src="http://codyaray.com/downloads/2011/07/CallStats-1024x340.png" alt="Pie Charts showing To Whom I Speak as Percent of Total Calls and Total Minutes" width="498" height="166" /></a>Graphs such as these can tell us a few interesting things, <span id="more-1116"></span>other than the fact that <a title="PrettyNerd" href="http://prettynerd.com">PrettyNerd</a> and I talk frequently and that I&#8217;m a momma&#8217;s boy. It shows that, save for these two people, I don&#8217;t spend a lot of time on the phone. However, the time I do spend on the phone actually <em>increases</em> with these two people. The remainder tend to be short, to-the-point conversations with friends, family, and colleagues. The data itself also shows that I make a lot of calls to service providers (e.g., I made 8 calls to Comcast in this period as I repeatedly tried to cancel my service), and that I spend far too long on hold for my tastes.</p>
<p style="text-align: left;">If you&#8217;re an AT&amp;T customer, you can use this script for yourself. <a title="AT&amp;T Phone Stats" href="https://github.com/codyaray/att_phone_stats">Download it from my GitHub</a>.</p>
<p>Example usage:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ ./att_phone_stats 061411-071311.csv &gt; 061411-071311.out.csv</pre></div></div>

<p>This command will parse the call history (presumably for June 14, 2011 to July 13, 2011) and write out a new CSV that is more useful for data analysis and statistics. We can then open this file in Excel or other spreadsheet software and create simple graphs to visually depict our behaviors regarding cell phone usage. </p>
<p>The expected columns on the input CSV: Item, Day, Date, Time, Number Called, Call To, Min, Rate Code, Rate Pd, Feature, Airtime Charge, LD/Add&#8217;l Charge, and Total Charge. The output CSV contains the following columns in order: Number Called, Total Number Calls, Total Mins, Number Incoming Calls, Number Outgoing Calls, Incoming Mins, and Outgoing Mins. Note that most of the input columns are unused, and there is a lot of data munging that we could still do. </p>
<p><em>Does anyone else have other ideas for how we might look at and interpret this data? Please share them in the comments. <img src='http://codyaray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<div class="shr-publisher-1116"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/07/case-study-cell-phone-bill-analysis/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>For Loops and Finite Series</title>
		<link>http://codyaray.com/2011/07/for-loops-and-finite-series</link>
		<comments>http://codyaray.com/2011/07/for-loops-and-finite-series#comments</comments>
		<pubDate>Sun, 24 Jul 2011 01:30:33 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1030</guid>
		<description><![CDATA[At the request of one of my AP Computer Science students, I&#8217;m posting a few solutions to a simple loop problem in Java. The question reads: How many times are the following loops executed? for&#40;int i=0; i&#60;10; i++&#41; for&#40;int j=0; j&#60;i; j++&#41; System.out.println&#40;i*j&#41;; The possible options are A) 100, B) 20, C) 10, or D) [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>At the request of one of my AP Computer Science students, I&#8217;m posting a few solutions to a simple loop problem in Java. The question reads:</p>
<p><em>How many times are the following loops executed?</em></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>i<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The possible options are A) 100, B) 20, C) 10, or D) 45.</p>
<p>Now, there are a few ways you can go about solving this problem. <span id="more-1030"></span>The easiest is to simply plug this excerpt into a Java program and execute it. Add line numbers if you don&#8217;t want to count, and you&#8217;ll easily see how many times the statement is executed.</p>
<p>You can also work it out by hand using simple arithmetic. A for-loop of the form</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>n<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>will execute <tt>n</tt> times. Extending this further, a nested for-loop from <tt>i=0 to 10, j=0 to 10</tt> will execute <tt>10 x 10 = 100</tt> times. Since the upper bound on the inner loop changes on every iteration, we cannot compute this with a single multiplication. When <tt>i=0</tt> in the outer loop, the inner loop never executes (<tt>0</tt> is not less than <tt>0</tt>). When <tt>i=1</tt>, the inner loop executes once for <tt>j=0</tt>. When <tt>i=2</tt>, the inner loop executes twice, for <tt>j=0</tt> and <tt>j=1</tt>. Extending this for the variable boundary (<tt>i &lt; j</tt>) case, we compute the number of iterations as follows:</p>
<p><img src='http://s.wordpress.com/latex.php?latex=%281%20%5Ccdot%200%29%20%2B%20%282%20%5Ccdot%200%20%2B%202%20%5Ccdot%201%29%20%2B%20%5Cdots%20%2B%20%289%20%5Ccdot%200%20%2B%209%20%5Ccdot%201%20%2B%20%5Cdots%20%2B%209%20%5Ccdot%208%20%29%20%3D%2045&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(1 \cdot 0) + (2 \cdot 0 + 2 \cdot 1) + \dots + (9 \cdot 0 + 9 \cdot 1 + \dots + 9 \cdot 8 ) = 45' title='(1 \cdot 0) + (2 \cdot 0 + 2 \cdot 1) + \dots + (9 \cdot 0 + 9 \cdot 1 + \dots + 9 \cdot 8 ) = 45' class='latex' /></p>
<p>A more elegant approach, mathematically speaking, uses our knowledge of finite series to re-write the above series and find its solution:</p>
<p><img src='http://s.wordpress.com/latex.php?latex=%5CRightarrow%20%5Csum_%7Bi%3D0%7D%5E%7B9%7D%20%5Csum_%7Bj%3D0%7D%5Ei%201%20%3D%20%5Csum_%7Bi%3D0%7D%5E%7B9%7D%20i%20%3D%20%5Cfrac%7B9%289%2B1%29%7D%7B2%7D%20%3D%2045&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\Rightarrow \sum_{i=0}^{9} \sum_{j=0}^i 1 = \sum_{i=0}^{9} i = \frac{9(9+1)}{2} = 45' title='\Rightarrow \sum_{i=0}^{9} \sum_{j=0}^i 1 = \sum_{i=0}^{9} i = \frac{9(9+1)}{2} = 45' class='latex' /></p>
<p>There ya have it, folks! Three different ways to determine how many times a loop is executed, ranging from brute force to elegant.</p>
<div class="shr-publisher-1030"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/07/for-loops-and-finite-series/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update on My Life</title>
		<link>http://codyaray.com/2011/07/update-on-my-life</link>
		<comments>http://codyaray.com/2011/07/update-on-my-life#comments</comments>
		<pubDate>Tue, 19 Jul 2011 05:42:38 +0000</pubDate>
		<dc:creator>codyaray</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://codyaray.com/?p=1006</guid>
		<description><![CDATA[I&#8217;m sorry its been so long since I&#8217;ve written! A lot has changed in my life recently, and I should tell you all about it. In brief, Finally graduated from Drexel University with both my bachelor and master degrees in electrical engineering. (Honors, baby!) Moved to Chicago. Technically, I&#8217;m currently living in Evanston, IL, at Northwestern [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I&#8217;m sorry its been so long since I&#8217;ve written! A lot has changed in my life recently, and I should tell you all about it. In brief,</p>
<ul>
<li>Finally graduated from Drexel University with both my bachelor and master degrees in electrical engineering. (Honors, baby!)</li>
<li>Moved to Chicago. Technically, I&#8217;m currently living in Evanston, IL, at Northwestern University. See next point.</li>
<li>Starting working with gifted students through Northwestern University&#8217;s Center for Talent Development <span id="more-1006"></span>summer programs as a Residential Teaching Assistant. I spent the first half of the summer helping teach <em>Computer Programming Honors: Java</em> to middle school students, and I&#8217;m helping teach <em>AP Computer Science</em> to high school students for the remainder of the second half. My students are all amazing. The middle school kids produced some cool final projects, and the high schoolers are off to a really strong start. 16 hour days FTW!</li>
<li>I&#8217;ve accepted a position as a software engineer at an awesome startup called BrightTag in downtown Chicago starting in August. I&#8217;m early in the company—employee 19—and the team is a dream team. The CEO is Mike Sands, the former CMO/COO of the original management team behind Orbitz. He helped take Orbitz from startup to IPO. I&#8217;m reporting directly to CTO Eric Lunt, who co-founded Feedburner, sold it to Google, and then spent the next several years as a senior tech guy at Google. Marc Kiven, the head marketing/sales guy, has also built and sold a couple companies, most recently selling Right Media to Yahoo!. Even the &#8220;ordinary&#8221; devs are awesome; they were all hand-picked, e.g., the head infrastructure guy was behind scaling Feedburner and some other Google stuff. Dream team. And they have awesome VCs and advisors. And the company culture fits like a glove. Collegial and relaxed with lots of laughter, playful teasing, and hanging out after work. Couldn&#8217;t be a better fit. I&#8217;m really freaking excited.</li>
</ul>
<p>I&#8217;ll try to resume posting tutorials and ramblin&#8217; thoughts in the near-ish future, but it likely won&#8217;t be til mid-August, after I finish my time at Northwestern and when I start at BrightTag. Looking forward to catching up with everyone!</p>
<div class="shr-publisher-1006"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://codyaray.com/2011/07/update-on-my-life/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 4.668 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-22 12:54:41 -->

