<?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; Code Sample</title>
	<atom:link href="http://davidmccuskey.com/category/code-sample/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>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>How to build and install the Metakit DB for Python on MacOSX</title>
		<link>http://davidmccuskey.com/2009/02/how-to-build-and-install-the-metakit-db-for-python-on-macosx/</link>
		<comments>http://davidmccuskey.com/2009/02/how-to-build-and-install-the-metakit-db-for-python-on-macosx/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 02:39:38 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Code Sample]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[metakit]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.davidmccuskey.com/?p=237</guid>
		<description><![CDATA[Ever since I used it years ago on a geek-project for my Zaurus, the Metakit DB has always been a favorite of mine. I had the chance to use it again on another personal project and this time on MacOSX. Unfortunately, the prebuilt binaries on the Metakit site are for older versions of MacOSX, so [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I used it years ago on a geek-project for my Zaurus, the Metakit DB has always been a favorite of mine. I had the chance to use it again on another personal project and this time on MacOSX. Unfortunately, the prebuilt binaries on the Metakit site are for older versions of MacOSX, so I had to build it myself.</p>

<p>Normally one would simply follow the <a href="http://www.equi4.com/pub/mk/">Metakit installation instructions</a>, but they are old and didn&#8217;t work correctly with 10.5 Leopard. I scraped enough information together from the Internet to get it working, but I had to do a lot of research. To save others the same hassle, I have put together all of the changes and put them here in their entirety:</p>

<p><strong>Building Metakit</strong></p>

<p>Make sure you have Xcode installed on your system before starting.</p>

<p>Get the latest source from the <a href="http://www.equi4.com/pub/mk/">Metakit downloads page</a>. At this time the latest version is <code>metakit-2.4.9.7.tar.gz</code>.</p>

<p>Uncompress the archive in a work directory and run the following commands:</p>



<pre>
&amp;gt; cd builds
&amp;gt; ../unix/configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.5
</pre>



<p>Note: Your Python install might be in a different location. If so, give the  <code>--with-python</code> arg the proper value.</p>

<p><em>&#8220;Fat&#8221; binary setup</em></p>

<p>If you need this to run on the <span class="caps">PPC </span>architecture you will need to make a couple of modifications to <code>./builds/Makefile</code> <em>after</em> running <code>configure</code>, otherwise you can skip this step and build the binaries with <code>make</code>.</p>

<p>Find <code>CXXFLAGS = $(CXX_FLAGS)</code> and change to the following:</p>



<pre>
CXXFLAGS = $(CXX_FLAGS) -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
</pre>



<p>Find <code>SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress</code> and change to the following:</p>



<pre>
SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress -arch ppc -arch i386
</pre>



<p><em>Build the binaries</em></p>

<p>Run your typical <code>Makefile</code> commands:</p>



<pre>
&amp;gt; make
&amp;gt; make test
</pre>



<p><strong>Installing Metakit</strong></p>

<p>Rename the shared library which is now in the <code>./builds</code> directory:</p>



<pre>
&amp;gt; mv Mk4py.dylib Mk4py.so
</pre>



<p>And copy the following files to <code>/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python</code> (be sure to adjust the path name for your version of Python):</p>



<pre>
../python/metakit.py
./Mk4py.so
</pre>



<p><strong>Testing Metakit</strong></p>

<p>At this point you should have a working system and ought to be able to run the following command in a Python shell without issue:</p>



<pre>
&amp;gt;&amp;gt;&amp;gt;from metakit import *
</pre>



<p>Enjoy !</p>

<h3>Resources</h3>


<ul>
<li><a href="http://www.equi4.com/metakit/python.html">Metakit for Python website</a></li>
</ul>




<ul>
<li><a href="http://www.ospace.net/wiki/index.php/ServerHowTo">helpful instructions from www.ospace.net</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://davidmccuskey.com/2009/02/how-to-build-and-install-the-metakit-db-for-python-on-macosx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

