<?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>Dodgeball Cannon &#187; Code</title>
	<atom:link href="http://www.johntantalo.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johntantalo.com/blog</link>
	<description>It's not so much a time machine as it is my blog.</description>
	<lastBuildDate>Thu, 05 Aug 2010 17:40:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Short and sweet OAuth</title>
		<link>http://www.johntantalo.com/blog/short-and-sweet-oauth/</link>
		<comments>http://www.johntantalo.com/blog/short-and-sweet-oauth/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 05:28:37 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=94</guid>
		<description><![CDATA[I recently grew quite frustrated when I had to update Emend&#8217;s Twitter bot to use OAuth.
There are, of course, readily available implementations of OAuth in python, even some specifically engineered for App Engine with lovely persistence and caching and KILL ME NOW.
I gave up after a couple hours of staring at this nonsense. I grew [...]]]></description>
			<content:encoded><![CDATA[<p>I recently grew quite frustrated when I had to update <a href="http://emendapp.com">Emend&#8217;s</a> Twitter bot to use <a href="http://oauth.net/">OAuth</a>.</p>
<p>There are, of course, <a href="http://oauth.googlecode.com/svn/code/python/oauth/oauth.py">readily available implementations of OAuth</a> in python, even some <a href="http://github.com/mikeknapp/AppEngine-OAuth-Library/raw/master/oauth.py">specifically engineered for App Engine</a> with lovely persistence and caching and KILL ME NOW.</p>
<p>I gave up after a couple hours of staring at this nonsense. I grew so displeased because my app doesn&#8217;t need 95% of what these libraries offer. I only need to <a href="http://oauth.net/core/1.0/#signing_process">sign requests</a> with a fixed <em>oauth_consumer_key</em>, <em>oauth_consumer_secret</em>, <em>oauth_token</em>, and <em>oauth_token_secret</em>. However, this simple task would require me to subclass or instantiate several object with Culver&#8217;s library, and I can&#8217;t even begin to fathom what I&#8217;d need to do with Knapp&#8217;s offering.</p>
<p>(Aside: if you want to authorize and build access tokens for your app, I highly recommend <a href="http://term.ie/oauth/example/client.php">this excellent OAuth test client</a>)</p>
<p>I finally teased apart the core function of signing requests, thanks in large part to the <a href="http://oauth.net/core/1.0/#anchor30">great reference example</a>. If all you need is to access a protected resource, this will get the job done with a single function call, no object-orientation required.</p>
<p><script src="http://gist.github.com/284452.js?file=oauth.py"></script></p>
<p><a href="http://gist.github.com/284452">Source code and unit test of short and sweet OAuth.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/short-and-sweet-oauth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip tags with html5lib</title>
		<link>http://www.johntantalo.com/blog/strip-tags-with-html5lib/</link>
		<comments>http://www.johntantalo.com/blog/strip-tags-with-html5lib/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 04:14:37 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[html5lib]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=82</guid>
		<description><![CDATA[There are a couple posts out there that discuss stripping tags with html5lib, but they seem intent on preserving the &#8220;acceptable elements&#8221; such as &#60;span&#62; and &#60;code&#62;.
This is fine unless you really want to friggin&#8217; strip out the tags, like I needed for Emend. The following is my solution.

Source code for stripping tags with html5lib [...]]]></description>
			<content:encoded><![CDATA[<p>There are a couple posts <a href="http://code.google.com/p/html5lib/issues/detail?id=62">out</a> <a href="http://deathofagremmie.com/2009/04/12/using-html5lib-to-sanitize-user-input/">there</a> that discuss stripping tags with <a href="http://code.google.com/p/html5lib/"><em>html5lib</em></a>, but they seem intent on preserving the &#8220;acceptable elements&#8221; such as <code>&lt;span&gt;</code> and <code>&lt;code&gt;</code>.</p>
<p>This is fine unless you really want to <em>friggin&#8217; strip out the tags</em>, like I needed for <a href="http://emendapp.com">Emend</a>. The following is my solution.</p>
<p><script src="http://gist.github.com/256684.js?file=strip_tags.py"></script></p>
<p><a href="http://gist.github.com/256684">Source code for stripping tags with html5lib and unit test.</a></p>
<p>For example,</p>
<pre><code>&gt;&gt;&gt; from strip_tags import strip_tags
&gt;&gt;&gt; strip_tags('&lt;p&gt;foo&lt;/p&gt; &lt;script&gt;bar&lt;/script&gt;')
u'foo bar'</code></pre>
<p>Thanks go to <a href="http://edward.oconnor.cx/">Edward O’Connor</a> for pointing me towards <em>html5lib</em> in the first place. It&#8217;s a huge improvement over <a href="http://docs.python.org/library/htmlparser.html"><em>HTMLParser</em></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/strip-tags-with-html5lib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPA TTS bookmarklet</title>
		<link>http://www.johntantalo.com/blog/ipa-tts-bookmarklet/</link>
		<comments>http://www.johntantalo.com/blog/ipa-tts-bookmarklet/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 17:33:49 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[ipa]]></category>
		<category><![CDATA[tts]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=70</guid>
		<description><![CDATA[I present the IPA (International Phonetic Alphabet) TTS (text-to-speech) bookmarklet. (Source)
Bookmarklet: IPA TTS (drag to your bookmark bar)
How to use: select any text that contains IPA and click on the bookmarklet. Wait a second for the iframe at the bottom of the page to load.
Try these examples: /ˌɪntəˈnæʃnəl/, /ˌɪntɚˈnæʃnəl/
]]></description>
			<content:encoded><![CDATA[<p>I present the IPA (<a href="http://en.wikipedia.org/wiki/International_Phonetic_Alphabet">International Phonetic Alphabet</a>) TTS (<a href="http://en.wikipedia.org/wiki/Text-to-speech">text-to-speech</a>) <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a>. (<a href="http://gist.github.com/202523">Source</a>)</p>
<p>Bookmarklet: <a href="javascript:(function%20()%20{var%20selection%20=%20window.getSelection%20?%20window.getSelection()%20:document.getSelection%20?%20document.getSelection()%20:document.selection%20?%20document.selection.createRange().text%20:%20%27%27;if%20(selection)%20{selection%20=%20String(selection);}if%20(selection)%20{var%20match%20=%20selection.match(%27\/(.*)\/%27);var%20ipa;if%20(match%20&amp;&amp;%20match[1])%20{ipa%20=%20match[1];}if%20(!ipa)%20{ipa%20=%20prompt(%22Couldn%27t%20find%20any%20IPA.%20Type%20it%20in%20instead?%22);}if%20(ipa)%20{ipa%20=%20ipa.replace(/./g,%20function%20(c)%20{if%20(/%u0(...)/.test(escape(c)))%20{return%20escape(c).replace(/%u0(...)/g,%20%27&amp;#x$1;%27);}%20else%20{return%20c;}});var%20request%20=%20{txt:%20%27&lt;phoneme%20alphabet=%22ipa%22%20ph=%22%27+ipa+%27%22&gt;%20&lt;/phoneme&gt;%27,voice:%20%27crystal%27};var%20iframe%20=%20document.createElement(%27iframe%27);iframe.name%20=%20iframe.id%20=%20%22iframe%22+new%20Date().getTime();document.body.appendChild(iframe);var%20form%20=%20document.createElement(%27form%27);form.target%20=%20iframe.name;form.method%20=%20%27post%27;form.action%20=%20%27http://192.20.225.55/tts/cgi-bin/nph-talk%27;form.acceptCharset%20=%20%22iso-8859-1%22;form.style.display%20=%20%27none%27;for%20(var%20name%20in%20request)%20{var%20input%20=%20document.createElement(%27input%27);input.name%20=%20name;input.value%20=%20request[name];form.appendChild(input);}document.body.appendChild(form);form.submit();}}%20else%20{alert(%22Select%20some%20IPA.%22);}})()">IPA TTS</a> (drag to your bookmark bar)</p>
<p>How to use: select any text that contains IPA and click on the bookmarklet. Wait a second for the iframe at the bottom of the page to load.</p>
<p>Try these examples: /ˌɪntəˈnæʃnəl/, /ˌɪntɚˈnæʃnəl/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/ipa-tts-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>IE6 submit-click on text input submit</title>
		<link>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/</link>
		<comments>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 23:15:44 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=32</guid>
		<description><![CDATA[Found this fun bug in IE6 today. If you have a text input and submit input unassociated with a form, then submitting the text input (by hitting return or enter when focused) will cause a click event on the submit input.
The solution is simple and intuitive: eliminate unassociated submit inputs and submit buttons.

&#60;!DOCTYPE html PUBLIC [...]]]></description>
			<content:encoded><![CDATA[<p>Found this fun bug in IE6 today. If you have a text input and submit input unassociated with a form, then submitting the text input (by hitting return or enter when focused) will cause a click event on the submit input.</p>
<p>The solution is simple and intuitive: eliminate unassociated submit inputs and submit buttons.</p>
<p><code>
<pre>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
&quot;http://www.w3.org/TR/html4/DTD/strict.dtd&quot;&gt;
&lt;input type=&quot;text&quot;/&gt;
&lt;input type=&quot;submit&quot; onclick=&quot;this.value='clicked';&quot; /&gt;</pre>
<p></code></p>
<p><a href="http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20HTML%204.01%2F%2FEN%22%0D%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fhtml4%2FDTD%2Fstrict.dtd%22%3E%0D%0A%3Cinput%20type%3D%22text%22%2F%3E%0D%0A%3Cinput%20type%3D%22submit%22%20onclick%3D%22this.value%3D'clicked'%3B%22%20%2F%3E">Demo (IE only)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dangers of anonymous function closures</title>
		<link>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/</link>
		<comments>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 19:43:57 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=17</guid>
		<description><![CDATA[pre {font-size: 1.5em}
John Resig&#8217;s jQuery uses a standard technique of anonymous function closures to namespace its internal functionality.
(function(){
  // jQuery stuff goes here...
})();

This is all well and good until you want to inline this code under some of your application code, as I did while working on Eventful&#8217;s MySpace application. Consider this example, written [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">pre {font-size: 1.5em}</style>
<p>John Resig&#8217;s <a target="_blank" href="http://jquery.com/">jQuery</a> uses a standard technique of anonymous function closures to namespace its internal functionality.</p>
<blockquote><pre><code>(function(){
  // jQuery stuff goes here...
})();</code></pre>
</blockquote>
<p>This is all well and good until you want to inline this code under some of your application code, as I did while working on <a target="_blank" href="http://www.myspace.com/topperformers">Eventful&#8217;s MySpace application</a>. Consider this example, written in standard Javascript style.</p>
<blockquote><pre><code>var foo = function(bar) {
  console.log("foo");
  return bar;
}

(function(){
  console.log("bar")
})();</code></pre>
</blockquote>
<p>What do you expect this code to print? If you say &#8220;bar&#8221;, you&#8217;re wrong. It prints &#8220;foo bar&#8221; because in this context the anonymous function closure becomes a call to the function that prints &#8220;foo&#8221; and returns the function that prints &#8220;bar&#8221;, which is then called.</p>
<p>Most of us probably wouldn&#8217;t notice what just happened because we are so used to Javascript interpreters automatically inserting semicolons after function definitions.</p>
<p>The danger is assuming, as John Resig and hundreds others have, that your anonymous function closure is the first token in a new line. In my case, it wasn&#8217;t. The solution? Either start meticulously sprinkling semicolons in your application code, or just add a single semicolon before your parenthetical block, guaranteeing it&#8217;s the first token in the line.</p>
<blockquote><pre><code>;(function(){
  // jQuery stuff goes here...
})();
</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
