<?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>david mccuskey.com &#187; Programming</title>
	<atom:link href="http://davidmccuskey.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidmccuskey.com</link>
	<description>my slice of the Internet</description>
	<lastBuildDate>Thu, 22 Jul 2010 16:58:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>LightCharts – Lightweight charts for Flex</title>
		<link>http://davidmccuskey.com/2010/07/lightcharts-lightweight-charts-for-flex/</link>
		<comments>http://davidmccuskey.com/2010/07/lightcharts-lightweight-charts-for-flex/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 16:47:58 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://davidmccuskey.com/?p=652</guid>
		<description><![CDATA[LightCharts A lightweight line-chart library for Flex. Background I created LightCharts for a project of mine that involves tracking many stock market symbols. Originally I was using the Adobe Flex Charting library, but found that performance suffered greatly given the number of charts I was using (around 60+), the amount of data displayed, and the [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-left:auto;margin-right:auto" src="http://davidmccuskey.com/wp-content/uploads/2010/07/lightcharts-single-screenshot.png" alt="lightcharts-single-screenshot.png" border="0" width="440" height="135" /></p>


<h3>LightCharts</h3>

<p>A lightweight line-chart library for Flex.</p>

<h3>Background</h3>

<p>I created LightCharts for a project of mine that involves tracking many stock market symbols. Originally I was using the Adobe Flex Charting library, but found that performance suffered greatly given the number of charts I was using (around 60+), the amount of data displayed, and the constant real-time updates. Of course this isn&#8217;t necessarily due to poor coding on Adobe&#8217;s part, it&#8217;s just that their library contains an amazing amount of features to handle a variety of needs, consequently it&#8217;s very heavy. I didn&#8217;t need a lot of features, just a nimble way to display data.</p>

<p>I searched the Internet for other charting libraries which I could use and stumbled across a fantastic set of components created by Keith Peters called <a href="http://www.minimalcomps.com/">Minimal Comps</a>. Keith&#8217;s library is extremely lightweight and it would have been a good fit, but MinimalComps is geared towards the pure Flash environment and not Flex &#8211; a major issue being the disparity in the component lifecycle.</p>

<p>Nonetheless, I was inspired by his code so I decided to use it as a starting point, adding and changing what I needed along the way.</p>

<h3>Features</h3>

<p>The result is a charting library that has many new features and several new object classes, some for visual enhancements and others for displaying and interacting with data. For instance, the data series class gives the ability to display multiple lines on a graph. The Toolset architecture is useful for creating mini plug-ins which can annotate or interact with data, all without needing to change any of the charting base classes.</p>

<p>Also, the line-chart class can be subclassed to create new line-chart types which have different visual characteristics or behavior. Included are a couple of examples for charts which I used in my project &#8211; these include the <span class="caps">MACD </span>and Stochastic. <em>Note: These examples show how to make visual and behavioral changes to the base class, not how to calculate the values for the <span class="caps">MACD </span>or Stochastic charts. Those formulas can be easily found online.</em></p>

<h3>Screenshot</h3>

<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://davidmccuskey.com/wp-content/uploads/2010/07/lightcharts-screenshot.png" alt="lightcharts-screenshot.png" border="0" width="440" height="371" /> </p>

<p>In the screenshot above you can see many of the features:</p>


<ul>
<li>Three different charts (standard, <span class="caps">MACD, </span>and Stochastic), displaying different backgrounds including gradients and alphas, line colors, value ranges, etc.</li>
<li>On the first chart, the display of crosshairs and coordinate value on mouseover; all charts have this functionality.</li>
<li>On the first and second charts, a custom plug-in called <em>DotDisplayTool</em> which displays a dot over the last data point in the series. <em>DotDisplayTool</em> is an example of a non-interactive plug-in.</li>
<li>On the second and third charts, a custom plug-in called <em>LinearDrawTool</em> which allows you to draw on top of the data; it displays a line and the chart values which correspond to the beginning and ending points. <em>LinearDrawTool</em> is an example of an interactive plug-in.</li>
</ul>



<h3>Live Demo &amp; Source</h3>

<p>If you want to see the library in action, click on the following link: <a href="http://davidmccuskey.com/demos/lightcharts/" target="_lightcharts_demo"> LightCharts live demo</a>.</p>

<p>The source is covered under the <span class="caps">MIT </span>license and it&#8217;s currently available from the live demo &#8220;View Source&#8230;&#8221;.</p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2010/07/lightcharts-lightweight-charts-for-flex/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Generating Random Session IDs</title>
		<link>http://davidmccuskey.com/2009/09/generating-random-session-ids/</link>
		<comments>http://davidmccuskey.com/2009/09/generating-random-session-ids/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 21:03:36 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.mccuskey.com/?p=578</guid>
		<description><![CDATA[For any online service you must login so you can gain access to your stuff. So that you only have to put in your password once, the website must maintain a special unique character sequence called a session key to know that you have already authenticated. There is a problem with these keys, however, if [...]]]></description>
			<content:encoded><![CDATA[<p>For any online service you must login so you can gain access to your stuff.  So that you only have to put in your password once, the website must maintain a special unique character sequence called a <em>session key</em> to know that you have already authenticated.</p>

<p>There is a problem with these keys, however, if they are not truly random. This is detailed in a paper I stumbled upon entitled &#8220;Brute-Force Exploitation of Web Application Session IDs&#8221; by David Endler. It covers ways in which these keys can be &#8220;hacked&#8221; because they are not unique, but rather follow some sequence which can be guessed. He lists some major websites which he was able to get access to information that should have been private.</p>

<p>The paper got me thinking about how to generate random session keys, so I created some quick Python scripts using Twisted which demonstrates my solution. (This was my first time using Twisted, so it&#8217;s very possible that there is a better way to structure the code).</p>

<h4>Solution</h4>

<p>The character buffer in the server is used to generate new keys.</p>

<p>To fill the buffer:</p>

<p>0. Create a list of websites which themselves deliver random web pages (eg, wikipedia)<br />
1. Select a website from random and ask for a random page<br />
2. Grab the data within the <span class="caps">HTML </span><em>body</em> tags and put that string in the character buffer<br />
3. When the buffer needs more data, go back to 1.</p>

<p>To generate X number of keys:</p>

<p>0. Grab two random lengths of the character buffer. Use one to re-seed the random generator and the other as the basis for the new session key. Create the session key using <span class="caps">MD5 </span>and the key seed<br />
1. Update() the current <span class="caps">MD5 </span>session key using a generated random character / string<br />
2. Add that key to the buffer.<br />
3. When the key buffer needs more keys, go back to Step 1. For every Y number of keys generated, go back to Step 0.</p>


<h4>Notes</h4>

<p>We don&#8217;t use a a new seed for each <span class="caps">MD5 </span>session key because the buffer will be emptied too quickly. Of course, the settings for the buffer size, etc could be tweaked.</p>

<h4>Performance</h4>

<p>Running the server code on my Mac Mini (2.16GHz Dual Core) and 5 clients on another machine, I was able to service ~8000 keys/sec (~750 million keys/day).</p>

<h4>Conclusion</h4>

<p>My experiment satisfied my curiosity and answered the questions from my own project.</p>

<p>There are, of course, many tweaks that can be made. Send me the code changes to your favorites and I&#8217;ll include them.</p>

<p><a href="/downloads/code/HTTP-Session-Key.zip">Click to download the client server files.</a></p>

<h3>Resources</h3>


<ul>
<li><a href="http://www.cgisecurity.com/lib/SessionIDs.pdf">Brute-Force Exploitation fo Web Application Session IDs</a> (PDF)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/09/generating-random-session-ids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KryptoPhoto Photo Viewer is Released</title>
		<link>http://davidmccuskey.com/2009/08/kryptophoto-photo-viewer-is-released/</link>
		<comments>http://davidmccuskey.com/2009/08/kryptophoto-photo-viewer-is-released/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 18:38:44 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[KryptoPhoto release]]></category>

		<guid isPermaLink="false">http://www.mccuskey.com/?p=572</guid>
		<description><![CDATA[I have released my new photo viewer, so now I can once again show my photography on this site. It currently supports the API at SmugMug.com, but I have plans for compatibility with other photo-sharing sites. I built it using the Adobe Flex framework. You can get more information about KryptoPhoto at MentalHijack.com.]]></description>
			<content:encoded><![CDATA[<p>I have released my new photo viewer, so now I can once again show <a href="/photography/">my photography</a> on this site. It currently supports the <span class="caps">API </span>at SmugMug.com, but I have plans for compatibility with other photo-sharing sites.</p>

<p>I built it using the Adobe Flex framework. You can <a href="http://www.mentalhijack.com/software/kryptophoto/">get more information about KryptoPhoto at MentalHijack.com.</a></p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/08/kryptophoto-photo-viewer-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to do custom chart annotations in Flex</title>
		<link>http://davidmccuskey.com/2009/03/how-to-do-custom-chart-annotations-in-flex/</link>
		<comments>http://davidmccuskey.com/2009/03/how-to-do-custom-chart-annotations-in-flex/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:16:14 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[annotationElements]]></category>
		<category><![CDATA[backgroundElements]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/?p=150</guid>
		<description><![CDATA[Hunting around the &#8216;Net, I found a few good examples of creating chart annotations in Flex. One example app which helped me greatly was from a blog posting by Ely Greenfield. If you&#8217;re interested, you can view it on his website: chart annotation demo. Unfortunately, the code you can download from his site is a [...]]]></description>
			<content:encoded><![CDATA[<p>Hunting around the &#8216;Net, I found a few good examples of creating chart annotations in Flex.</p>

<p>One example app which helped me greatly was from a <a href="http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/">blog posting by Ely Greenfield</a>. If you&#8217;re interested, you can view it on his website: <a href="http://demo.quietlyscheming.com/overlayDemo/index.html">chart annotation demo</a>.</p>

<p>Unfortunately, the code you can download from his site is a little old so it has problems compiling in Flex Builder 2+. I have updated the code, fixed some bugs in it and have it available here: <a href="http://davidmccuskey.com/wp-content/uploads/2010/07/OverlayDemo-fixed.zip" title="OverlayDemo-fixed.zip">download OverlayDemo-fixed.zip</a>.</p>

<p>Ely has other interesting demos on his site which are worth checking out. Some of my favorites are: the <a href="http://www.quietlyscheming.com/blog/charts/variable-radius-pie-chart/">variable radius pie chart demo</a>, the <a href="http://www.quietlyscheming.com/blog/charts/variable-radius-pie-chart/">interactive bubble chart demo</a>, and the <a href="http://www.quietlyscheming.com/blog/charts/dashed-lines/">dashed lines demo</a>.</p>

<h3>Resources</h3>

<p><em>annotation example by Ely Greenfield</em></p>


<ul>
<li><a href="http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/">http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/</a></li>
<li>demo: <a href="http://demo.quietlyscheming.com/overlayDemo/index.html">http://demo.quietlyscheming.com/overlayDemo/index.html</a></li>
</ul>



<p><em>annotation example by Brendan Meutzner</em></p>


<ul>
<li><a href="http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements">http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements</a></li>
<li>demo: <a href="http://www.stretchmedia.ca/code_examples/chart_milestone/main.html">http://www.stretchmedia.ca/code_examples/chart_milestone/main.html</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/03/how-to-do-custom-chart-annotations-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trying to do MVC in pure Flex</title>
		<link>http://davidmccuskey.com/2009/02/trying-to-do-mvc-in-pure-flex/</link>
		<comments>http://davidmccuskey.com/2009/02/trying-to-do-mvc-in-pure-flex/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 06:37:32 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://blog.davidmccuskey.com/?p=108</guid>
		<description><![CDATA[I was looking for some examples of how to structure a Flex application using MVC, but using only the Flex framework. In the long run I think I&#8217;ll be using PureMVC, but right now I am anxious to get my app working and don&#8217;t want to have to learn Yet Another Technology just to get [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for some examples of how to structure a Flex application using <span class="caps">MVC, </span>but using only the Flex framework. In the long run I think I&#8217;ll be using PureMVC, but right now I am anxious to get my app working and don&#8217;t want to have to learn <em>Yet Another Technology</em> just to get there. Besides, shouldn&#8217;t Flex be able to stand on its own?</p>

<p>I found what I was looking for in the article <a href="http://www.adobe.com/devnet/flex/articles/blueprint.html"><em>&#8220;An architectural blueprint for Flex applications&#8221;</em></a> written by Joe Berkovitz. In it he talks about a way in which he architects Flex applications using pure Flex/Actionscript constructs.</p>

<p>Being a Flex newbie, I learned a lot from his article like how to pass variables to your own <span class="caps">MXML </span>tags and even customize them using Actionscript. His architecture also solves an issue I was having with Event messaging/bubbling due to the fact that it only works automatically on DisplayObject components. His design also has an interesting way of handling multiple data-services as well as the operations required for handling service communication.</p>

<p>Source code for the project is available in the article. I would recommended downloading it and browsing through the files.</p>

<p><strong>Resources:</strong></p>


<ul>
<li>&#8220;<em>An architectural blueprint for Flex applications</em>&#8221; written by Joe Berkovitz, <a href="http://www.adobe.com/devnet/flex/articles/blueprint.html">http://www.adobe.com/devnet/flex/articles/blueprint.html</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/02/trying-to-do-mvc-in-pure-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting journal entries from Outlook to MacJournal</title>
		<link>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/</link>
		<comments>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 05:26:49 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/converting-journal-entries-from-outlook-to-macjournal.html#unique-entry-id-22</guid>
		<description><![CDATA[I wrote a Python script to convert a journal file export from Microsoft Outlook to one which can be read by MacJournal. It requires the Python module csv (included with Python 2.3 or later) Run the script like so: ./outlook2macjournal.py [input_file] [output_file] If no input or output files are listed, it will use the following [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a Python script to convert a journal file export from Microsoft Outlook to one which can be read by MacJournal.</p>

<p>It requires the Python module csv (included with Python 2.3 or later)</p>

<p>Run the script like so:</p>


<pre>./outlook2macjournal.py [input_file] [output_file]</pre>


<p>If no input or output files are listed, it will use the following defaults:</p>

<p>Outlook (input): <code>exchange_export.csv</code><br />
MacJournal (output): <code>macjournal_import.txt</code></p>

<p>You can <a href="/wp-content/uploads/2010/07/outlook2macjournal.py_.zip" title="outlook2macjournal.py.zip"> click here to download the Outlook to MacJournal Python script</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2007/06/converting-journal-entries-from-outlook-to-macjournal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Template Method pattern handout now available</title>
		<link>http://davidmccuskey.com/2006/04/template-method-pattern-handout-now-available/</link>
		<comments>http://davidmccuskey.com/2006/04/template-method-pattern-handout-now-available/#comments</comments>
		<pubDate>Thu, 20 Apr 2006 02:35:06 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/template-method-pattern-handout-now-available.html#unique-entry-id-14</guid>
		<description><![CDATA[I have posted a PDF of the handout I made for my design patterns workgroup. The information came mostly from the O&#8217;Reilly book Head First Design Patterns. The layout and typography are roughly based on the format of the book as well. You can click here to download the Template Method handout.]]></description>
			<content:encoded><![CDATA[<p>I have posted a <span class="caps">PDF </span>of the handout I made for my design patterns workgroup. The information came mostly from the <span class="caps">O&#8217;R</span>eilly book <em>Head First Design Patterns</em>.</p>

<p>The layout and typography are roughly based on the format of the book as well.</p>

<p>You can <a href="/wp-content/uploads/2010/07/template_method.pdf" title="pdf">click here to download the Template Method handout</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2006/04/template-method-pattern-handout-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Pattern: A decorator in the wild</title>
		<link>http://davidmccuskey.com/2006/03/design-pattern-a-decorator-in-the-wild/</link>
		<comments>http://davidmccuskey.com/2006/03/design-pattern-a-decorator-in-the-wild/#comments</comments>
		<pubDate>Sat, 25 Mar 2006 03:14:12 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/design-pattern-a-decorator-in-the-wild.html#unique-entry-id-11</guid>
		<description><![CDATA[I&#8217;ve been looking over a lot of Javascript code lately, mostly in the various AJAX libraries. It&#8217;s been interesting to see the ways in which the different projects are using the language to enable them to coexist peacefully. Though, one such example I found was a simple function that I found at Simon Wilson&#8217;s web [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking over a lot of Javascript code lately, mostly in the various <span class="caps">AJAX </span>libraries. It&#8217;s been interesting to see the ways in which the different projects are using the language to enable them to coexist peacefully.</p>

<p>Though, one such example I found was a simple function that I found at <a href="http://simon.incutio.com/">Simon Wilson&#8217;s web site</a>. It solves the problem of having several Javascript modules fighting for the coveted <code>onload</code> event in the <span style="font-family: courier,monospace">&lt;body&gt;</span> tag. I say coveted because there is only one of these events on an <span class="caps">HTML </span>page, and it is very important because this event is called only after the entire page is loaded. For a Javascript module, this is a good time to do an action like initialization because it guarantees that any called functions will be able to work on on a complete set of <span class="caps">HTML </span>tags, Javascript modules, images, etc.</p>

<h3>The Past</h3>

<p>Before the widespread use of Javascript, the <code>onload</code> function would simply be set in the <span class="caps">HTML </span>@@ tag on a page.:</p>


<pre><!--mce:0-->

   .
   .</pre>


<p>And if there were several methods to be called, you could make the <code>onload</code> function more generic by using it to call other methods:</p>


<pre><!--mce:1-->

   .
   .</pre>


<p>But this only works well if you are the creator of all of the code which goes into a site.</p>

<h3>The Present</h3>

<p>Now that we&#8217;re seeing a ton of development happening on the <span class="caps">HTML</span>-side of things, especially from the <span class="caps">AJAX</span>-world, it&#8217;s certain that folks will start using multiple Javascript modules on their sites and that some of these modules will want to get their piece of the <code>onload</code> event.</p>

<p>However, a problem arises if a module isn&#8217;t careful about how it sets the <code>onload</code> event. If it  uses basic Javascript syntax it would effectively wipeout any previously defined <code>onload</code> functions:</p>


<pre><!--mce:2--></pre>


<p>Enter in <a href="http://simon.incutio.com/archive/2004/05/26/addLoadEvent">Simon&#8217;s addLoadEvent function</a> which uses Javascript closures wrapped in a decorator-like fashion to allow more than one function to be assigned to the &#8216;onload&#8217; event at runtime.</p>

<p>This is the code listing pasted from Simon&#8217;s site:</p>


<pre>function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
  /* more code to run on page load */
});</pre>


<p>However, I will note that this solution is not a <em>pure</em> example of the decorator pattern because:</p>

<p>1. The definition from my Head Start book states &#8220;The Decoration Pattern involves a set of decorator classes that are used to wrap concrete components.&#8221; In this example the concrete component, the very innermost function, is of the same class as the  closure decorators &#8211; a function &#8211; and not of a separate object type.</p>

<p>2. Also the function objects get called themselves rather then a separate method on a class object. However, I think this would be ok if you consider each function having an equivalent to Python&#8217;s  <code>__call__</code> method. This method would then be the common interface between the objects.</p>

<p>In any event, pure Decorator or not, this is a clever way to use Javascript to solve this web problem and at least deserves a <em>Decorator Honorable Mention</em>.</p>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2006/03/design-pattern-a-decorator-in-the-wild/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first `case` statement in 60 months.</title>
		<link>http://davidmccuskey.com/2006/03/my-first-case-statement-in-60-months/</link>
		<comments>http://davidmccuskey.com/2006/03/my-first-case-statement-in-60-months/#comments</comments>
		<pubDate>Thu, 23 Mar 2006 03:11:11 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/my-first-case-statement-in-60-months.html#unique-entry-id-10</guid>
		<description><![CDATA[The first time flipping through my O&#8217;Reilly Javascript Definitive Guide, I was pleasantly surprised to read that Javascript had a case statement. I&#8217;m not sure why I was surprised, but I guess I forgot about it considering that I have been programming in Perl1 and Python for so long. The other day, I came across [...]]]></description>
			<content:encoded><![CDATA[<p>The first time flipping through my <em><span class="caps">O&#8217;R</span>eilly Javascript Definitive Guide</em>, I was pleasantly surprised to read that Javascript had a <code>case</code> statement. I&#8217;m not sure why I was surprised, but I guess I forgot about it considering that I have been programming in Perl<sup class="footnote"><a href="#fn1">1</a></sup> and Python for so long.</p>

<p>The other day, I came across a <code>case</code> statement while glancing through some Javascript code from another company. This time I made a mental note to use it the next time that I could.</p>

Well, my chance arrived yesterday while doing a project for work. Our designer had wanted to place bounding corners at certain sections on the page. I was going to position a @<br />
<div>@ at the corner of each section and then turn off the appropriate borders to give it the look he wanted. I had named each @
<div>@ corner using a suffix which described its location (eg, tl &#8211; top left) and wanted to think of a way to map that name to the borders which were to be showing.

<p>Here is the incomplete code using a <code>case</code> statement. I think it is more concise and easier to read than if it had been written using @if@ statements.</p>

<p>My First Javascript Case Statement:</p>


<pre>this.corner_suffix = ['tl','tr','br','bl'];

for( i = 0; i &amp;lt; this.corner_suffix.length; i++ ) {

  // the first character takes care of top/bottom borders
  switch ( this.corner_suffix[i].charAt(0) ) {
    case 't':
      // set top location, turn off bottom border
      break;

    case 'b':
      // set bottom location, turn off top border
      break;
  }
  // the second character takes care of left/right borders
  switch ( this.corner_suffix[i].charAt(1) ) {
    case 'r':
      // set right location, turn off left border
      break;

    case 'l':
      // set left location, turn off right border
      break;
    }
}</pre>


<p>I was happy to have rediscovered the <code>case</code> statement and found that it was very natural to write it once I had remembered the rules for <code>break</code> and <code>default</code>. It&#8217;s like meeting an old friend: you get along instantly and continue without missing a beat.</p>

I stopped programming in Perl sometime in 2002. I see that there is now a module called Switch, released sometime in 2002, which emulates a <code>case</code> construct.</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2006/03/my-first-case-statement-in-60-months/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing Python-style imports in JavaScript</title>
		<link>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/</link>
		<comments>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 02:53:57 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/files/doing-python-style-imports-in-javascript.html#unique-entry-id-7</guid>
		<description><![CDATA[Lately at work I&#8217;ve been doing a lot of programming in JavaScript. Among other things, I have been learning about using the prototype object to do object oriented programming. One thing that I missed was the feature in Python used to import modules directly into other code. For example: from glorp import blah import foo [...]]]></description>
			<content:encoded><![CDATA[<p>Lately at work I&#8217;ve been doing a lot of programming in JavaScript. Among other things, I have been learning about using the prototype object to do object oriented programming. One thing that I missed was the feature in Python used to import modules directly into other code. For example:</p>


<pre>from glorp import blah
import foo</pre>


<p>I was happy to have found an open-source project which emulates that functionality in JavaScript! I haven&#8217;t been able to do more than skim the web site, but it looks promising.</p>

<h3>Resources</h3>


<ul>
<li><a rel="external" href="http://ajile.sourceforge.net/">http://ajile.sourceforge.net/</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2006/03/doing-python-style-imports-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

