<?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>PlanetB &#187; Code</title>
	<atom:link href="http://www.planetb.ca/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.planetb.ca</link>
	<description></description>
	<lastBuildDate>Sat, 31 Dec 2011 23:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Looters, Project Updates, SVG and Adobe Air</title>
		<link>http://www.planetb.ca/2011/01/481/</link>
		<comments>http://www.planetb.ca/2011/01/481/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 03:43:39 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PlayBook]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=481</guid>
		<description><![CDATA[I&#8217;ve been hard at work on a few projects in my spare time, but no excuses for the lack of recent posts.  I&#8217;ve been concurrently reading both No More Mondays by Dan Miller and Atlus Shrugged by Ayn Rand.  While one is fiction and the other is not, they both ironically (and unintentionally) share a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.planetb.ca/wp-content/uploads/2011/01/hello-my-name-is-john-galt.jpg"><img class="aligncenter size-full wp-image-482" title="hello-my-name-is-john-galt" src="http://www.planetb.ca/wp-content/uploads/2011/01/hello-my-name-is-john-galt.jpg" alt="" width="500" height="375" /></a></p>
<p>I&#8217;ve been hard at work on a few projects in my spare time, but no excuses for the lack of recent posts.  I&#8217;ve been concurrently reading both No More Mondays by Dan Miller and Atlus Shrugged by Ayn Rand.  While one is fiction and the other is not, they both ironically (and unintentionally) share a theme &#8211; that one must take accountability of their own actions in order to accomplish any worthwhile goals.  Otherwise, complaining and shifting responsibilities and blame is the path to unhappiness and a life filled with woes. Of course, Any Rand doesn&#8217;t start really getting into this concept until around 450 pages into the book while No More Mondays isn&#8217;t even 1/4 the length of Atlus Shrugged.  Regardless, I&#8217;ve been enjoying both books (although this isn&#8217;t my first read of Atlus Shrugged, possibly my favorite novel).</p>
<p>I have some big plans to get through 3 books per month in 2011.  At the current rate, it looks like I&#8217;ll have to make up time in February, but I&#8217;m not at all jaded by the slow progress so far.  Onward and upward, so they say.</p>
<p>Life in project land has been moving at a quick pace.  Earlier this month I released a new website, Automated Web Design, which flaunts a simple web development technique for bloggers and Internet marketers.  <a href="http://www.automated-web-design.com">www.automated-web-design.com</a> provides a number of tutorial videos chronicling my creation of the site using Artisteer &#8211; a brilliant web theme template creator. It is possibly one of my favorite programs that allows me to build <a href="http://www.automated-web-design.com">WordPress or Joomla themes in minutes</a> (dead serious).</p>
<p>I&#8217;m also hard at work on a PlayBook app. My first frontier into PlayBook application development has been a fortunately smooth process.  Actionscript is an awesome language and Air is a great framework to be working in.  The fact that RIM chose Air as a main SDK for the PlayBook was a smart move IMO.</p>
<p>Along with the app development, I&#8217;ve found myself building tools to supplement the BlackBerry PlayBook Air SDK.  Some of those tools I&#8217;m hoping to release to the community soon.</p>
<p>As a result of all this PlayBook stuff, something that I&#8217;ve found myself looking into without much success in the last week has been Adobe&#8217;s FXG vector file format.  For whatever reason, in the latest Air/Flex SDK, Adobe has decided to deprecate the far more common SVG vector image file type in favor of their own markup that they call FXG.  It&#8217;s not that the schema or documentation is not available &#8211; as always, Adobe provides a good dish of documentation on their website.  The problem is that Adobe Illustrator is one of the very few programs capable of writing to this format and I&#8217;m not at all interested in purchasing Illustrator. Apparently Illustrator does a somewhat lousy job of converting from SVG to FXG anyway.</p>
<p>So in my quest to find more FXG related resources, I&#8217;ve put this tiny list together:<br />
<a href="http://fxgeditor.7jigen.net/edit/"><br />
fxgeditor.7jigen.net</a></p>
<p>fxgeditor is a simple Flash based FXG online vector graphics editor.  It supports shapes, paths, lines and some effects but doesn&#8217;t seem to do gradients very well &#8211; at least from what I saw.  But like I said &#8211; it&#8217;s simple and free.  Certainly no Illustrator, but often Illustrator is unnecessary.<br />
<a href="http://rome.adobe.com/">Project ROME by Adobe</a></p>
<p>This is interesting.  In an attempt to create creative software tools as a service, Adobe released &#8220;Project ROME&#8221;.  This app is available in both an online version and Air desktop application.  The application allows you to create documents in a variety of ways.  The documents can then be exported in a number of formats including FXG files.  Despite the potential that Project ROME seems to have, Adobe decided to stop development on it and released the application for free.  This, of course, works in our favor.<br />
<a href="https://bugs.launchpad.net/inkscape/+bug/625140">InkScape SVG to FXG xslt plugin</a></p>
<p>An extension was recently committed to the InkScape trunk for FXG exporting from the fantastic InkScape vector editor.  Post #24 in the link above describes how to install it.  Further down in the buglog (link above) there is a link to the updated xslt transform that is used to transform the SVG document to FXG.</p>
<p>Fortunately there is a difference between &#8220;deprecated&#8221; and &#8220;not supported&#8221; and SVG files can still be embedded into swf files. I can&#8217;t see that changing any time soon. In fact, I&#8217;d be seriously surprised if Adobe fully removed support for SVG.  It would be like (although arguably opposite) Google removing support for h264 video in Chrome&#8230; <a href="http://blog.chromium.org/2011/01/html-video-codec-support-in-chrome.html">oh wait</a>&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2011/01/481/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turn Tweets Into a PDF</title>
		<link>http://www.planetb.ca/2010/12/turn-tweets-into-a-pdf/</link>
		<comments>http://www.planetb.ca/2010/12/turn-tweets-into-a-pdf/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 20:28:45 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[appspot]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[twitter to pdf]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=471</guid>
		<description><![CDATA[Last night I tried my hand with Google&#8217;s app engine.  In short, I totally   dig it.  I figured I&#8217;d try to make a very simple app that turned recent   Twitter stream posts from a user into a PDF file.  It was fun, it was   stunningly easy and the Python MVC framework that the Google Apps [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tweets2pdf.appspot.com/" target="_blank"><img class="aligncenter size-full wp-image-472" title="tweets-2-pdf" src="http://www.planetb.ca/wp-content/uploads/2010/12/tweets-2-pdf.jpg" alt="" width="350" height="228" /></a></p>
<p>Last night I tried my hand with<a href="http://appengine.google.com" target="_blank"> Google&#8217;s app engine</a>.  In short, I totally   dig it.  I figured I&#8217;d try to make a very simple app that turned recent   Twitter stream posts from a user into a PDF file.  It was fun, it was   stunningly easy and the Python MVC framework that the Google Apps Engine uses is very nice.</p>
<p>The app performs a jquery JSONp lookup on the entered user screen name to  first make sure it&#8217;s valid and verify that the Twitter API isn&#8217;t &#8220;Fail  Whale&#8221;.  Then it submits the user screen name to a POST handler.  The POST  handler uses a Google App Engine URL fetch() to retrieve the top 100  tweets from the user&#8217;s Twitter feed and uses ReportLab&#8217;s Open Source PDF  generation toolkit to generate the PDF file.</p>
<p>Given that it simply uses the Twitter public API to retrieve the Twitter  feed, private users won&#8217;t be able to use this to turn their tweets into a  PDF file.  But if your Twitter account isn&#8217;t private, rejoice and click  here to <a href="http://tweets2pdf.appspot.com/" target="_blank">turn your Twitter feed into a PDF</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2010/12/turn-tweets-into-a-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlayBook Dev &#8211; Blitting with Copy Pixels Does Not Draw When App is in Background</title>
		<link>http://www.planetb.ca/2010/11/playbook-dev-blitting-with-copy-pixels-does-not-draw-when-app-is-in-background/</link>
		<comments>http://www.planetb.ca/2010/11/playbook-dev-blitting-with-copy-pixels-does-not-draw-when-app-is-in-background/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 00:53:55 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PlayBook]]></category>
		<category><![CDATA[blitting]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[playbook]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tablet]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=416</guid>
		<description><![CDATA[Thought I&#8217;d share this. I&#8217;m using the CopyPixels ActionScript method to blit images to the screen for animation. In this sample, notice how the CopyPixels method doesn&#8217;t update the sprite when the app is pushed into the background. This is unlike some of the device demos where we see movie footage continuing to run when [...]]]></description>
			<content:encoded><![CDATA[<p>Thought I&#8217;d share this.  I&#8217;m using the CopyPixels ActionScript method to  blit images to the screen for animation.  In this sample, notice how  the CopyPixels method doesn&#8217;t update the sprite when the app is pushed  into the background.  This is unlike some of the device demos where we  see movie footage continuing to run when the movie player is pushed into  the background.  Perhaps the video or media API uses some other method to modify image pixels, or maybe the beta version of the PlayBook simulator doesn&#8217;t have that snazzy ability like we&#8217;ve seen in the videos of others (Jim B) playing with the PlayBook.</p>
<p><iframe src="http://player.vimeo.com/video/17059906?title=0&amp;byline=0&amp;portrait=0" width="588" height="353" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2010/11/playbook-dev-blitting-with-copy-pixels-does-not-draw-when-app-is-in-background/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>10 Tips for Developing for the BlackBerry PlayBook</title>
		<link>http://www.planetb.ca/2010/11/9-tips-for-developing-for-the-blackberry-playbook/</link>
		<comments>http://www.planetb.ca/2010/11/9-tips-for-developing-for-the-blackberry-playbook/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 03:52:07 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PlayBook]]></category>
		<category><![CDATA[playbook]]></category>
		<category><![CDATA[PlayBook development]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=402</guid>
		<description><![CDATA[So it&#8217;s been a couple of weeks now since RIM unleashed the PlayBook development SDK and simulator.  I thought I&#8217;d share some of the things that I&#8217;ve experienced &#8211; issues, tips, etc in a quick blog post. Flex Builder 4.0 isn&#8217;t going to cut it.  You need to download the 4.1 update in order to [...]]]></description>
			<content:encoded><![CDATA[<p>So it&#8217;s been a couple of weeks now since RIM unleashed the PlayBook development SDK and simulator.  I thought I&#8217;d share some of the things that I&#8217;ve experienced &#8211; issues, tips, etc in a quick blog post.</p>
<ol>
<li>Flex Builder 4.0 isn&#8217;t going to cut it.  You need to download the 4.1 update in order to avoid a very vague error when trying to deploy to the PlayBook simulator.</li>
<li>FlexBuilder is absolutely not required to build a PlayBook application.  I haven&#8217;t been using it.  Instead, I&#8217;ve turned to trusty Notepad++ on Windows.  If you plan on doing the same, make sure to remove the .as extension from the langs.xml file for the haskell language type.  Actionscript is already defined as a language with the .as extension, but by default, Notepad++ sets the language type to haskell when the .as extension is used.</li>
<li>You need the 32bit java runtime installed.  If using Windows 7 or Vista, you might have the 64bit version installed.  You can have both on your machine at the same time.  I downloaded the 32 bit JDK and unzipped it into c:\Java.  I then created a shortcut to the command line that also sets the JAVA_HOME path and adds the Playbook SDK bin folder to my PATH environment variable.</li>
<li>If you&#8217;re using the command line tools to build and deploy, you will find that packaging a number of large assets into a bar file will cause an error when deploying the bar file to the PlayBook when using the blackberry-airpackager batch file for install and launch.   Instead, break the packaging and deployment into two separate steps.  Step 1, package with blackberry-airpackager.  Step 2: Use blackberry-deploy to deploy the app to the PlayBook simulator.</li>
<li>If you&#8217;re building and deploying with the command line tools, use Ant.  It will make your life a billion times easier by allowing you to bundle your command line arguments into build targets using the exec command.  For example:<br />
<code><br />
&lt;target name="build-debug"&gt;<br />
&lt;exec executable="amxmlc.bat"&gt;<br />
&lt;arg value="-compiler.debug"/&gt;<br />
&lt;arg value="HelloWorld.as"/&gt;<br />
&lt;/exec&gt;<br />
&lt;/target&gt;</code></li>
<li>MXML isn&#8217;t optimized for the PlayBook yet.  Write it all out in action script.  ActionScript is a great language anyway  (best implementation of ECMAScript in my opinion) and the more you have to write in it, the better programmer you become.</li>
<li>Many of the PlayBook functions don&#8217;t have anything written for them in the QNX API yet.  So don&#8217;t search too hard online for geolocation methods.  I suspect that these hooks will be available in an upcoming SDK package.  By the way &#8211; RIM is hoping to release an updated SDK at least once per month (according to the first developer webinar).</li>
<li>I wasn&#8217;t able to get the debugger working with an app if it was deployed with the blackberry-deploy tool.  This is unfortunate, given point 4 above.  However, adl seems to work fine so in theory, you probably don&#8217;t even need to test in the PlayBook simulator for the majority of the time.  Just use adl and run as if it were a regular Air app.</li>
<li>Blitting BitmapData objects with CopyPixels is wicked fast for Bitmap based animation.</li>
<li>There is no way currently to change the opening BlackBerry splash for an app.  Ask RIM to change this via the developer forum or via email to pressure them to make this change.</li>
</ol>
<div></div>
<div style="width: 100%; text-align: center;"><a href="http://www.tabletbucks.com/hop/how-to-create-iphone-apps.html"><img src="http://www.planetb.ca/wp-content/uploads/2010/11/makemoneymakingapps.jpg" alt="" /></a></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<p>So it&#8217;s been a couple of weeks now since RIM unleashed the PlayBook development SDK and simulator.  I thought I&#8217;d</p>
<p>share some of the things that I&#8217;ve experienced &#8211; issues, tips, etc in a quick blog post.</p>
<p>1) Flex Builder 4.0 isn&#8217;t going to cut it.  You need to download the 4.1 update in order to avoid a very vague</p>
<p>error when trying to deploy to the PlayBook simulator.</p>
<p>2) FlexBuilder is absolutely not required to build a PlayBook application.  I haven&#8217;t been using it.  Instead,</p>
<p>I&#8217;ve turned to trusty Notepad++ on Windows.  If you plan on doing the same, make sure to remove the .as extension</p>
<p>from the langs.xml file for the haskell language type.  Actionscript is already defined as a language with the</p>
<p>.as extension, but by default, Notepad++ sets the language type to haskell when the .as extension is used.</p>
<p>3) You need the 32bit java runtime installed.  If using Windows 7 or Vista, you might have the 64bit version</p>
<p>installed.  You can have both on your machine at the same time.  I downloaded the 32 bit JDK and unzipped it into</p>
<p>c:\Java.  I then created a shortcut to the command line that also sets the JAVA_HOME path and adds the Playbook</p>
<p>SDK bin folder to my PATH environment variable.</p>
<p>4) If you&#8217;re using the command line tools to build and deploy, you will find that packaging a number of large</p>
<p>assets into a bar file will cause an error when deploying the bar file to the PlayBook when using the</p>
<p>blackberry-airpackager batch file for install and launch.   Instead, break the packaging and deployment into two</p>
<p>separate steps.  Step 1, package with blackberry-airpackager.  Step 2: Use blackberry-deploy to deploy the app to</p>
<p>the PlayBook simulator.</p>
<p>5) If you&#8217;re building and deploying with the command line tools, use Ant.  It will make your life a billion times</p>
<p>easier by allowing you to bundle your command line arguments into build targets using the exec command.  For</p>
<p>example:<br />
&lt;target name=&#8221;build-debug&#8221;&gt;<br />
&lt;exec executable=&#8221;amxmlc.bat&#8221;&gt;<br />
&lt;arg value=&#8221;-compiler.debug&#8221;/&gt;<br />
&lt;arg value=&#8221;HelloWorld.as&#8221;/&gt;<br />
&lt;/exec&gt;<br />
&lt;/target&gt;</p>
<p>5) MXML isn&#8217;t optimized for the PlayBook yet.  Write it all out in action script.  ActionScript is a great</p>
<p>language anyway  (best implementation of ECMAScript in my opinion) and the more you have to write in it, the</p>
<p>better programmer you become.</p>
<p>6) Many of the PlayBook functions don&#8217;t have anything written for them in the QNX API yet.  So don&#8217;t search too</p>
<p>hard online for geolocation methods.  I suspect that these hooks will be available in an upcoming SDK package.</p>
<p>By the way &#8211; RIM is hoping to release an updated SDK at least once per month (according to the first developer</p>
<p>webinar).</p>
<p>7) I wasn&#8217;t able to get the debugger working with an app if it was deployed with the blackberry-deploy tool.</p>
<p>This is unfortunate, given point 4 above.  However, adl seems to work fine so in theory, you probably don&#8217;t even</p>
<p>need to test in the PlayBook simulator for the majority of the time.  Just use adl and run as if it were a</p>
<p>regular Air app.</p>
<p> <img src='http://www.planetb.ca/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> Blitting BitmapData objects with CopyPixels is wicked fast for Bitmap based animation.</p>
<p>9) There is no way currently to change the opening BlackBerry splash for an app.  Ask RIM to change this via the</p>
<p>developer forum or via email to pressure them to make this change.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2010/11/9-tips-for-developing-for-the-blackberry-playbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting mp3&#8242;s and a FLASH mp3 Player on Your Website for FREE</title>
		<link>http://www.planetb.ca/2010/09/hosting-mp3s-and-a-flash-mp3-player-on-your-website-for-free/</link>
		<comments>http://www.planetb.ca/2010/09/hosting-mp3s-and-a-flash-mp3-player-on-your-website-for-free/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 00:57:05 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=351</guid>
		<description><![CDATA[For one of my new WordPress blogs, I had some sound bites to post.  I wanted a simple minimalist FLASH based mp3 player on the post and the audio files were nearly 10 minutes each.  I&#8217;m on Dreamhost with the crazy insane unlimited everything plan, but with a few people listening to the audio clips [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my new WordPress blogs, I had some sound bites to post.  I wanted a simple minimalist FLASH based mp3 player on the post and the audio files were nearly 10 minutes each.  I&#8217;m on Dreamhost with the crazy insane unlimited everything plan, but with a few people listening to the audio clips concurrently, my site response time could suffer.</p>
<p>The solution came easily and with nearly zero effort.</p>
<p><strong>Step 1:</strong> Register at <a href="http://www.dropbox.com/">Dropbox</a> for a new account.  New accounts come with a couple of gigs of storage space.  If this new account is simply for hosting large files for  your website, then don&#8217;t bother installing the Dropbox software.  Instead, click on the <strong>login</strong> button without entering any credentials. You will be brought to another login page that also has a &#8220;Create an Account&#8221; tab.  Use that to create a new account.</p>
<p><strong>Step 2</strong>: Login to your new account through the website.  Navigate to your public folder and upload the audio clips there.  Your public folder is automatically shared and publicly visible.</p>
<p><strong>Step 3</strong>: Install the <a href="http://wpaudioplayer.com/">WordPress Audio Player</a> plugin.  This thing has a swanky minimalist design.  Login to your WordPress account and navigate to the Plugins menu on the left and click &#8220;Add New&#8221;.  In the search box, type in &#8220;Audio Player&#8221; and click search.  I&#8217;m fairly confident that the first or second plugin will be the one we&#8217;re after. It&#8217;s the one by <a href="http://www.1pixelout.net/">Martin Laine</a>.  Select the plugin and click the Install Now button. Activate the plugin after installed.  Even if the plugin installation warns that it doesn&#8217;t support WP 3 (and you&#8217;re using version 3, right??) it does. The WordPress plugin installation process is awesome. WordPress is awesome.</p>
<p><strong>Step 4</strong>: Back in Dropbox, click the arrow to the right of the mp3 you&#8217;d like to use in your post.  A menu will show with a link to &#8220;Copy public URL&#8221;.  Click that and copy the public URL (CTRL-C or click the copy to clipboard button).</p>
<p><strong>Step 5</strong>: In a WordPress post, use the following, where &lt;url&gt; is the copied url of the file and &lt;sound file title&gt; is the name or title that you would like to use for the audio clip.</p>
<pre style="padding-left: 30px; font-size: 12pt;">[audio:&lt;url&gt;|titles=&lt;audio clip title&gt;]</pre>
<p>And that&#8217;s it!</p>
<p>You can further customize the FLASH mp3 player via WordPress under the plugins menu, but personally I like the basic slick version that&#8217;s available by default.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2010/09/hosting-mp3s-and-a-flash-mp3-player-on-your-website-for-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter oAuth in .Net without Web Login</title>
		<link>http://www.planetb.ca/2010/07/twitter-oauth-in-net-without-web-login/</link>
		<comments>http://www.planetb.ca/2010/07/twitter-oauth-in-net-without-web-login/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 02:07:57 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[oAuth]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=278</guid>
		<description><![CDATA[I was interested in getting a Twitter App together to orchestrate some follows and unfollows and user searches for a personal project. In the past, I&#8217;ve used Twitter&#8217;s Basic Authentication API to get my Twitter feed, but according to the Twitter API documentation, Basic Auth is going to be unsupported in August of this year. [...]]]></description>
			<content:encoded><![CDATA[<p>I was interested in getting a <strong>Twitter App</strong> together to orchestrate some follows and unfollows and user searches for a personal project.  In the past, I&#8217;ve used <strong>Twitter&#8217;s Basic Authentication</strong> API to get my Twitter feed, but according to the Twitter API documentation, Basic Auth is going to be unsupported in August of this year.  So I figured I might as well get my feet wet with <strong>Twitter oAuth</strong> authentication.</p>
<p>I came across <a href="http://www.voiceoftech.com/swhitley/?p=856" target="_blank">this article</a> about how to use Twitter oAuth with .Net (via Twitter API documentation) and used the extended oAuth code for my own project.</p>
<p>Unfortunately in all examples of desktop apps that I can find, they all involve opening up Twitter.com in a web browser control to get the user&#8217;s PIN for the app.  Of course, this makes sense, but I wanted to short circuit this process.  I wanted to be able to enter a userid and password and go straight into my account.</p>
<p>Here&#8217;s a quick snip of my code in case you&#8217;re interested in doing the same.  The code uses HTTPWebRequest and HTTPWebResponse to automate the PIN request procedure so a web browser control is not needed.</p>
<p>This code uses Twitter oAuth for .Net from <a href="http://www.voiceoftech.com/swhitley/?p=856">here</a>, which itself extends .Net oAuth from <a href="http://oauth.net/code/">here</a>. The code is probably not complete as I simply took the code snippets from a larger project and as such, some variables may not be declared or initialized properly.</p>
<div style="font-size:8pt;">
<pre class="brush: c#">
//Assumes these vars are populated before below code.
private string _consumerKey = &quot;&quot;;
private string _consumerSecret = &quot;&quot;;
private string _userid = &quot;&quot;;
private string _password = &quot;&quot;;

//These get populated by below code
private string _token=&quot;&quot;;
private Uri AuthUri = null;
private oAuthTwitter oAuth;
private string _pin = &quot;&quot;;

public void authenticate()
{
    oAuth = new oAuthTwitter();
    oAuth.ConsumerKey = _consumerKey;
    oAuth.ConsumerSecret = _consumerSecret;

    Uri AuthUri = new Uri(oAuth.AuthorizationLinkGet());
    _token = HttpUtility.ParseQueryString(AuthUri.Query)[&quot;oauth_token&quot;];
    CookieContainer cookies = null;
    string content = getContent(AuthUri.ToString(), null, &quot;&quot;, null, ref cookies);
    string authenticity_token = Regex.Match(content, &quot;twttr\\.form_authenticity_token = &#039;([^&#039;]+)&#039;;&quot;, RegexOptions.IgnoreCase).Groups[1].Value;

    string post = ue(&quot;authenticity_token&quot;, authenticity_token) +
                    &quot;&amp;&quot; + ue(&quot;oauth_token&quot;, _token) +
                    &quot;&amp;&quot; + ue(&quot;session[username_or_email]&quot;, _userid) +
                    &quot;&amp;&quot; + ue(&quot;session[password]&quot;, _password) + &quot;&amp;Allow=allow&quot;;

    content = getContent(oAuthTwitter.AUTHORIZE, post, &quot;https://www.twitter.com/&quot;, cookies, ref cookies);
    Match m = Regex.Match(content, &quot;oauth_pin\\\&quot;&gt;\\s*([0-9]+)&quot;, RegexOptions.IgnoreCase);
    _pin = &quot;&quot;;
    if (m != null)
    {
        _pin = m.Groups[1].Value;
    }

    oAuth.Token = _token;
    oAuth.AccessTokenGet(_token, _pin);
    if (oAuth.TokenSecret.Length &gt; 0)
    {
        string xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, &quot;http://twitter.com/account/verify_credentials.xml&quot;, String.Empty);
    }
}
private string ue(string parm, string val)
{
    return HttpUtility.UrlEncode(parm) + &quot;=&quot; + HttpUtility.UrlEncode(val);
}

public static string getContent(string url, string requestBody, string referrer, CookieContainer cookies, ref CookieContainer retCookies)
{
    ServicePointManager.CertificatePolicy = new trustedCertificatePolicy();
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
    request.Method = (requestBody == null) ? &quot;GET&quot; : &quot;POST&quot;;
    request.UserAgent = &quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)&quot;;
    request.Accept = &quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;;
    request.Referer = referrer;
    request.CookieContainer = cookies;

    if (requestBody != null)
    {
        request.ContentType = &quot;application/x-www-form-urlencoded&quot;;
        request.ContentLength = System.Text.Encoding.UTF8.GetByteCount(requestBody);
        Stream requestStream = request.GetRequestStream();
        StreamWriter writer = new StreamWriter(requestStream);
        writer.Write(requestBody);
        writer.Flush();
    }
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);
    string content = reader.ReadToEnd();

    CookieContainer rc = new CookieContainer();

    UriBuilder ubuilder = new UriBuilder();
    Uri u = new Uri(&quot;https://www.twitter.com&quot;);

    rc.SetCookies(u, response.Headers[&quot;Set-Cookie&quot;]);
    rc.Add(response.Cookies);
    retCookies = rc;

    return content;
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2010/07/twitter-oauth-in-net-without-web-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fight Spam with Free Ready Made CAPTCHA Service</title>
		<link>http://www.planetb.ca/2008/11/fight-spam-with-free-ready-made-captcha-service/</link>
		<comments>http://www.planetb.ca/2008/11/fight-spam-with-free-ready-made-captcha-service/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 01:28:44 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[free CAPTCHA]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=83</guid>
		<description><![CDATA[CAPTCHA&#8217;s. Love &#8216;em or hate &#8216;em, they&#8217;re sometimes a good idea to implement. reCAPTCHA is a free service that allows web developers to implement a CAPTCHA on their form with virtually no effort. And did I mention it is a free service? Well, that&#8217;s not entirely true. In exchange, reCAPTCHA is putting the user challenge [...]]]></description>
			<content:encoded><![CDATA[<p>CAPTCHA&#8217;s.  Love &#8216;em or hate &#8216;em, they&#8217;re sometimes a good idea to implement.  reCAPTCHA is a free service that allows web developers to implement a CAPTCHA on their form with virtually no effort.  And did I mention it is a free service?  Well, that&#8217;s not entirely true.  </p>
<p>In exchange, reCAPTCHA is putting the user challenge responses to good use.  The service uses scanned in text for the CAPTCHA.  The idea is that all the time spent &#8220;solving&#8221; CAPTCHA&#8217;s online can be channeled into assisting optical character recognition programs in decoding the hard to decode scanned in words.  Neat, eh?</p>
<p>I put together the following reCAPTCHA in literally 3 minutes.  For more information and to put your own reCAPTCHA into action, check out the site here: <a href="http://recaptcha.net/">http://recaptcha.net/</a></p>
<p><center><iframe frameborder="0" width="350" height="170" scrolling="no" allowtransparency="true" src="http://www.planetb.ca/projects/reCAPTCHA/test.php"></iframe></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2008/11/fight-spam-with-free-ready-made-captcha-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capturing Keyboard Events in Adobe Flex 3</title>
		<link>http://www.planetb.ca/2008/11/capturing-keyboard-events-in-adobe-flex-3/</link>
		<comments>http://www.planetb.ca/2008/11/capturing-keyboard-events-in-adobe-flex-3/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 03:10:54 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[KeyboardEvent]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=80</guid>
		<description><![CDATA[For anyone else spending an unfortunate length of time unsuccessfully attempting to capture keyboard events in a Flex 3 application (for browser or AIR), here&#8217;s where you&#8217;re probably going wrong. You are likely registering the keyboard listener too early. It&#8217;s likely that you are calling an init() method where you register the keyboard event on [...]]]></description>
			<content:encoded><![CDATA[<p>For anyone else spending an unfortunate length of time unsuccessfully attempting to capture keyboard events in a Flex 3 application (for browser or AIR), here&#8217;s where you&#8217;re probably going wrong.</p>
<p>You are likely registering the keyboard listener too early.  It&#8217;s likely that you are calling an init() method where you register the keyboard event on creationComplete.  Instead, call the init function later on.  Try registering the event in the applicationComplete event handler.</p>
<p>More info here:<br />
<a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;productId=2&#038;postId=304">http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;productId=2&#038;postId=304</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2008/11/capturing-keyboard-events-in-adobe-flex-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ajax Made Easy &#8211; the Power of jQuery</title>
		<link>http://www.planetb.ca/2008/11/ajax-made-easy-the-power-of-jquery/</link>
		<comments>http://www.planetb.ca/2008/11/ajax-made-easy-the-power-of-jquery/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 03:56:01 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[E4X]]></category>
		<category><![CDATA[ECMAScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlhttprequest]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=71</guid>
		<description><![CDATA[Ajax &#8211; Asynchronous Javascript and XML. It&#8217;s more a technique than anything else. While senior management may consider Ajax to be fancy animations and &#8220;rich&#8221; internet applications, fundamentally, the term Ajax simply refers to exploiting a browser&#8217;s ability to background load XML from other URL&#8217;s. Loading XML Asynchronously In the past, I&#8217;ve implemented Ajaxiness by [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:15pt;font-weight:bold;">Ajax</span> &#8211; <strong>A</strong>synchronous <strong>Ja</strong>vascript and <strong>X</strong>ML.  It&#8217;s more a technique than anything else.  While senior management may consider Ajax to be fancy animations and &#8220;rich&#8221; internet applications, fundamentally, the term Ajax simply refers to exploiting a browser&#8217;s ability to background load XML from other URL&#8217;s.</p>
<h2>Loading XML Asynchronously</h2>
<p>In the past, I&#8217;ve implemented Ajaxiness by creating XMLHttpRequest objects (or Microsoft.XMLHTTP objects fo IE):</p>
<pre class="brush: javascript">
var request = (document.all)?new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;):new XMLHttpRequest();
request.onreadystatechange = function(){
	if(request.readyState == 4)
		alert(&quot;Document loaded&quot;);
};
request.open(&quot;GET&quot;, &quot;test.xml&quot;, true);
request.send(&quot;&quot;);
</pre>
<p>The above code just loads an xml file, test.xml, and alerts the user when the load is finished.  It&#8217;s as simple an Ajax example as it gets.  Fully cross-browser compliant (as much as necessary anyway). From there, you could use your browser&#8217;s ridiculous XML parsing capabilities which isn&#8217;t the same between browsers and with much trial and error and a whack of frustration, implement some client-server Ajax and maybe pull data into a grid or something.  </p>
<p>As I&#8217;ve said, I&#8217;ve done it this way.  But it&#8217;s insane.  In this day and age of the wheel already having been invented over and over, the time needed to implement the core cross-browser Ajax functions should be zero.  In fact, the addition of a particular library to your script can not only make cross browser Ajax and DOM\XML processing worry free, it can make your scripting days a hell of a lot easier in general.</p>
<p>That incredible library is&#8230; <span style="font-size:20pt;font-weight:bold;">jQuery</span>.</p>
<p>With jQuery, the above code becomes a one liner (sorta anyway):</p>
<pre class="brush: javascript">
$.ajax({
  url: &quot;test.xml&quot;,
  success: function(retxml){
    alert(&quot;Document loaded&quot;);
  }
});
</pre>
<h2>ECMAScript for XML (E4X)</h2>
<p>ECMAScript is javascript.  They&#8217;re one and the same.  In 2004, a standardized extended version of ECMAScript was published that elegantly treated xml as a primitive data type.  Doing so makes traversing an XML or DOM document a breeze.  Firefox and Safari both support this standard.  So does Adobe Flash\Flex actionscript.  Unfortunately (and unsurprisingly) IE doesn&#8217;t and from what I&#8217;ve read, MS doesn&#8217;t intend to change that.   This being the case, combined with the utterly depressing fact that IE is so incredibly popular, means that using E4X in any script is likely a poor choice for the time being (unless, of course, you choose not to support IE &#8211; good luck with that).</p>
<h2>jQuery &#8211; the E4X Alternative</h2>
<p>So for now, until either Dell&#8217;s stop being shipped with IE as the default browser or Microsoft decides to incorporate more of the browser standards, we&#8217;re squeezed out from using xml as a primitive data type.  While this no doubt sucks, <b>jQuery</b> again comes to the rescue.</p>
<p>Suppose the following XML file named test.xml :</p>
<pre class="brush: xml">
&lt;Provinces&gt;
	&lt;Province name=&quot;Ontario&quot;&gt;
		&lt;Cities&gt;
			&lt;City&gt;Kitchener&lt;/City&gt;
			&lt;City&gt;Guelph&lt;/City&gt;
			&lt;City&gt;Toronto&lt;/City&gt;
		&lt;/Cities&gt;
	&lt;/Province&gt;
&lt;/Provinces&gt;
</pre>
<p>We can easily load the file and traverse all City elements as follows:</p>
<pre class="brush: javascript">
$.ajax({
  url: &quot;test.xml&quot;,
  success: function(retxml){
    $(retxml).find(&quot;City&quot;).each(function(){
    	alert(&quot;City: &quot; + $(this).text());
    })
  }
});
</pre>
<p>Easy peasy&#8230;</p>
<p>jQuery not only enables easy Ajax, it also has many other cool features like fading and sliding elements and animation support that would certainly feed management&#8217;s buzz word frenzy.</p>
<p>For more information about jQuery, check out the homepage, <a href="http://jquery.com/">http://jquery.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2008/11/ajax-made-easy-the-power-of-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Schema Recipes</title>
		<link>http://www.planetb.ca/2008/11/xml-schema-recipes/</link>
		<comments>http://www.planetb.ca/2008/11/xml-schema-recipes/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 03:40:34 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.planetb.ca/?p=32</guid>
		<description><![CDATA[Don&#8217;t underestimate the power of validating XML with a schema. I&#8217;ve often overlooked much of what an XML schema is capable of, generally doing the minimum needed to create one. But investing a little more love with a schema can save time and headache (especially when working in situations involving multiple systems and interfaces). Creating [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t underestimate the power of validating XML with a schema. I&#8217;ve often overlooked much of what an XML schema is capable of, generally doing the minimum needed to create one. But investing a little more love with a schema can save time and headache (especially when working in situations involving multiple systems and interfaces).</p>
<p>Creating custom types with regular expressions is an extremely powerful tool:</p>
<p>The GUID type:</p>
<pre class="brush: xml">
	&lt;xsd:simpleType name=&quot;GUIDType&quot;&gt;
		&lt;xsd:restriction base=&quot;xsd:string&quot;&gt;
			&lt;xsd:pattern value=&quot;\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}&quot;/&gt;
		&lt;/xsd:restriction&gt;
	&lt;/xsd:simpleType&gt;
</pre>
<p>Phone Number:</p>
<pre class="brush: xml">
	&lt;xsd:simpleType name=&quot;PhoneNumberType&quot;&gt;
		&lt;xsd:restriction base=&quot;xsd:string&quot;&gt;
			&lt;xsd:pattern value=&quot;[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]&quot;/&gt;
		&lt;/xsd:restriction&gt;
	&lt;/xsd:simpleType&gt;
</pre>
<p>Postal Code:</p>
<pre class="brush: xml">
	&lt;xsd:simpleType name=&quot;PostalCodeType&quot;&gt;
		&lt;xsd:restriction base=&quot;xsd:string&quot;&gt;
			&lt;xsd:pattern value=&quot;[A-CEGHJ-NPR-TVXY]\d[A-Z] \d[A-Z]\d&quot;/&gt;
		&lt;/xsd:restriction&gt;
	&lt;/xsd:simpleType&gt;
</pre>
<p>SIN:</p>
<pre class="brush: xml">
	&lt;xsd:simpleType name=&quot;SINType&quot;&gt;
		&lt;xsd:restriction base=&quot;xsd:string&quot;&gt;
			&lt;xsd:pattern value=&quot;\d{3} \d{3} \d{3}&quot;/&gt;
		&lt;/xsd:restriction&gt;
	&lt;/xsd:simpleType&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.planetb.ca/2008/11/xml-schema-recipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

