<?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>Paul Butler.org</title>
	<atom:link href="http://paulbutler.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulbutler.org</link>
	<description></description>
	<lastBuildDate>Thu, 12 Nov 2009 16:47:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Do we really need another programming language?</title>
		<link>http://paulbutler.org/archives/do-we-really-need-another-programming-language/</link>
		<comments>http://paulbutler.org/archives/do-we-really-need-another-programming-language/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 03:39:24 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://paulbutler.org/?p=239</guid>
		<description><![CDATA[Yesterday, a group inside Google released a new programming language called go. Among the many comments on the new language, I noticed a number of people rhetorically asking if there is really room for more programming languages. I&#8217;ve seen the same sentiment expressed before, seemingly whenever someone releases a pet language (Arc, Factor) or rediscovers [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, a group inside Google released a new programming language called <a href="http://golang.org">go</a>. Among the many comments on the new language, I noticed a number of people rhetorically asking if there is really room for more programming languages. I&#8217;ve seen the same sentiment expressed before, seemingly whenever someone releases a pet language (Arc, Factor) or rediscovers an older programming language (Smalltalk, Erlang, LISP).</p>
<p>I&#8217;m convinced that there is, in fact, room for more programming languages.</p>
<p>I recently read The Mythical Man Month, the 1975 classic about software engineering. Two things stuck out at me. First, that compared to programmers in 1975, programmers today are spoiled by hardware. Many software constraints, like memory and CPU speed &mdash; let alone the size of the program on disk &mdash; are not issues worth much thought for many software projects. There are of course exceptions: low-level systems code, graphics, data-intensive calculations (in other words, &#8220;the fun stuff&#8221;) &mdash; but in general, application programmers face far fewer constraints than they did 35 years ago. The second thing that struck me is how comparatively little programming has changed since then. Despite the loosening of constraints, we still write applications that, say, directly use pointer arithmetic and manually allocate and deallocate memory.</p>
<p>It&#8217;s not just C++, either. Here&#8217;s an experiment. Consider the last program you wrote in any language. Imagine you had to describe, in plain English, your program. The description must be complete enough that another programmer could read it and produce your program. Not your program exactly, of course, but one that satisfies the same requirements your program does. (If you actually try this, you may get something that looks like it was written by a lawyer who charges by the comma. That&#8217;s fine.)</p>
<p>Now compare your description to the program&#8217;s source code. The source code is almost certainly several times longer, less intuitive, and less descriptive. And yet, if your description is precise enough, all the source code does is communicate the same idea to the compiler.</p>
<p>There are two main things that differentiate the source from your description. One is that the source is designed so that a computer can parse it. This amounts to having some regular structure and a well-defined meaning to all the symbols. The other difference is that the description defines <strong>what</strong> the program should do, and the source describes <strong>how</strong>. These differences both contribute to the verbosity of the source code, but I suspect the latter contributes more (consider how concise formal math notation can be, despite having structure and being well-defined).</p>
<p>The obvious way to make a language more expressive, then, is to make it more declarative &mdash; to describe <em>what</em> the program does, not <em>how</em> it does it. Ideally our programs could be completely declarative. We could translate the description we wrote for the experiments a few paragraphs back into a more formal language, without adding any implementation details. Then we would have a compiler that created a program which satisfied our description and produced an executable. This type of programming is actually possible in certain, constrained domains (SQL and Prolog, for example), but unfortunately there isn&#8217;t a good general algorithm to translate any program we describe declaratively into machine instructions.</p>
<p>The best we can do, then, is to give imperative languages more declarative features. In fact, many high-level language features fall under this category. Take continuations, which let you say &#8220;resume code at this point&#8221; instead of how &#8220;store these pieces of state there, then restore the state and return here when called&#8221;. Or list comprehensions, which let you say &#8220;give me a list satisfying these properties&#8221;, rather than &#8220;loop through these elements and do that to them, discarding them if this is not true&#8221;. Or iteration constructs, which let you say &#8220;do this stuff for each element in that&#8221;, without specifying that space must be allocated for a counter, how to look up each element, or that the counter is incremented after each element.</p>
<p>All of those concepts have existed for decades. When available, they make code easier to write, understand, and modify. But even today, if you want to develop a native, cross-platform application, you have to give them all up or resort to using a relatively obscure language like Haskell.</p>
<p>It&#8217;s unfair to expect C++ to evolve to support these features, because it has decades of legacy code that it must be backwards compatible with. The language must be improved by either breaking legacy code or adding language features in an awkward sort of tacked-on way. Neither works very well, so the language evolves slowly or not at all.</p>
<p>I don&#8217;t mean to knock C++; sometimes it&#8217;s exactly what the problem needs. But I think a lot of programmers&#8217; time is wasted solving high level problems with low level tools.</p>
<p>I&#8217;m doubtful that any one language will ever be the right tool for every job. Certain abstractions work well with certain domains (continuations with web programming, the actor model with concurrency, etc.), and abstractions that are baked into the language tend to have advantages to those that aren&#8217;t.</p>
<p>That&#8217;s why I welcome new programming languages. And as long as programming languages are less expressive than written English, I&#8217;ll keep welcoming them.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/do-we-really-need-another-programming-language/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>N-Queens in a Tweet</title>
		<link>http://paulbutler.org/archives/n-queens-in-a-tweet/</link>
		<comments>http://paulbutler.org/archives/n-queens-in-a-tweet/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 04:36:32 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://paulbutler.org/?p=145</guid>
		<description><![CDATA[Most people who like puzzles or study computer science have probably encountered the famous N-Queens problem. If you haven&#8217;t, before reading any further, try this online version of the most popular form, the 8-Queens problem.
The 8-Queens problem is to find positions on a chess board for eight queen chess pieces so that none of them [...]]]></description>
			<content:encoded><![CDATA[<p>Most people who like puzzles or study computer science have probably encountered the famous <a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle">N-Queens problem</a>. If you haven&#8217;t, before reading any further, try this <a href="http://www.hbmeyer.de/backtrack/achtdamen/eight.htm">online version</a> of the most popular form, the 8-Queens problem.</p>
<p>The 8-Queens problem is to find positions on a chess board for eight <a href="http://en.wikipedia.org/wiki/Queen_(chess)">queen</a> chess pieces so that none of them &#8220;threaten&#8221; the others. Since a queen in chess can move horizontally, vertically, and diagonally, this means placing each queen on her own horizontal, vertical, and diagonal lines.</p>
<p>The N-Queens problem is a generalization of the 8-Queens problem with (surprise) <img src='http://s.wordpress.com/latex.php?latex=N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N' title='N' class='latex' /> queens instead of 8, on an <img src='http://s.wordpress.com/latex.php?latex=N%20%5Ctimes%20N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N \times N' title='N \times N' class='latex' /> board instead of a standard <img src='http://s.wordpress.com/latex.php?latex=8%20%5Ctimes%208&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='8 \times 8' title='8 \times 8' class='latex' /> chess board.</p>
<p>In the spirit of <a href="http://en.wikipedia.org/wiki/Perl#Perl_golf">Perl Golf</a>, I wondered what the minimal amount of code would be to solve the N-Queens problem. As an arbitrary target, I picked 140 characters, also the limit on message length imposed by Twitter. I picked Haskell, knowing its list functions and generally terse syntax would come in handy. Naturally, I broke all the conventions that would cost extra characters, like using whitespace and explicit function signatures.</p>
<p>Since Haskell modules have a bit of overhead that would use up my valuable characters, I had to cheat a bit by leaving the module declaration out. The only way to run the program unmodified is to name it <samp><a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html">.ghci</a></samp> to trick GHCi into using it as a start script.</p>
<p>The result follows. I used 140 characters exactly, including the newline character.</p>
<div class="geshi no haskell">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">import</span> Data<span class="sy0">.</span>List</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">let</span> nqueens n<span class="sy0">=</span><span class="br0">&#91;</span><span class="kw3">zipWith</span><span class="br0">&#40;</span>\x y<span class="sy0">-&gt;</span>x:<span class="kw3">show</span> y<span class="br0">&#41;</span><span class="br0">&#91;</span>&#39;a&#39;<span class="sy0">..</span><span class="br0">&#93;</span>x<span class="sy0">|</span>x<span class="sy0">&lt;-</span>permutations<span class="br0">&#91;</span><span class="nu0">1</span><span class="sy0">..</span>n<span class="br0">&#93;</span>,<span class="br0">&#40;</span><span class="kw3">length</span><span class="sy0">$</span>nub<span class="sy0">$</span>zipWith<span class="br0">&#40;</span><span class="sy0">+</span><span class="br0">&#41;</span><span class="br0">&#40;</span>x<span class="sy0">++</span>x<span class="br0">&#41;</span><span class="sy0">$</span><span class="br0">&#91;</span><span class="nu0">0</span>,<span class="nu0">-1</span><span class="sy0">..</span><span class="nu0">1</span><span class="sy0">-</span>n<span class="br0">&#93;</span><span class="sy0">++</span><span class="br0">&#91;</span>n<span class="sy0">..</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">==</span>n<span class="sy0">*</span><span class="nu0">2</span><span class="br0">&#93;</span></div>
</li>
</ol>
</div>
<p>Pretty, eh? Fine, maybe not, but it works:</p>
<pre>
> nqueens 4
[["a2","b4","c1","d3"],["a3","b1","c4","d2"]]
> nqueens 5
[["a2","b4","c1","d3","e5"],["a3","b1","c4","d2","e5"],
["a3","b5","c2","d4","e1"],["a4","b2","c5","d3","e1"],
["a2","b5","c3","d1","e4"],["a1","b3","c5","d2","e4"],
["a4","b1","c3","d5","e2"],["a5","b3","c1","d4","e2"],
["a1","b4","c2","d5","e3"],["a5","b2","c4","d1","e3"]]
</pre>
<p>The result is a list of queen positions given as <a href="http://en.wikipedia.org/wiki/Algebraic_chess_notation#Naming_squares_on_the_board">coordinates on a chess board</a> (generalizing them in the obvious way).</p>
<p>As an example, the result <samp>["a1","b5","c8","d6","e3","f7","g2","h4"]</samp> would look like this:</p>
<div id="attachment_195" class="wp-caption none" style="width: 312px"><a href="http://paulbutler.org/wp-content/uploads/2009/06/8queens.png"><img src="http://paulbutler.org/wp-content/uploads/2009/06/8queens.png" alt="Eight Queens Solution" width="302" height="302" class="size-full wp-image-195" /></a>
<p class="wp-caption-text">Eight Queens Solution (created with <a href="http://www.chessup.net/">ChessUp</a>)</p>
</div>
<p>Before I explain how it works, I&#8217;ll put the whitespace back in.</p>
<div class="geshi no haskell">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">import</span> Data<span class="sy0">.</span>List</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">let</span> nqueens n <span class="sy0">=</span> <span class="br0">&#91;</span><span class="kw3">zipWith</span> <span class="br0">&#40;</span>\x y <span class="sy0">-&gt;</span> x : <span class="kw3">show</span> y<span class="br0">&#41;</span> <span class="br0">&#91;</span>&#39;a&#39;<span class="sy0">..</span><span class="br0">&#93;</span> x <span class="sy0">|</span> x <span class="sy0">&lt;-</span> permutations <span class="br0">&#91;</span><span class="nu0">1</span><span class="sy0">..</span>n<span class="br0">&#93;</span>, <span class="br0">&#40;</span><span class="kw3">length</span> <span class="sy0">$</span> nub <span class="sy0">$</span> <span class="kw3">zipWith</span> <span class="br0">&#40;</span><span class="sy0">+</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>x <span class="sy0">++</span> x<span class="br0">&#41;</span> <span class="sy0">$</span> <span class="br0">&#91;</span><span class="nu0">0</span>,<span class="nu0">-1</span><span class="sy0">..</span><span class="nu0">1</span><span class="sy0">-</span>n<span class="br0">&#93;</span> <span class="sy0">++</span> <span class="br0">&#91;</span>n<span class="sy0">..</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">==</span> n<span class="sy0">*</span><span class="nu0">2</span><span class="br0">&#93;</span></div>
</li>
</ol>
</div>
<p>Ignore diagonal movements for now &mdash; we could call it the N-<a href="http://en.wikipedia.org/wiki/Rook_(chess)">Rooks</a> problem. If we want to place <img src='http://s.wordpress.com/latex.php?latex=N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N' title='N' class='latex' /> rooks on a chess board so none of them are threatened, each needs to be in its own column and row. If you number the rows <img src='http://s.wordpress.com/latex.php?latex=1%2C%202%20%5Cldots%20N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1, 2 \ldots N' title='1, 2 \ldots N' class='latex' />, each solution corresponds to a permutation of these numbers. The board above, for example, would be <samp>[1, 5, 8, 6, 3, 7, 2, 4]</samp>. So to solve the N-Rooks problem in Haskell, all we need is <samp>permutations [1..n]</samp>.</p>
<p>That&#8217;s a good start, but we have to consider the diagonal lines as well. The simplest way to do this is to assign the columns numbers from <img src='http://s.wordpress.com/latex.php?latex=1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1' title='1' class='latex' /> to <img src='http://s.wordpress.com/latex.php?latex=N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N' title='N' class='latex' />. Then add those to the number of the row the queen in that column is in (remember, since we are using permutations, there is exactly one queen in each column).</p>
<p>For example, if we add <samp>[1, 5, 8, 6, 3, 7, 2, 4]</samp> and <samp>[1, 2, 3, 4, 5, 6, 7, 8]</samp>, we get <samp>[2, 7, 11, 10, 8, 13, 9, 12]</samp>. The resulting numbers are all different, so the queens are all on different diagonal lines &mdash; at least for downward diagonals. For upward diagonals, we could do the same thing but use <samp>[N..1]</samp> instead of <samp>[1..N]</samp>.</p>
<p>Since every character counts here, it&#8217;s better if we can do both diagonal directions at once. This complicates things a bit because without caution, the numbers for upward diagonal lines will overlap with those for downward diagonal lines. Fortunately, we can just add a constant factor of at least <img src='http://s.wordpress.com/latex.php?latex=2N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2N' title='2N' class='latex' /> to either set of lines. This is essentially what the code above does, although the arithmetic is a bit more cryptic to keep the character count down.</p>
<p>The resulting list will have <img src='http://s.wordpress.com/latex.php?latex=2N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2N' title='2N' class='latex' /> elements &mdash; <img src='http://s.wordpress.com/latex.php?latex=N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N' title='N' class='latex' /> for the upward diagonal lines and <img src='http://s.wordpress.com/latex.php?latex=N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='N' title='N' class='latex' /> more for the downward ones. Now we can use <samp>nub</samp> to rid the list of duplicates. If the list had no duplicates &mdash; that is, each queen is on her own diagonal lines &mdash; the <span>length</span> of that list will still equal <img src='http://s.wordpress.com/latex.php?latex=2N&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2N' title='2N' class='latex' /> after duplicates are removed. That makes it a valid solution, so it is included in the result.</p>
<p>I should note that this algorithm isn&#8217;t (nearly) as efficient as a standard backtracking approach as described on Wikipedia&#8217;s <a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle_solutions">eight queens puzzle solutions article</a>. But good luck getting one of those solutions into a tweet.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/n-queens-in-a-tweet/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Start-ups from UWaterloo Class of 2009</title>
		<link>http://paulbutler.org/archives/start-ups-from-uwaterloo-class-of-2009/</link>
		<comments>http://paulbutler.org/archives/start-ups-from-uwaterloo-class-of-2009/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 05:28:53 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Waterloo]]></category>

		<guid isPermaLink="false">http://paulbutler.org/?p=129</guid>
		<description><![CDATA[I was curious to know how many companies were founded by UWaterloo&#8217;s class of 2009, so I put together a list. It&#8217;s probably incomplete (let me know in the comments), but it may be of interest to anyone who follows the entrepreneurial community in Waterloo.
NeverBored Studios is a Waterloo-based game company founded by Velocity &#8220;alumni&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I was curious to know how many companies were founded by UWaterloo&#8217;s class of 2009, so I put together a list. It&#8217;s probably incomplete (let me know in the comments), but it may be of interest to anyone who follows the entrepreneurial community in Waterloo.</p>
<p><strong><a href="http://neverboredstudios.com/">NeverBored Studios</a></strong> is a Waterloo-based game company founded by <a href="http://velocity.uwaterloo.ca/">Velocity</a> &#8220;alumni&#8221; Jimmy Ho, Thomas Ang, Orin Bishop, and Steve Truong. They are working on an iPhone game called ThreadBound, which they <a href="http://www.youtube.com/watch?v=8L8INVjztuA" title="ThreadBound demo video">demo on YouTube</a>. They were recently <a href="http://www.techvibes.com/blog/neverbored-studios-set-to-launch-threadbound-for-the-iphone">covered on TechVibes</a>.</p>
<p><strong><a href="http://eightytwentygroup.com/">EightyTwenty Group</a></strong>, founded by <a href="http://twitter.com/ray_cao">Ray Cao</a> and <a href="http://twitter.com/aditya8020">Aditya Shah</a> in Toronto. They are working on enterprise software for law firms. Ray is a former president of <a href="http://www.impact.org/">Impact</a>. I had the pleasure of working with Ray at <a href="http://www.polarmobile.com/">Polar Mobile</a> (another UWaterloo start-up) last summer. He and Aditya are smart and capable guys, so I&#8217;m looking forward to seeing EightyTwenty Group progress. EightyTwenty Group was featured in a <a href="http://www.nationalpost.com/todays-paper/story.html?id=1418354">National Post</a> article in March.</p>
<p><strong><a href="http://www.giftah.com/">Giftah</a></strong> originated as a Velocity project. Although it is only a part-time project for founders Rezart Bajraktari, Nick Belyaev and Henry Finn, they&#8217;ve managed to create a functional site that has been featured on <a href="http://www.youtube.com/watch?v=IuWLeDEIlPM">CTV</a> and <a href="http://communities.canada.com/montrealgazette/blogs/tech/archive/2009/01/02/giftah-lets-canadians-sell-unwanted-gift-cards.aspx">The Montreal Gazette</a>. They also won $2,000 at the <a href="http://www.techvibes.com/blog/giftah-unsynced-and-say-more-are-velocitys-winning-teams">Velocity Project Exhibition</a>.</p>
<p><strong><a href="http://unsynced.com/">Unsynced</a></strong> is a Toronto software start-up founded by Ted Livingston, Vassili Skarine, and Vick Yao. They are developing BlackBerry software to allow users to sync their music collection and listen from their BlackBerry. Unsynced won free patent filing services at the <a href="http://www.techvibes.com/blog/giftah-unsynced-and-say-more-are-velocitys-winning-teams">(Winter 2009) Velocity Project Exhibition</a>. They were also <a href="http://www.techvibes.com/blog/unsynced-puts-your-entire-music-collection-in-your-pocket">featured on TechVibes</a>.</p>
<p>Mississauga-based <strong><a href="http://www.soeie.com/">Soeie</a></strong> is developing a tool for organizing research called <strong><a href="http://www.thinkpanda.com">Thinkpanda</a></strong>. I can&#8217;t find names of the entire founding team, but I do know that <a href="http://twitter.com/fahdoo">Fahd Butt</a> has the title &#8220;CTO&#8221; (&#8220;Chief Thinker Officer&#8221;). Technically I think these guys are class of 2008, but since Thinkpanda is a new product and looks promising, I&#8217;ve included them anyway. They also have a cool logo.</p>
<p><em>Update: I found another (thanks, <a href="http://peterkao.com/">Peter</a>)</em></p>
<p><strong><a href="http://www.allerta.ca/">Allerta</a></strong> started as the Velocity project of Eric Migicovsky. They are working on a wristwatch which, among other things, displays the caller ID from your BlackBerry when you get a call. Eric was profiled in <a href="http://news.therecord.com/Business/article/428065">The Record</a> last October after winning a $1,000 pitch competition. Allerta is based in Waterloo.</p>
<p>A few observations:</p>
<ul>
<li>Most start-ups left Waterloo to go to Toronto.</li>
<li>Three of five were part of Velocity. To me, this is some validation for Velocity after just two terms.</li>
<li>Two consumer web apps, two mobile apps, and one enterprise software company.</li>
<li>Most of the founders were engineering students.</li>
</ul>
<p><em>Update 2: corrected Fahd Butt&#8217;s title (thanks, <a href="http://meetrajesh.com/">Rajesh</a>)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/start-ups-from-uwaterloo-class-of-2009/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Python Debugging with Decorators</title>
		<link>http://paulbutler.org/archives/python-debugging-with-decorators/</link>
		<comments>http://paulbutler.org/archives/python-debugging-with-decorators/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 00:20:40 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/python-debugging-with-decorators/</guid>
		<description><![CDATA[I&#8217;ve written a little python function which I have found to be very helpful for debugging. It takes a function, and returns a function which is identical to the original except that it prints a message to the console with useful information every time the function is called or returns.
Here is the function:



# Number of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a little python function which I have found to be very helpful for debugging. It takes a function, and returns a function which is identical to the original except that it prints a message to the console with useful information every time the function is called or returns.</p>
<p>Here is the function:</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1"><span class="co1"># Number of times to indent output</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># A list is used to force access by reference</span></div>
</li>
<li class="li1">
<div class="de1">__report_indent = <span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> report<span class="br0">&#40;</span>fn<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot;Decorator to print information about a function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;call for use while debugging.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;Prints function name, arguments, and call number</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;when the function is called. Prints this information</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;again along with the return value when the function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;returns.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &nbsp; &nbsp;&quot;</span><span class="st0">&quot;&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">def</span> wrap<span class="br0">&#40;</span><span class="sy0">*</span>params,<span class="sy0">**</span>kwargs<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; call = wrap.<span class="me1">callcount</span> = wrap.<span class="me1">callcount</span> + <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; indent = <span class="st0">&#39; &#39;</span> <span class="sy0">*</span> __report_indent<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; fc = <span class="st0">&quot;%s(%s)&quot;</span> <span class="sy0">%</span> <span class="br0">&#40;</span>fn.__name__, <span class="st0">&#39;, &#39;</span>.<span class="me1">join</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>a.<span class="kw4">__repr__</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">for</span> a <span class="kw1">in</span> params<span class="br0">&#93;</span> +</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span><span class="st0">&quot;%s = %s&quot;</span> <span class="sy0">%</span> <span class="br0">&#40;</span>a, <span class="kw2">repr</span><span class="br0">&#40;</span>b<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">for</span> a,b <span class="kw1">in</span> kwargs.<span class="me1">items</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span> <span class="st0">&quot;%s%s called [#%s]&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">%</span> <span class="br0">&#40;</span>indent, fc, call<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; __report_indent<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> += <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; ret = fn<span class="br0">&#40;</span><span class="sy0">*</span>params,<span class="sy0">**</span>kwargs<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; __report_indent<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> -= <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span> <span class="st0">&quot;%s%s returned %s [#%s]&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">%</span> <span class="br0">&#40;</span>indent, fc, <span class="kw2">repr</span><span class="br0">&#40;</span>ret<span class="br0">&#41;</span>, call<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> ret</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; wrap.<span class="me1">callcount</span> = <span class="nu0">0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> wrap</div>
</li>
</ol>
</div>
<p>The function can be used as a decorator. For example, in this simple (and inefficient) recursive Fibonacci sequence function:</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1">@report</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> fibonacci<span class="br0">&#40;</span>n<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> n <span class="kw1">in</span> <span class="br0">&#91;</span><span class="nu0">0</span>,<span class="nu0">1</span><span class="br0">&#93;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> n</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> fibonacci<span class="br0">&#40;</span>n &#8211; <span class="nu0">1</span><span class="br0">&#41;</span> + fibonacci<span class="br0">&#40;</span>n &#8211; <span class="nu0">2</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>The result:</p>
<div class="geshi no text">
<ol>
<li class="li1">
<div class="de1">&gt;&gt;&gt; fibonacci(4)</div>
</li>
<li class="li1">
<div class="de1">fibonacci(4) called [#1]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;fibonacci(3) called [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(2) called [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;fibonacci(1) called [#4]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;fibonacci(1) returned 1 [#4]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;fibonacci(0) called [#5]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;fibonacci(0) returned 0 [#5]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(2) returned 1 [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(1) called [#6]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(1) returned 1 [#6]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;fibonacci(3) returned 2 [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;fibonacci(2) called [#7]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(1) called [#8]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(1) returned 1 [#8]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(0) called [#9]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; fibonacci(0) returned 0 [#9]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;fibonacci(2) returned 1 [#7]</div>
</li>
<li class="li1">
<div class="de1">fibonacci(4) returned 3 [#1]</div>
</li>
<li class="li1">
<div class="de1">3</div>
</li>
</ol>
</div>
<p>The level of indent reflects the level of recursion, and the [#...] at the end of each line is the number of times the function has been called.</p>
<p>The level of indent is independent of the function being called, so it is helpful with mutual recursion as well. For example, when used with the functions <samp>even</samp> and <samp>odd</samp> from my earlier <a href="http://www.paulbutler.org/archives/tail-recursion-in-python/">post on tail recursion</a>, the result looks like this:</p>
<div class="geshi no text">
<ol>
<li class="li1">
<div class="de1">&gt;&gt;&gt; even(5)</div>
</li>
<li class="li1">
<div class="de1">even(5) called [#1]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;odd(4) called [#1]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; even(3) called [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;odd(2) called [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; even(1) called [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;odd(0) called [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;odd(0) returned False [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; even(1) returned False [#3]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;odd(2) returned False [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp; even(3) returned False [#2]</div>
</li>
<li class="li1">
<div class="de1">&nbsp;odd(4) returned False [#1]</div>
</li>
<li class="li1">
<div class="de1">even(5) returned False [#1]</div>
</li>
<li class="li1">
<div class="de1">False</div>
</li>
</ol>
</div>
<p>I find it useful to stick <samp>@report</samp> before the function I am having trouble with, and use comments to turn it on and off while I&#8217;m debugging that function. It can also be used at times other than function declaration, for example: <samp>report(base64.encodestring)(&#8216;test&#8217;)</samp>.</p>
<p><strong>Update (July 6, 2008)</strong>: Fixed so that keyword arguments are printed as well.</p>
<p><strong>Update (August 16, 2008)</strong>: Changed .__repr__() to the more proper repr().</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/python-debugging-with-decorators/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SimpleDiff in Python</title>
		<link>http://paulbutler.org/archives/simplediff-in-python/</link>
		<comments>http://paulbutler.org/archives/simplediff-in-python/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 21:22:32 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/simplediff-in-python/</guid>
		<description><![CDATA[A while ago I posted a PHP implementation of a diff algorithm I came up with1. Since it was well received, and it&#8217;s a useful little algorithm to have, I created a Python version as well.
There are a few performance improvements as well. The PHP version creates an array in memory proportional to the square [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I posted a <a href="http://www.paulbutler.org/archives/a-simple-diff-algorithm-in-php/">PHP implementation</a> of a diff algorithm I came up with<sup>1</sup>. Since it was well received, and it&#8217;s a useful little algorithm to have, I created a Python version as well.</p>
<p>There are a few performance improvements as well. The PHP version creates an array in memory proportional to the square of the size of the input, while the Python version&#8217;s array is directly proportional to the size of the input. I also sped up how the algorithm finds the indexes of the &#8220;new&#8221; elements in the &#8220;old&#8221; array.</p>
<p><a href="http://github.com/paulgb/simplediff/blob/5bfe1d2a8f967c7901ace50f04ac2d9308ed3169/simplediff.py">Download simplediff.py</a></p>
<p><sup>1</sup> It is probably the same algorithm that others use, but I haven&#8217;t gotten around to getting an ACM membership to access the related papers</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/simplediff-in-python/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Tail recursion in Python</title>
		<link>http://paulbutler.org/archives/tail-recursion-in-python/</link>
		<comments>http://paulbutler.org/archives/tail-recursion-in-python/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 03:58:32 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/tail-recursion-in-python/</guid>
		<description><![CDATA[After spending a lot of time in Scheme, it&#8217;s hard not to think in recursion from time to time. When I recently started to improve my Python skills, I missed having Scheme optimize my tail recursive calls.
For example, consider the mutually recursive functions even and odd. You know a number, n, is even if it [...]]]></description>
			<content:encoded><![CDATA[<p>After spending a lot of time in Scheme, it&#8217;s hard not to think in recursion from time to time. When I recently started to improve my Python skills, I missed having Scheme optimize my tail recursive calls.</p>
<p>For example, consider the mutually recursive functions <samp>even</samp> and <samp>odd</samp>. You know a number, <em>n</em>, is even if it is 0, or if <em>n</em> &#8211; 1 is odd. Similarly, you know a number is not odd if it is 0, and that it is odd if <em>n</em> &#8211; 1 is even. This translates to the python code:</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">def</span> even<span class="br0">&#40;</span>x<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> x == <span class="nu0">0</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">True</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> odd<span class="br0">&#40;</span>x &#8211; <span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> odd<span class="br0">&#40;</span>x<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> x == <span class="nu0">0</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">False</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> even<span class="br0">&#40;</span>x &#8211; <span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>This code works, but only for <em>x</em> &lt; 1000, because Python limits the recursion depth to 1000. As it turns out, it is easy to get around this limitation. Included below is a generic <samp>tail_rec</samp> function that could be used for most cases where you need tail recursion, and an example of it used for the odd/even problem.</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">def</span> tail_rec<span class="br0">&#40;</span>fun<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">def</span> tail<span class="br0">&#40;</span>fun<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; a = fun</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="kw2">callable</span><span class="br0">&#40;</span>a<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a = a<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> a</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw1">lambda</span> x: tail<span class="br0">&#40;</span>fun<span class="br0">&#40;</span>x<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> tail_even<span class="br0">&#40;</span>x<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> x == <span class="nu0">0</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">True</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw1">lambda</span>: tail_odd<span class="br0">&#40;</span>x &#8211; <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> tail_odd<span class="br0">&#40;</span>x<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> x == <span class="nu0">0</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">False</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><span class="kw1">lambda</span>: tail_even<span class="br0">&#40;</span>x &#8211; <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">even = tail_rec<span class="br0">&#40;</span>tail_even<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">odd = tail_rec<span class="br0">&#40;</span>tail_odd<span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>It&#8217;s not as pretty as the Scheme version, but it does the trick. Of course, the odd/even functions are just for the sake of a simple example and have no real-world use, but the <samp>tail_rec</samp> function could be used in practice.</p>
<p><strong>April 2009 Update</strong>: this article has recently had some popularity. One of the more common comments is that tail_rec could be used as a decorator. In fact, this isn&#8217;t true, because <samp>even</samp> and <samp>odd</samp> need access to the raw, undecorated versions of each other in the creation of the lambda.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/tail-recursion-in-python/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>JSSpamBlock 2.0, ImageScaler 1.1</title>
		<link>http://paulbutler.org/archives/jsspamblock-20-imagescaler-11/</link>
		<comments>http://paulbutler.org/archives/jsspamblock-20-imagescaler-11/#comments</comments>
		<pubDate>Sun, 21 Oct 2007 00:48:27 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Image Scaler]]></category>
		<category><![CDATA[JSSpamBlock]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/jsspamblock-20-imagescaler-11/</guid>
		<description><![CDATA[Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.
JSSpamBlock and ImageScaler were both originally one-day projects that turned out to be a bit more popular than I expected. Recently I have neglected to update them at all, but with reports of ImageScaler not working on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.</strong></p>
<p>JSSpamBlock and ImageScaler were both originally one-day projects that turned out to be a bit more popular than I expected. Recently I have neglected to update them at all, but with reports of ImageScaler not working on WordPress 2.3, I decided to put a day aside and make some changes I had been meaning to make for a while.</p>
<p>A new version of <strong>ImageScaler</strong> was released last week (thanks to <a href="http://www.davidkarlsson.info/">David Karlsson</a> for doing most if not all of the work). I still got comments that it didn&#8217;t work with WordPress 2.3, so I installed WordPress 2.3 myself to see what the problem is. I didn&#8217;t have any issues, but I made some changes to ImageScaler that might make it more likely to work. If you still have problems with WordPress 2.3, let me know. I also made another major change &#8211; images hosted on other servers were previously ignored by ImageScaler and left as-is. Now they are mirrored on the server and can be re-sized properly. Also, images are now always resized so that the aspect ratio is preserved. You can download <a href="http://wordpress.org/extend/plugins/image-scaler/">ImageScaler 1.1</a> from WordPress.</p>
<p>The new version of <strong>JSSpamBlock</strong> doesn&#8217;t need a database. It uses sessions instead. I also cleaned up the code a bit and tested it with WordPress 2.3. You can download <a href="http://wordpress.org/extend/plugins/jsspamblock/">JSSpamBlock 2.0</a> from WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/jsspamblock-20-imagescaler-11/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>JSSpamBlock-like protection for any website</title>
		<link>http://paulbutler.org/archives/jsspamblock-like-protection-for-any-website/</link>
		<comments>http://paulbutler.org/archives/jsspamblock-like-protection-for-any-website/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 13:59:36 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[JSSpamBlock]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/jsspamblock-like-protection-for-any-website/</guid>
		<description><![CDATA[Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.
I just noticed a trackback from Brandon Cheketts about a PHP script he has released that lets you incorporate functionality similar to JSSpamBlock in any website, called bcSpamBlock. He also released a WordPress plugin based on JSSpamBlock [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.</strong></p>
<p>I just noticed a trackback from <a href="http://www.brandonchecketts.com/">Brandon Cheketts</a> about a PHP script he has released that lets you incorporate functionality similar to JSSpamBlock in any website, called <a href="http://www.brandonchecketts.com/bcspamblock/">bcSpamBlock</a>. He also released a WordPress plugin based on JSSpamBlock that uses the script.</p>
<p>Although both plugins take advantage of the same limitation of spam bots &#8211; that they ignore JavaScript, the way they verify the codes is different. While JSSpamBlock uses a database, bcSpamBlock uses one-way encryption to verify the codes. Although this is a clever way to do it, I chose not to do it in JSSpamBlock for a reason: Storing the code in a database ensures that, even if a spammer were to write a bot targeting sites with JSSpamBlock, each comment posted would require the bot to parse another page from the server. Each code sent to the browser can only be used once. The problem with not using a database is that you have no way to verify that the codes sent from the browser are being used for the first time, and not the 10th.</p>
<p><a href="http://blog.gkaindl.com/">Georg Kaindl</a> made similar comments about the database being unnecessary, and I wrote a more lengthy <a href="http://blog.gkaindl.com/2007/04/18/outsmarting-spam-bots/#comments">response</a> explaining why it was. He then came up with a clever solution &#8211; including the post&#8217;s ID in the hash. It still isn&#8217;t quite as secure as JSSpamBlock (I hate to use the word &#8220;secure&#8221; to describe what I admit is &#8220;security-by-inconvenience&#8221;, but I can&#8217;t think of another word that fits), but for all practical purposes it should be just as good. The only difference is that spammers could post multiple comments to any given post while only parsing the page once, while JSSpamBlock would require the page to be parsed once for each comment. The other advantage is that I do not have to rely on the JSSpamBlock user to come up with a unique salt in order for the protection to be secure. bcSpamBlock gets around this in a clever way, by using unchanging environment variables to generate the salt.</p>
<p>Another way to look at it is that generating a random code for each page view does not actually increase security (over using the same code for each page view) unless you use a database. So for a plugin that doesn&#8217;t use a database, this only gives the illusion of security. You might as well use the code &#8220;4422&#8243; for everything, and it would be just as secure. This might sound bad, but any bot that is currently blocked by JSSpamBlock would be blocked by this as well. The only reason JSSpamBlock does more is to make it harder to write a bot that specifically targets JSSpamBlock. It may sound egotistical to suggest that a spammer would ever bother to write a bot specifically targeting the plugin, but for the extra cost (milliseconds of CPU time), I think it is worth making the plugin slightly more future-proof.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/jsspamblock-like-protection-for-any-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ImageScaler 1.0</title>
		<link>http://paulbutler.org/archives/imagescaler-10/</link>
		<comments>http://paulbutler.org/archives/imagescaler-10/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 22:27:03 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[Image Scaler]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/imagescaler-10/</guid>
		<description><![CDATA[Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.
This blog has been a bit slow since I started school, partly because of the extra work but also partly because the &#8220;just for fun&#8221; projects I have been working on have gotten larger. At the same [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.</strong></p>
<p>This blog has been a bit slow since I started <a href="http://uwaterloo.ca">school</a>, partly because of the extra work but also partly because the &#8220;<em>just for fun</em>&#8221; projects I have been working on have gotten larger. At the same time, I hate to neglect my existing projects to start other ones. Given that, I was very lucky to have <a href="http://www.davidkarlsson.info/">David Karlsson</a>, who had released a modified version of Image Scaler, agree to incorporate the original functionality back in so that I could make it an official release. The biggest improvement is that you can now set a maximum width and height, which are used to resize all the images. So if your theme breaks with images over 600 pixels in width, Image Scaler is a graceful way to stop this from happening.</p>
<p>You can <a href="http://wordpress.org/extend/plugins/image-scaler/">download Image Scaler 1.0</a> from WordPress, where it is hosted.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/imagescaler-10/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Proper Image Resizing for WordPress</title>
		<link>http://paulbutler.org/archives/proper-image-resizing-for-wordpress/</link>
		<comments>http://paulbutler.org/archives/proper-image-resizing-for-wordpress/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 16:14:01 +0000</pubDate>
		<dc:creator>Paul Butler</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.paulbutler.org/archives/proper-image-resizing-for-wordpress/</guid>
		<description><![CDATA[Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.
WordPress has a cool WYSIWIG editor that lets you easily resize images by dragging the corner around. The problem is that WordPress does not actually resize the image, it just tells the browser to display it smaller. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: Due to lack of time and interest (on my part), I am no longer maintaining JSSpamBlock or ImageScaler.</strong></p>
<p>WordPress has a cool WYSIWIG editor that lets you easily resize images by dragging the corner around. The problem is that WordPress does not actually resize the image, it just tells the browser to display it smaller. This means that the full sized image is being sent to the browser, which makes the page load slower and take up more bandwidth. Additionally, most browsers are bad at resizing images, so the images look worse than if they were properly resized.</p>
<p>To get around this, I wrote a WordPress plugin called ImageScaler. <strike>I am still waiting for it to be approved by WordPress for hosting, so I have hosted it myself for now.</strike> It requires GD (almost all web hosts with PHP will have GD). It should work with PHP 4, but it has only been tested on PHP 5.</p>
<p><em>[Example removed]</em></p>
<p><strong>Update</strong>: the plugin is now <a href="http://wordpress.org/extend/plugins/image-scaler/">hosted by WordPress</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbutler.org/archives/proper-image-resizing-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>
