<?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>CodeDread Blog &#187; Tips</title>
	<atom:link href="http://www.codedread.com/blog/archives/category/technology/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codedread.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 02 Jan 2012 15:30:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Creating a Camera Archive Folder</title>
		<link>http://www.codedread.com/blog/archives/2012/01/02/creating-a-camera-archive-folder/</link>
		<comments>http://www.codedread.com/blog/archives/2012/01/02/creating-a-camera-archive-folder/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 15:28:51 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.codedread.com/blog/?p=1037</guid>
		<description><![CDATA[I kind of forgot about the idea of writing in my blog so that I can find the answers again via Google. Well here&#8217;s a quick one: How to backup the entire contents of your webcam (I own a Sony HDR-XR150) to a &#8220;Camera Archive Folder&#8221; on OSX. Open up iMovie Go to &#8220;File > [...]]]></description>
			<content:encoded><![CDATA[<p><img width="100" height="100" style="float:right" src="http://codedread.com/clipart/photo.svgz" alt="A simple vector image of a camera" /><br />
I kind of forgot about the idea of writing in my blog so that I can find the answers again via Google.  Well here&#8217;s a quick one:  How to backup the entire contents of your webcam (I own a Sony HDR-XR150) to a &#8220;Camera Archive Folder&#8221; on OSX.</p>
<ol>
<li>Open up iMovie</li>
<li>Go to &#8220;File > Import from Camera&#8221; or the click big camera button under the Project Library pane</li>
<li>Click the &#8220;Archive All&#8221; button beside &#8220;Camera: Sony HDR-XR150&#8243;</li>
<li>Choose a location to save the entire contents of your camera (I use portable hard drives)</li>
</ol>
<p>After doing this, you&#8217;ll have a &#8220;Camera Archive Folder&#8221; where you can import movies into iMovie for your editing pleasure.</p>
<div id="attachment_1039" class="wp-caption alignnone" style="width: 655px"><a href="http://www.codedread.com/blog/wp-content/uploads/2012/01/Capture-Status.jpg"><img src="http://www.codedread.com/blog/wp-content/uploads/2012/01/Capture-Status.jpg" alt="Screenshot of iMovie and the Archive All button" title="iMovie Archive All" width="645" height="483" class="size-full wp-image-1039" /></a><p class="wp-caption-text">Screenshot of iMovie and the Archive All button</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2012/01/02/creating-a-camera-archive-folder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Know The Beast</title>
		<link>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/</link>
		<comments>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 01:07:09 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://www.codedread.com/blog/?p=757</guid>
		<description><![CDATA[[clipart]Cameron Adams decided to benchmark Flash, SVG, Canvas and HTML5 using a particle engine he created. Not surprising (to me anyway), the SVG scores were the worst of the bunch. This stands to reason: does each particle really need to be a DOM element? Nonetheless, I decided to see what I could do to make [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" style="float:right" data="http://codedread.com/clipart/tools.svgz">[clipart]</object><a href="http://www.themaninblue.com/writing/perspective/2010/03/22/">Cameron Adams</a> decided to benchmark Flash, SVG, Canvas and HTML5 using a particle engine he created.  Not surprising (to me anyway), the SVG scores were the worst of the bunch.  This stands to reason:  does each particle really need to be a DOM element?  Nonetheless, I decided to see what I could do to make the SVG scores suck less.  I thought I&#8217;d use it as an opportunity to also teach some techniques.</p>
<p><strong>Update: Added some browser scores for Nov 2011</strong></p>
<p><span id="more-757"></span></p>
<h3>Particle Creation</h3>
<p>Cameron initializes the particles this way:</p>
<pre>
	var domNode = document.createElementNS(SVG_NS, "circle");
	var benchmark = document.getElementById("benchmark");
	benchmark.appendChild(domNode);

	// Set initial position to middle of screen
	domNode.setAttribute("cx", x + PARTICLE_RADIUS);
	domNode.setAttribute("cy", y + PARTICLE_RADIUS);
	domNode.setAttribute("r", PARTICLE_RADIUS);

	// Set colour of element
	domNode.setAttribute("fill", COLORS[Math.floor(Math.random() * COLORS.length)]);
</pre>
<p>That is, he creates a svg:circle element, then appends it to the DOM, then modifies its attributes.  Every time an attribute is changed in the DOM it has the potential to cause a layout/render change.  Thus, it makes more sense (to me) to attach the circle to the DOM only after you&#8217;re done initializing the element (i.e. after all the setAttribute calls).</p>
<p>This doesn&#8217;t affect the frame-rate, since creation only happens at the beginning, but it might affect the startup time of the animation so I thought I&#8217;d drop it in this post.</p>
<h3>DOM Animation &#8211; the Naive Approach</h3>
<p>Next, he has a function that is called as fast as possible to animate the particles.  The animate function does a simple loop over all particles and calls a draw() function.  The particle&#8217;s draw function does this:</p>
<pre>
		// lots of other JS code here
		domNode.setAttribute("cx", nextX + PARTICLE_RADIUS);
		domNode.setAttribute("cy", nextY + PARTICLE_RADIUS);
</pre>
<p>The problem with this again is that each DOM call can cause a re-render.  This means if you have 500 particles, there are 1000 DOM calls affecting the rendering with every call to animate().  Depending on how stupid the browser is, this could be expensive.</p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle.xhtml">Click here to try the original demo</a></li>
</ul>
<table>
<thead>Original Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>1.75 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>1.9 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>3.8 fps</strong></td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>12.5 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>14.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>28 fps</td>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>32 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>40 fps</td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>55 fps</strong></td>
</tr>
</table>
<h3 id="suspendredraw">Suspension</h3>
<p>My first attempt was to use suspendRedraw() and unsuspendRedraw() around the for-loop that calls particle.draw().  This is the SVG-recommended way to do a bunch of operations &#8216;off-screen&#8217; and then have the results updated in one-shot.  This <em>did</em> have an effect on Firefox&#8217;s frame rate.  </p>
<p>But it didn&#8217;t really seem to affect WebKit&#8217;s performance at all.  Looking at the WebKit source (svg/SVGSVGElement.cpp) it&#8217;s pretty easy to see why:</p>
<pre>
unsigned SVGSVGElement::suspendRedraw(unsigned /* maxWaitMilliseconds */)
{
    // FIXME: Implement me (see bug 11275)
    return 0;
}
</pre>
<p>Maybe WebKit will one day implement this and the technique will become more broadly useful. <strong>[Update Nov 2011: This has been implemented in WebKit]</strong></p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle-suspend.xhtml">Click here to try the demo that uses suspendRedraw</a></li>
</ul>
<table>
<thead>SuspendRedraw Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>3.2 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>3.4 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>8 fps</strong></td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>8.2 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>23.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>N/A</td>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>32 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>40 fps</td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>45 fps</strong></td>
</tr>
</table>
<p>NOTE: IE9 Preview 1 has not implemented suspendRedraw() and the demo does not run.</p>
<h3 id="manual-offscreen">Manually Doing Off-Screen Rendering</h3>
<p>I then went and did something crazy.  </p>
<p>I added a svg:g (group) element to the particle test, added all the particles to it.  Then with each call to render, I remove the &#60;g&#62; from the DOM, call all the particle draw() functions, then re-add the &#60;g&#62; to the DOM.  </p>
<p>This had a <em>dramatic</em> effect on Firefox&#8217;s performance, but it seemed to slow down Safari and Opera.  Not sure why that would be, but I guess they have much more sensible ways of updating the rendered state of the DOM than Firefox so that removing and adding an element to the DOM becomes more expensive.</p>
<ul>
<li><a href="http://codedread.com/browser-tests/particle/particle-g.xhtml">Click here to try the demo with manual off-screen rendering</a></li>
</ul>
<table>
<thead>Manual Offscreening Results</thead>
<tr>
<th>Browser</th>
<th>Frame Rate</th>
</tr>
<tr>
<td>Safari 4.0.5 (OSX)</td>
<td>12.75 fps</td>
</tr>
<tr>
<td>Opera 10.10 (OSX)</td>
<td>14 fps</td>
</tr>
<tr>
<td>Firefox 3.6 (OSX)</td>
<td>21.5 fps</td>
</tr>
<tr>
<td>Firefox 3.7 Nightly (OSX)</td>
<td>21.5 fps</td>
</tr>
<tr>
<td>Opera 10.50 (OSX)</td>
<td>23.5 fps</td>
</tr>
<tr>
<td>IE9 Preview 1 (Win7 VM)</td>
<td>25 fps</td>
</tr>
<tr>
<td>Chrome 5 Nightly (OSX)</td>
<td>26.5 fps</td>
</tr>
<tr>
<td>Firefox 8 Beta (OSX)</td>
<td><strong>37 fps</strong></td>
</tr>
<tr>
<td>Chromium 17 Nightly (OSX)</td>
<td><strong>49 fps</strong></td>
</tr>
</table>
<h3>Conclusion</h3>
<p>This blog post is really just an attempt to share the knowledge about some of the challenges in using SVG for high-performance demos.  Basically don&#8217;t change the live DOM if you can avoid it.</p>
<p>Note that I still stand by my original statement that SVG is not the right technology for particle effects unless you need mouse interactivity.  This type of demo is much more suitable for HTML5&#8242;s &#60;canvas&#62; element.  Let&#8217;s hope IE9 also implements a GPU-accelerated version of this element too!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2010/03/22/know-the-beast/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>MIX 10k Code Challenge += SVG</title>
		<link>http://www.codedread.com/blog/archives/2010/01/14/mix-10k-code-challenge-svg/</link>
		<comments>http://www.codedread.com/blog/archives/2010/01/14/mix-10k-code-challenge-svg/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:56:59 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2010/01/14/mix-10k-code-challenge-svg/</guid>
		<description><![CDATA[[clipart]I came across the MIX 10k Coding Challenge on the weekend, and on a whim I decided to submit one of my old SVG demos to the contest. The 10k challenge&#8217;s tagline is &#8220;What could you create for the Web if you had only 10 kilobytes of code?&#8221;. The rules didn&#8217;t explicitly say I could [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" style="float:right" data="http://codedread.com/clipart/villain.svgz">[clipart]</object>I came across the <a href="http://mix10k.visitmix.com/">MIX 10k Coding Challenge</a> on the weekend, and on a whim I decided to submit one of my old SVG demos to the contest.  The 10k challenge&#8217;s tagline is &#8220;What could you create for the Web if you had only 10 kilobytes of code?&#8221;.  The rules didn&#8217;t explicitly say I could use pure SVG, they mention SVG/Canvas in the context of HTML5 only, but I thought I&#8217;d give it a shot.  It&#8217;s in the spirit of the contest, after all.  At the very least it would encourage Microsoft to clarify the rules and at the very best it would be accepted and the rules updated to allow pure SVG applications.  Looks like it was my lucky day.<span id="more-551"></span></p>
<p>I decided to go with my <a href="http://codedread.com/solitaire.php">Solitaire</a> demo because it was the most complete, didn&#8217;t infringe on any copyrights (looking at you Tetris), and most visually recognizable.  It&#8217;s not the most innovative, but then again the point of this is not necessarily to win any prizes.  It&#8217;s really about increasing awareness.</p>
<p>Unfortunately, the SVG (26kb) and JavaScript (16kb + 21kb) totaled 63kb.  I did some cleanup of the SVG, minified the JS and then put the script inline with the SVG and then gzipped it.  The result was a .svgz file that was 9kb.  Perfect!</p>
<p>I then got an email from a friendly marketing/evangelism person at Microsoft who said that the engineers did not know how to open the svgz file to review the code to ensure it was under 10k.  Woops!  I explained to her that I thought it would be ok for the SVG to be gzipped, much as PNG/GIF files use compression and sent her the uncompressed SVG file for them to review.  After all, SVG is just an image format, right? <img src='http://www.codedread.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Was I following the rules?  Did Microsoft give me a fair shake?  <a href="http://mix10k.visitmix.com/Entry/Details/160">See for yourself</a>.  Who knows, maybe this is the first time a Microsoft admin had to figure out how to serve SVG on a Microsoft web server.</p>
<p>Out of curiosity, I later tried to see how far I was able to get down the Solitaire game: <a href="http://codedread.com/solitaire.svgz">5811 bytes</a>.  Not bad for a complete game that has scalable graphics.  I&#8217;d be curios to see the equivalent SWF file.</p>
<p>I don&#8217;t expect you to vote for my entry, but what I do expect you to do is now go out and submit .SVGZ entries to the MIX 10k challenge.  That one SVG entry is looking pretty lonely.  If I can get Solitaire down to 5811 bytes, surely you can do better?</p>
<p>Thanks a lot to Amy, the evangelist/marketing person who really was quite patient with me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2010/01/14/mix-10k-code-challenge-svg/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Running Your Android App With A Single Click</title>
		<link>http://www.codedread.com/blog/archives/2009/02/02/running-your-android-app-with-a-single-click/</link>
		<comments>http://www.codedread.com/blog/archives/2009/02/02/running-your-android-app-with-a-single-click/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 17:26:20 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2009/02/02/running-your-android-app-with-a-single-click/</guid>
		<description><![CDATA[I&#8217;m not a big fan of Eclipse from a UI perspective, but I do acknowledge that it&#8217;s pervasive in the industry and some big projects are using it extensively. Plus it&#8217;s better than &#8216;vi&#8217; and the command-line. I guess Anyway, I&#8217;m sure I&#8217;ll get used to it. Here&#8217;s a really simple tip on using Eclipse [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" style="float:right" data="http://codedread.com/clipart/android.svgz"><span/></object><object type="image/svg+xml" width="100" height="100" style="float:right" data="http://codedread.com/clipart/eclipse.svgz"><span/></object>I&#8217;m not a big fan of Eclipse from a UI perspective, but I do acknowledge that it&#8217;s pervasive in the industry and some big projects are using it extensively.  Plus it&#8217;s better than &#8216;vi&#8217; and the command-line.  I guess <img src='http://www.codedread.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Anyway, I&#8217;m sure I&#8217;ll get used to it.  Here&#8217;s a really simple tip on using <a href="http://eclipse.org/">Eclipse</a> with <a href="http://code.google.com/android">Android</a> : <span id="more-520"></span></p>
<p>If you want to launch your app in one click in the emulator (instead of having to pick &#8220;Android Application&#8221; from that silly &#8220;Run As&#8221; window every time), then you need to go to Preferences > Run/Debug > Launching.  Under &#8220;Launch Operation&#8221;, choose &#8220;Always launch the previously launched application&#8221;.</p>
<p>The first time you&#8217;ll have to choose how to run your project (right-click on the project, Run As > Android Application).  Afterwards, all you&#8217;ll have to do is click the &#8220;Run&#8221; button (or the shortcut combo: Ctrl+Shift+F11).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2009/02/02/running-your-android-app-with-a-single-click/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C++ STL: Safely Removing Items From A Container</title>
		<link>http://www.codedread.com/blog/archives/2007/11/30/c-stl-safely-removing-items-from-a-container/</link>
		<comments>http://www.codedread.com/blog/archives/2007/11/30/c-stl-safely-removing-items-from-a-container/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 22:21:26 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/11/30/c-stl-safely-removing-items-from-a-container/</guid>
		<description><![CDATA[A short article about removing items from a standard C++ container. When using the C++ Standard Template Library, one has to be careful not to invalidate iterators in a container that you&#8217;re iterating over. If that makes any sense to you, then A colleague of mine had code like this: class TaskList { &#160;&#160;vector&#60;Task*> mTasks; [...]]]></description>
			<content:encoded><![CDATA[<p>A short article about removing items from a standard C++ container.  <span id="more-411"></span></p>
<p>When using the C++ Standard Template Library, one has to be careful not to invalidate iterators in a container that you&#8217;re iterating over.  If that makes any sense to you, then <!--more--></p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
<p>A colleague of mine had code like this:</p>
<p><code></p>
<p>class TaskList {</p>
<p>&#160;&#160;vector&#60;Task*> mTasks;</p>
<p>&#160;&#160;typedef vector&#60;Task*>::iterator TaskIter;</p>
<p>&#160;</p>
<p>&#160;&#160;void removeTask(Task* t) {</p>
<p>&#160;&#160;&#160;&#160;TaskIter it = find(mTasks.begin(),mTasks.end(),t);</p>
<p>&#160;&#160;&#160;&#160;if(it != mTasks.end()) { mTasks.erase(it); }</p>
<p>&#160;&#160;}</p>
<p>&#160;</p>
<p>&#160;public:</p>
<p>&#160;&#160;void addTask(Task* t) { mTasks.push_back(t); }</p>
<p>&#160;</p>
<p>&#160;&#160;void processQueue() {</p>
<p>&#160;&#160;&#160;&#160;for(TaskIter loopit=mTasks.begin();loopit!=mTasks.end();++loopit) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;Task* task = *loopit;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;if(task->isNotDone()) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;task->doSomething();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;else {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;removeTask(task);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;}</p>
<p>};</p>
<p></code></p>
<p>You might be surprised to hear that the program crashed when the first task had to be removed.  The reason is that the removeTask() function erases an item out the collection which invalidates the iterator loopit.  When the for-loop tries to increment the iterator, we get <i>unexpected results</i>.</p>
<p>This is a frustrating problem, but it can be solved.  In short you have to:</p>
<ul>
<li>grab the iterator that is returned from the erase operation</li>
<li>set your loop iterator to that returned iterator</li>
<li>change from a for-loop to a while-loop (to ensure that your loop iterator is not incremented when a task is removed)</li>
</ul>
<p>Here is the modified code:</p>
<p><code></p>
<p>&#160;&#160;TaskIter removeTask(Task* t) {</p>
<p>&#160;&#160;&#160;&#160;TaskIter it = find(mTasks.begin(); mTasks.end(), t);</p>
<p>&#160;&#160;&#160;&#160;if(it != mTasks.end()) { it = mTasks.erase(it); }</p>
<p>&#160;&#160;&#160;&#160;return it;</p>
<p>&#160;&#160;}</p>
<p>&#160;</p>
<p>&#160;&#160;void processQueue() {</p>
<p>&#160;&#160;&#160;&#160;TaskIter loopit = mTasks.begin();</p>
<p>&#160;&#160;&#160;&#160;while(loopit != mTasks.end()) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;Task* task = *loopit;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;if(task->isNotDone()) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;task->doSomething();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;++loopit;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;else {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;loopit = removeTask(task);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;&#160;&#160;}</p>
<p>&#160;&#160;}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/11/30/c-stl-safely-removing-items-from-a-container/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Windows on a MacBook Pro: Keyboard Differences</title>
		<link>http://www.codedread.com/blog/archives/2007/11/30/windows-on-a-macbook-pro-keyboard-differences/</link>
		<comments>http://www.codedread.com/blog/archives/2007/11/30/windows-on-a-macbook-pro-keyboard-differences/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 21:33:25 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/11/30/windows-on-a-macbook-pro-keyboard-differences/</guid>
		<description><![CDATA[I recently got ahold of a nice MacBook Pro and I&#8217;m using it as my primary Windows box at work. It&#8217;s nice and snappy and I like it, but I&#8217;m having trouble getting used to the keyboard, let alone the one-button mousepad. I thought I&#8217;d use this post to collapse several google searches into one [...]]]></description>
			<content:encoded><![CDATA[<p><object type="image/svg+xml" width="100" height="100" align="right" hspace="10" data="http://codedread.com/clipart/windows.svgz"><span/></object>I recently got ahold of a nice MacBook Pro and I&#8217;m using it as my primary Windows box at work.  It&#8217;s nice and snappy and I like it, but I&#8217;m having trouble getting used to the keyboard, let alone the one-button mousepad.  I thought I&#8217;d use this post to collapse several google searches into one location.  I&#8217;ll likely add to this list as I learn more tricks.<span id="more-410"></span></p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
<table border="1">
<tr>
<th>Windows Shortcut</th>
<th>MacBook Pro Equivalent</th>
<th>Function+Notes</th>
</tr>
<tr>
<td>Alt+PrintScreen</td>
<td>fn+F11</td>
<td>copy screen capture of entire desktop to clipboard</td>
</tr>
<tr>
<td>Ctrl+PrintScreen</td>
<td>fn+option+F11</td>
<td>copy screen capture of current window to clipboard</td>
</tr>
<tr>
<td>Insert</td>
<td>fn+bottom enter key (next to arrows)</td>
<td>overstrike mode</td>
</tr>
<tr>
<td>Shift+Insert</td>
<td>ctrl+v</td>
<td>paste clipboard</td>
</tr>
<tr>
<td>Shift+Delete</td>
<td>ctrl+x</td>
<td>cut selected</td>
</tr>
<tr>
<td>Backspace</td>
<td>Delete</td>
<td>delete character to left of caret</td>
</tr>
<tr>
<td>Delete</td>
<td>fn+Delete</td>
<td>not backspace, but delete character to right of caret</td>
</tr>
<tr>
<td>Home</td>
<td>fn+left arrow</td>
<td>put caret at beginning of line</td>
</tr>
<tr>
<td>End</td>
<td>fn+right arrow</td>
<td>put caret at end of line</td>
</tr>
<tr>
<td>PgUp</td>
<td>fn+up arrow</td>
<td>page up</td>
</tr>
<tr>
<td>PgDn</td>
<td>fn+down arrow</td>
<td>page down</td>
</tr>
<tr>
<td>Ctrl+PgUp</td>
<td>no equivalent</td>
<td>Go to top of document</td>
</tr>
<tr>
<td>Ctrl+PgDn</td>
<td>no equivalent</td>
<td>Go to bottom of document</td>
</tr>
<tr>
<td>Function keys</td>
<td>fn+Function key</td>
<td>Various things. You can switch this behavior in Control Panel > Boot Camp if you want, I recommend this</td>
</tr>
<tr>
<td>Right-click Mouse</td>
<td>put two fingers on mousepad and press button</td>
<td>Bring Up Context Menu</td>
</tr>
</table>
<p>And finally, some flamebait questions:</p>
<ul>
<li>Why in God&#8217;s name are there duplicate enter and Apple keys?!?</li>
<li>Does anyone REALLY think the MacBook right-click equivalent is simpler than putting two #@!$ buttons on the pad?!?  That button is huge-ass!</li>
</ul>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/11/30/windows-on-a-macbook-pro-keyboard-differences/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Re-Sourcing Environment Variables in Windows</title>
		<link>http://www.codedread.com/blog/archives/2007/10/03/re-sourcing-environment-variables-in-windows/</link>
		<comments>http://www.codedread.com/blog/archives/2007/10/03/re-sourcing-environment-variables-in-windows/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 15:15:53 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/10/03/re-sourcing-environment-variables-in-windows/</guid>
		<description><![CDATA[I added some Environment Variables to my Windows operating system recently (right-click on My Computer, Properties, Advanced, Environment Variables). I was wondering if there is any way from an existing Command Prompt to pick those up. I know that all Command Prompt instances after this point will have those new environment variables defined, but I [...]]]></description>
			<content:encoded><![CDATA[<p><object class="clip" type="image/svg+xml" data="http://www.codedread.com/clipart/windows.svgz"><span/></object>I added some Environment Variables to my Windows operating system recently (right-click on My Computer, Properties, Advanced, Environment Variables).  I was wondering if there is any way from an existing Command Prompt to pick those up.  I know that all Command Prompt instances after this point will have those new environment variables defined, but I was just curious if there was an easy way to get an existing Command Prompt instance to &#8220;re-source&#8221; its environment variables.</p>
<p>On the other hand, is there any way to add a System Environment Variable to Windows from the command prompt?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/10/03/re-sourcing-environment-variables-in-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using tar to Snapshot a Subversion Working Directory</title>
		<link>http://www.codedread.com/blog/archives/2007/04/26/using-tar-to-snapshot-a-subversion-working-directory/</link>
		<comments>http://www.codedread.com/blog/archives/2007/04/26/using-tar-to-snapshot-a-subversion-working-directory/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 16:57:31 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/04/26/using-tar-to-snapshot-a-subversion-working-directory/</guid>
		<description><![CDATA[I have a bunch of different Subversion repositories where I store documents. Occasionally I&#8217;ll place some unversioned files in these directories while working on something. Today I needed to take a snapshot of the contents of my hard drive but I didn&#8217;t want to keep all the hidden .svn directories. Here&#8217;s what worked for me. [...]]]></description>
			<content:encoded><![CDATA[<p>I have a bunch of different <a href="http://subversion.tigris.org/">Subversion</a> repositories where I store documents.  Occasionally I&#8217;ll place some unversioned files in these directories while working on something.  Today I needed to take a snapshot of the contents of my hard drive but I didn&#8217;t want to keep all the hidden .svn directories.  Here&#8217;s what worked for me.  <span id="more-367"></span></p>
<p>First, to clarify &#8211; what I wanted to do was take a snapshot of all files in my working directories (even the non-versioned ones).  In some cases, the SVN server was no longer around (for one reason or another) so this was really about taking the files on my hard drive and archiving them somewhere (but removing the .svn hidden files and directories).</p>
<p>I use <a href="http://www.cygwin.com/">cygwin</a> on my Windows box because I love the power that Unix command line gives me.  Unfortunately, I hadn&#8217;t installed the man package in cygwin, so I used Google to find a <a href="http://www.cse.msu.edu/cgi-bin/man2html?tar">tar man page</a>.  It told me there is an exclude-file option (-X) so I did the following:</p>
<div class="code">
$ find &#124; grep \.svn$ &#124; cut -c3- > exclude.txt
</div>
<p>This creates a text file, called <i>exclude.txt</i> that has one line for every hidden .svn directory.  The reason I cut the first two characters out of the grep is because tar (for whatever reason) wouldn&#8217;t exclude a directory named &#8220;./blah/.svn&#8221; but it would exclude a directory named &#8220;blah/.svn&#8221;.</p>
<p>Once I had the exclude file, then I ran the tar command:</p>
<div class="code">
$ tar cvfX archive.tar exclude.txt dir1/* dir2/* &#8230;
</div>
<p>Hope it helps someone else&#8230;</p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/04/26/using-tar-to-snapshot-a-subversion-working-directory/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Knowing What The Browser Is Doing</title>
		<link>http://www.codedread.com/blog/archives/2007/04/19/knowing-what-the-browser-is-doing/</link>
		<comments>http://www.codedread.com/blog/archives/2007/04/19/knowing-what-the-browser-is-doing/#comments</comments>
		<pubDate>Thu, 19 Apr 2007 13:53:00 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/04/19/knowing-what-the-browser-is-doing/</guid>
		<description><![CDATA[Sometimes it&#8217;s not obvious how a document is being interpreted by a web browser. For instance, you might write some XHTML 1.1, but the browser actually interprets it as HTML 4. You may be expecting the browser to be using Standards Mode (recommended), but it might actually be using Quirks Mode because you missed the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s not obvious how a document is being interpreted by a web browser.  For instance, you might write some <a href="http://www.w3.org/TR/xhtml11/">XHTML 1.1</a>, but the browser actually interprets it as <a href="http://www.w3.org/TR/REC-html40/">HTML 4</a>.  You may be expecting the browser to be using Standards Mode (recommended), but it might actually be using <a href="http://en.wikipedia.org/wiki/Quirks_mode">Quirks Mode</a> because you missed the <a href="http://en.wikipedia.org/wiki/DOCTYPE">DOCTYPE</a> statement.  I&#8217;ll periodically update this blog entry to keep track of how to do this stuff in a variety of browsers.  <span id="more-360"></span></p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
<h3>Content Type</h3>
<p>Here&#8217;s a list of how to determine the content type (text/html, text/plain, application/xhtml+xml) that the browser is interpreting:</p>
<ul>
<li>Firefox:  Go to Tools > Page Info.  This tells you the type (text/html) and the rendering mode (Quirks or Standard)</li>
<li>Opera:  Go to View > Panels, then click on the Info button in this panel.  You can also click the left edge of the Opera window to get the Panels sidebar open.</li>
<li>Konqueror:  Go to View > Document Information.  This tells you the document type (text/html). </li>
</ul>
<p>If someone has a clue how to determine the content-type in IE (the developer toolbar didn&#8217;t help), Safari, Camino, please drop me a line below&#8230;</p>
<h3>Rendering Mode</h3>
<p>Firefox&#8217;s Tools > Page Info dialog box also tells you the rendering mode.</p>
<p>For other browsers, according to <a href="http://en.wikipedia.org/wiki/Quirks_mode">this page</a>, you can figure out the rendering mode of your own pages by looking at the DOM document.compatMode value using some JavaScript.</p>
<p>Again, drop me a line below if you know of a way to do this in a specific browser.</p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/04/19/knowing-what-the-browser-is-doing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Use IE Conditional Comments in &#8220;XHTML&#8221;</title>
		<link>http://www.codedread.com/blog/archives/2007/04/17/how-to-use-ie-conditional-comments-in-xhtml/</link>
		<comments>http://www.codedread.com/blog/archives/2007/04/17/how-to-use-ie-conditional-comments-in-xhtml/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 20:11:02 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.codedread.com/archives/2007/04/17/how-to-use-ie-conditional-comments-in-xhtml/</guid>
		<description><![CDATA[There&#8217;s a lot going on in the HTML Working Group mailing list right now about opt-in mechanisms for HTML5, discussions with smart people like Chris Wilson (co-chair and Microsoft IE champion) and Ian Hickson (WHATWG champion). I&#8217;ve going to sidestep the polemics for now &#8211; I&#8217;ve been trying to distill my own thoughts on that [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot going on in the HTML Working Group mailing list right now about opt-in mechanisms for HTML5, discussions with smart people like Chris Wilson (co-chair and Microsoft IE champion) and Ian Hickson (WHATWG champion).  I&#8217;ve going to sidestep the polemics for now &#8211; I&#8217;ve been trying to distill my own thoughts on that big debate, but things are still swirling around in my head because I&#8217;m still learning about the history of HTML, quirks mode, standards mode, DOCTYPEs, etc.  Instead, I&#8217;m just going to write a (hopefully) quick entry on something I just figured out today.  <span id="more-357"></span></p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
<p>If you are a web developer, I am sure you are very familiar with how difficult it can be to get the Internet Explorer browser to display your web pages correctly and still use web standards that are implemented more properly by other browsers.  Many hundreds of people wish that this were not so, but it&#8217;s an ugly fact in web development today.  IE includes a clever little feature called &#8220;<a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp">Conditional Comments</a>&#8221; that can allow you to select what elements on your page are displayed for certain versions of IE.  I wish that Conditional Comments were not necessary (because they muckify my markup), but that is the state things are in right now.</p>
<p>The traditional way of explaining this is by some examples:</p>
<div class="code">
<pre>
&#60;!--[if IE]>
  &#60;p>Only IE will display this paragraph&#60;/p>
&#60;![endif]-->
</pre>
</div>
<p><span style="font-weight:bold; color:green">Figure 1 &#8211; Conditional Comments for IE</span></p>
<p>If you know your HTML (especially how HTML comments work), then it should be pretty obvious that the whole code above looks like one big comment, meaning that it will not be displayed.  However, IE treats the square brackets differently by displaying the code between <i>[if IE]</i> and <i>[endif]</i> as code that it should display.</p>
<p>So that&#8217;s how to include code only for IE and exclude code from other browsers.  Now how to do the reverse:</p>
<div class="code">
<pre>
&#60;![if !IE]>
  &#60;p>All browsers except IE will display this paragraph&#60;/p>
&#60;![endif]-->
</pre>
</div>
<p><span style="font-weight:bold; color:#700">Figure 2 &#8211; Conditional Comments for Other Browsers (The Wrong Way)</span></p>
<p>In HTML browsers, the above code displays in every browser except IE (which will ignore everything between <i>[if !IE]</i> and <i>[endif]</i>).  It seems to rely on some de-facto implementations where anything between <i>&#60;!</i> and <i>&#62;</i> is ignored by browsers as if it was a comment.  The problem is that the above is not valid XHTML (comments in XHTML are anything between <i>&#60;!&#8211;</i> and <i>&#8211;&#62;</i>).</p>
<p>This is how I was feeding <a href="http://www.w3.org/Graphics/SVG/" title="Scalable Vector Graphics">SVG</a> to IE (in an <i>&#60;embed></i> element) and other browsers (in an <i>&#60;object></i> element).  However, it always rankled me that my pages wouldn&#8217;t validate as XHTML as a result of the conditional comments.</p>
<p>Then, I was reading <a href="http://www.xml.com/pub/a/2003/07/02/dive.html">this aging article</a> by <a href="http://www.diveintomark.org/">Mark Pilgrim</a> and found an example of valid &#8220;downlevel-revealed&#8221; comments (as Microsoft calls them):</p>
<div class="code">
<pre>
&#60;!--[if !IE]>-->
  &#60;p>All browsers except IE will display this paragraph&#60;/p>
&#60;!--&#60;![endif]-->
</pre>
</div>
<p><span style="font-weight:bold; color:green">Figure 3 &#8211; Conditional Comments for Other Browsers (The Right Way)</span></p>
<p>NOTE: It took me some time to figure this out because I was putting spaces between <i>[if !IE]></i> and <i>&#8211;></i> and between <i>[endif]</i> and <i>&#8211;></i>.  Make sure there are no spaces and things should work.  Here&#8217;s a <a href="http://www.codedread.com/test-cc.html">test page</a> so you can see how things work.  There should be 4 paragraphs displayed in every browser.</p>
<p>In fairness, after I started writing up this entry, I found that <a href="http://www.webmasterworld.com/css/3232700.htm" title="See Post 3239462 by Setek">several</a> <a href="http://www.cssplay.co.uk/menu/conditional.html">other</a> <a href="http://www.456bereastreet.com/archive/200511/valid_downlevelrevealed_conditional_comments/">people</a> had already discovered this.</p>
<p>Anyway, I know the other debate out there.  The one about how XHTML is not worth the trouble and can be harmful if served as text/html, but I&#8217;ve already written too much today to get into that <img src='http://www.codedread.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="ads"><object type="text/html" width="468" height="60" data="http://www.codedread.com/gads.php"></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.codedread.com/blog/archives/2007/04/17/how-to-use-ie-conditional-comments-in-xhtml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

