<?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>Intrepid Blog &#187; stupid</title>
	<atom:link href="http://blog.affien.com/archives/tag/stupid/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.affien.com</link>
	<description>A few thoughts</description>
	<lastBuildDate>Mon, 23 Jan 2012 08:47:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Twitter and Facebook</title>
		<link>http://blog.affien.com/archives/2009/08/07/twitter-and-facebook/</link>
		<comments>http://blog.affien.com/archives/2009/08/07/twitter-and-facebook/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 23:46:19 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google wave]]></category>
		<category><![CDATA[stupid]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.affien.com/?p=398</guid>
		<description><![CDATA[were both victim of a DDoS today.  Silently, I always h [...]]]></description>
			<content:encoded><![CDATA[<p>were both victim of a DDoS today.  Silently, I always hoped that a really long-lasting one will convince them to put effort in a distributed scheme.</p>
<p>Maybe I should be waiting for another <a href="http://wave.google.com/">Wave</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2009/08/07/twitter-and-facebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Damned DOM (1)</title>
		<link>http://blog.affien.com/archives/2009/06/22/damned-dom-1/</link>
		<comments>http://blog.affien.com/archives/2009/06/22/damned-dom-1/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:34:51 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.affien.com/?p=391</guid>
		<description><![CDATA[When I wanted to react to any changes to a input textbo [...]]]></description>
			<content:encoded><![CDATA[<p>When I wanted to react to any changes to a <code>input</code> textbox immediately, my first instrinct was to use <code>onChange</code>.  <code>onChange</code>, however, is called when the <code>input</code> loses focus.  <code>onKeyPress</code> then?  Isn&#8217;t called on backspaces.  <code>onKeyDown</code>, maybe?  It does get called, but the effect of the keystroke isn&#8217;t yet applied, for the return value determines whether it that is done in the first place. (Same story for <code>onKeyPress</code> by the way.) <code>onKeyUp</code> does work a bit, except if someone is holding down a single key, for a while.</p>
<p>The solution: hook <code>onKeyUp</code> and use <code>setTimeout</code> with a timeout of 0.  Yugh.  I hate DOM.</p>
<p><em><ins>Big Fat Disclaimer</ins>: I actually tested this only on one browser.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2009/06/22/damned-dom-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django annoyances: no reverse select_related</title>
		<link>http://blog.affien.com/archives/2009/05/30/django-annoyances-no-reverse-select_related/</link>
		<comments>http://blog.affien.com/archives/2009/05/30/django-annoyances-no-reverse-select_related/#comments</comments>
		<pubDate>Sat, 30 May 2009 13:48:45 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[select_related]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.affien.com/?p=380</guid>
		<description><![CDATA[Consider

for page in Page.objects.all():
&#160;&#038;nbs [...]]]></description>
			<content:encoded><![CDATA[<p>Consider</p>
<p><code>for page in Page.objects.all():<br />
&nbsp;&nbsp;print page.title<br />
&nbsp;&nbsp;for comment in page.comments.all():<br />
&nbsp;&nbsp;&nbsp;&nbsp;print comment</code>.</p>
<p>There will be a single query to fetch all pages, but there will be for every page another query to fetch its comments.  Luckily, Django has got a nice trick up its sleave: <code>select_related</code>.  Would I use instead of <code>Page.objects.all()</code>, <code>Page.objects.select_related('comments').all()</code> then Django will use a single joined query to prefetch comments for each page.</p>
<p>However, Django&#8217;s <code>select_related</code> only supports forward one-to-many references.  No many-to-many; certainly no reverce many-to-many; no reverse one-to-many and no, not even reverse one-to-one (<a href="http://code.djangoproject.com/ticket/7270">yet</a>).  <a href="http://code.djangoproject.com/ticket/2238">A developer</a> claims it&#8217;s impossible (which is bullshit), <a href="http://code.djangoproject.com/ticket/9166">another</a> asks for patches, which means he doesn&#8217;t care doing it himself.</p>
<p>It&#8217;s quite easy to manually code around the missing reverse <code>select_related</code>, but it takes too many ugly lines compared to the single word it could&#8217;ve been.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2009/05/30/django-annoyances-no-reverse-select_related/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript&#8217;s stupid Date constructor</title>
		<link>http://blog.affien.com/archives/2009/04/29/javascripts-stupid-date-constructor/</link>
		<comments>http://blog.affien.com/archives/2009/04/29/javascripts-stupid-date-constructor/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 16:27:42 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.affien.com/archives/2009/04/29/javascripts-stupid-date-constructor/</guid>
		<description><![CDATA[new Date(2009, 1, 1) represents the first of February 2 [...]]]></description>
			<content:encoded><![CDATA[<p><code>new Date(2009, 1, 1)</code> represents the first of February 2009.  Not the second of February nor the first of January.  Why this stupidity?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2009/04/29/javascripts-stupid-date-constructor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Stupid PHP (1) (Strings are faster than Arrays)</title>
		<link>http://blog.affien.com/archives/2007/09/23/stupid-php-1-strings-are-faster-than-arrays/</link>
		<comments>http://blog.affien.com/archives/2007/09/23/stupid-php-1-strings-are-faster-than-arrays/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 17:05:14 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[concat]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2007/09/23/stupid-php-1-strings-are-faster-than-arrays/</guid>
		<description><![CDATA[When I slowly build a big string out of little bits, th [...]]]></description>
			<content:encoded><![CDATA[<p>When I slowly build a big string out of little bits, the worst thing to do in most languages is to just use string concatenation:</p>
<p><code>for(something) {<br />
&nbsp;str .= little_bit;<br />
}</code></p>
<p>Why? Everytime a little bit is added to <code>str</code>, there must be a new string allocated big enough to contain <code>str</code> and the new little bit. Then the actual <code>str</code> must be copied in. In most languages there are constructs to efficiently build strings like this instead of concatenating. StringBuffer in C#. StringIO in Python.</p>
<p>But no, PHP has to be stupid. There is no nice construct and you&#8217;ll end up using concatenation. So, I thought to be smart and make use of PHP array&#8217;s and <code>implode</code>. Arrays are here for having elements added and removed all the time so they are properly buffered and should be great at having lots of small elements added. And when I want to pack it all into one big string, I can use PHP&#8217;s builtin <code>implode</code> function.</p>
<p>I wanted to try it out and created two scripts: <code>a.php</code> concats a little (10byte) string one million times and <code>b.php</code> appends it to an array and then <code>implode</code>s it. And because I&#8217;m also interested in the performance of <code>implode</code> I got a script <code>c.php</code> that&#8217;s identical to <code>b.php</code> but doesn&#8217;t implode afterwards. These are the results:</p>
<table>
<tr>
<th>a.php (concat)</th>
<td>0.320s</td>
</tr>
<tr>
<th>b.php (array append and implode)</th>
<td>0.814s</td>
</tr>
<tr>
<th>c.php (array append)</th>
<td>0.732s</td>
</tr>
</table>
<p>Indeed, string concatenation with all its allocation and copying is actually faster than plain simple array appending. PHP is stupid.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2007/09/23/stupid-php-1-strings-are-faster-than-arrays/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Stupid IE (2)</title>
		<link>http://blog.affien.com/archives/2007/09/02/stupid-ie-2/</link>
		<comments>http://blog.affien.com/archives/2007/09/02/stupid-ie-2/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 13:02:46 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Code sniplets]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2007/09/02/stupid-ie-2/</guid>
		<description><![CDATA[To create a multiple select-box with javascript you nee [...]]]></description>
			<content:encoded><![CDATA[<p>To create a multiple select-box with javascript you need a <em>very</em> ugly hack in IE.</p>
<pre style="font-size: 1.5em">if (navigator.appName.match(/Internet Explorer/)) {
	fsel = document.createElement(\'&lt;SELECT MULTIPLE&gt;\');
} else {
	fsel = document.createElement(\'select\');
	fsel.multiple = true;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2007/09/02/stupid-ie-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Stupid IE (1)</title>
		<link>http://blog.affien.com/archives/2007/09/02/stupid-ie-1/</link>
		<comments>http://blog.affien.com/archives/2007/09/02/stupid-ie-1/#comments</comments>
		<pubDate>Sun, 02 Sep 2007 12:51:19 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Code sniplets]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[stupid]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2007/09/02/stupid-ie-1/</guid>
		<description><![CDATA[if(!Array.prototype.indexOf) {
	Array.prototype.indexO [...]]]></description>
			<content:encoded><![CDATA[<pre style="font-size: 1.5em">if(!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(el) {
		var i = 0;
		for(; i &lt; this.length; i++)
			if(this[i] == el)
				return i;
		return -1;
	};
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2007/09/02/stupid-ie-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

