<?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>Tunaslut</title>
	<atom:link href="http://www.tunaslut.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tunaslut.com</link>
	<description>confessions of a code slut. any language. any time. in brine.</description>
	<lastBuildDate>Sun, 05 Sep 2010 14:01:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Apple loves Microsoft</title>
		<link>http://www.tunaslut.com/apple-loves-microsoft/</link>
		<comments>http://www.tunaslut.com/apple-loves-microsoft/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 14:01:54 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=153</guid>
		<description><![CDATA[I don&#8217;t know why, but these sorts of things tickle me pink&#8230;. Don&#8217;t get it? Let&#8217;s look at it again. This time with a nice red arrow to direct your attention&#8230;.. Oh no! The great Apple is authenticating their higher education purchases through some thoroughly Microsoft based technology. Say it ain&#8217;t so!]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why, but these sorts of things tickle me pink&#8230;.<br />
<img src="http://www.tunaslut.com/wp-content/uploads/2010/09/apple-edu-discount-680x525.png" alt="Apple Educational Discount Store" title="apple-edu-discount" width="680" height="525" class="alignnone size-large wp-image-154" /><br />
Don&#8217;t get it?<br />
Let&#8217;s look at it again. This time with a nice red arrow to direct your attention&#8230;..<br />
<img src="http://www.tunaslut.com/wp-content/uploads/2010/09/apple-edu-discount2-680x525.png" alt="" title="apple-edu-discount2" width="680" height="525" class="alignnone size-large wp-image-155" /></p>
<p>Oh no! The great Apple is authenticating their higher education purchases through some thoroughly Microsoft based technology. Say it ain&#8217;t so!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/apple-loves-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Telerik Radgrid and filtering on ListTextField with a GridDropDownColumn</title>
		<link>http://www.tunaslut.com/telerik-radgrid-and-filtering-on-listtextfield-with-a-griddropdowncolumn/</link>
		<comments>http://www.tunaslut.com/telerik-radgrid-and-filtering-on-listtextfield-with-a-griddropdowncolumn/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 10:38:14 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=147</guid>
		<description><![CDATA[Another story in what it&#8217;s really like to develop software. These are the kinds of hacky bodges you will end up making in any system that is more than a few months old and is in production. These hacks do not make me happy. Especially when they are hacked because of pre-built components that are [...]]]></description>
			<content:encoded><![CDATA[<p>Another story in what it&#8217;s really like to develop software. These are the kinds of hacky bodges you will end up making in any system that is more than a few months old and is in production. <img src='http://www.tunaslut.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  These hacks do not make me happy. Especially when they are hacked because of pre-built components that are meant to save you time!</p>
<p>The Telerik Radgrid is both a blessing and a curse at the same time. How can a grid, that seems designed to have a dropdown column in it <em>and</em> comes with default filtering, not take into account the fact that you <strong>are</strong> going to have foreign keys in a grid that you want to filter on?</p>
<p>This is an ongoing rant of mine. Getting good foreign key support on large enterprise applications seems like an uphill struggle every single time. I wrote about how I like to see books on programming jump right in and <a href="http://www.tunaslut.com/learning-ruby-drop-down-lists-in-one-to-many-relationships/">show me how to get my foreign key drop downs hooked</a> up almost right off the bat, since it is almost entirely unavoidable in any application that has any sort of usefulness in my opinion.</p>
<p>My goodness getting the RadGrid to do your bidding can be an infuriating ride. Personally, I think components should just work out of the box. I know the RadGrid is extremely complex and there are layers upon layers of documentation and examples on the Telerik site, but to me, I shouldn&#8217;t have to find out about how difficult it is to filter on ListTextField after I&#8217;ve knocked up a prototyped to a client. Heck the documentation should have a large caveat at the top telling you the limitation of the software. Really, I shouldn&#8217;t need to read that far into the documentation just to use the component in my opinion. I want something quick and easy to take the pain out of grid based data admin, not a whole new bloody thing that I have to learn inside out.</p>
<p>As per Telerik&#8217;s website:</p>
<blockquote><p>he built-in GridDropDownColumn will be filtered by its ListValueField when the default filtering feature of the control is used. Filtering by ListTextField is not attainable in the present version of Telerik RadGrid</p></blockquote>
<p>Great. Thanks! This is burried in the How To section. Okay, not too obtuse, but still, all the basic examples show filtering on example datasets that are things like Customer listings (with Customer, Contact Name, Company). Heck, it is reasonable to assume that Company was being looked up using the GridDropDownColumn column. Isn&#8217;t it?</p>
<p>So, Telerik provide a solution &#8211; have a hidden field that is the text description. Capture the ItemCommand on the grid and then if it is a filter command, pop the filter text into the hidden field&#8217;s filter text box and run the filter based on that criteria. The problem is, out of the box this breaks user experience because the filter text they typed in <strong>disappears</strong>.</p>
<p>Now you have to hack around to find a way to keep the filter text there. Come on Telerik, get this one together. Not pleasant. I gave up, because I didn&#8217;t have time to delve that deeply into the RadGrid. I needed something quicker. Option 2 given by Telerik &#8211; implement a custom drop down in the actual filter area of the grid. The example code was long and I didn&#8217;t feel like going through it &#8211; again time constraints. I just couldn&#8217;t spend time exploring all of this because I have deadlines. Why couldn&#8217;t they just build this into the grid? If they have solutions, it shouldn&#8217;t be that difficult to put it into the base functionality.</p>
<p>One more thing &#8211; putting a drop down in that is based on an id field (and let&#8217;s be honest it probably is if it&#8217;s a lookup into another table) means you get the default &#8220;number&#8221; filtering options. This means that the filtering options out of the box are things like &#8220;greater than&#8221;, &#8220;less than&#8221; etc etc. These don&#8217;t make sense for a user who is filtering based on <strong>text</strong>. This is another fault with their default solution outlined above of using the hidden field and substituting values in. I know you can overide this and put your own filtering menu in, but say it with me&#8230;..<strong>deadlines</strong>. <img src='http://www.tunaslut.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>By now, I&#8217;m not a happy bunny. What did I do in the end? I amended my stored proc to bring back a complete result set with description fields (making things slower for me because now I have table joins). Then I hid the drop down list field until the user wanted to edit the row or add a new row in. Then I hid the description fields and showed the drop down fields.</p>
<p>What a bodge.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/telerik-radgrid-and-filtering-on-listtextfield-with-a-griddropdowncolumn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stupid SQL mistakes &#8211; more from the land of application support</title>
		<link>http://www.tunaslut.com/stupid-sql-mistakes-more-from-the-land-of-application-support/</link>
		<comments>http://www.tunaslut.com/stupid-sql-mistakes-more-from-the-land-of-application-support/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 09:58:07 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=142</guid>
		<description><![CDATA[Here&#8217;s a lovely little one that just took me much to long, probably because I&#8217;m tired, or having an off day or something: SELECT &#91;Name&#93; &#91;Surname&#93;, &#91;Address&#93;, &#91;Telephone&#93;, &#91;Email&#93; FROM ATableAboutPeople See, the error isn&#8217;t obvious, because the SQL compiles and runs, but the result set just doesn&#8217;t bring back what you expect&#8230;..because [Name] is [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a lovely little one that just took me much to long, probably because I&#8217;m tired, or having an off day or something:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#91;</span>Name<span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>Surname<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span>
         <span style="color: #66cc66;">&#91;</span>Address<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span>
         <span style="color: #66cc66;">&#91;</span>Telephone<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span>
         <span style="color: #66cc66;">&#91;</span>Email<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> ATableAboutPeople</pre></div></div>

<p>See, the error isn&#8217;t obvious, because the SQL compiles and runs, but the result set just doesn&#8217;t bring back what you expect&#8230;..because [Name] is now aliased as [Surname] &#8211; all because of a missing comma.<br />
Bollocks!<br />
Hate it when that happens.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/stupid-sql-mistakes-more-from-the-land-of-application-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sometimes the Asp bites you &#8211; Void System.Web.UI.WebControls.Parameter..ctor</title>
		<link>http://www.tunaslut.com/sometimes-the-asp-bites-you-void-system-web-ui-webcontrols-parameter-ctor/</link>
		<comments>http://www.tunaslut.com/sometimes-the-asp-bites-you-void-system-web-ui-webcontrols-parameter-ctor/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 11:37:43 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[cleopatra. ctor]]></category>
		<category><![CDATA[error]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=133</guid>
		<description><![CDATA[There are days when ASP really lives up to its namesake and just completely kills you, or more accurately, kills your webserver that has previously managed to woo you as if it were Cleopatra herself. Seriously. Microsoft needs to sort out this inter platform CLR bollocks. How is it that an application working perfectly on [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-136 aligncenter" title="505px-Cleopatra_with_the_Asp_(1630);_Reni,_Guido" src="http://www.tunaslut.com/wp-content/uploads/2010/06/505px-Cleopatra_with_the_Asp_1630_Reni_Guido.jpg" alt="Cleopatra and the asp" width="505" height="599" /></p>
<p>There are days when ASP really lives up to its namesake and just completely kills you, or more accurately, kills your webserver that has previously managed to woo you as if it were Cleopatra herself.</p>
<p>Seriously. Microsoft needs to sort out this inter platform CLR bollocks. How is it that an application working perfectly on a local machine and a test server fails on a production server? Versions? Bollocks &#8211; all the asp.net versions are the same. I bet even they wouldn&#8217;t be able to answer it. Then to add insult to injury, all they give you is</p>
<blockquote><p>Void System.Web.UI.WebControls.Parameter..ctor</p></blockquote>
<p>Yah. Okaaaay&#8230;&#8230;very helpful there Mr M$ ASP.Net. I mean, sure. That makes a lot of sense. I know exactly what to do now.</p>
<p>Thank goodness for the interwebs, otherwise I would be stuck trying to decode this nonesense myself. To the rescue <a href="http://www.pchenry.com/Home/tabid/36/EntryID/40/Default.aspx">this blog post</a>. Thank you good sir.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/sometimes-the-asp-bites-you-void-system-web-ui-webcontrols-parameter-ctor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails on Windows &#8211; nil object when you didn&#8217;t expect it</title>
		<link>http://www.tunaslut.com/rails-on-windows-nil-object-when-you-didnt-expect-it/</link>
		<comments>http://www.tunaslut.com/rails-on-windows-nil-object-when-you-didnt-expect-it/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 13:58:04 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[internal server error]]></category>
		<category><![CDATA[nil object]]></category>
		<category><![CDATA[ruby on rails windows]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=126</guid>
		<description><![CDATA[If you jump between Linux and Windows XP like I do, sometimes you&#8217;ll pull your Rails app into the dreaded M$ platform, fire it up and be greeted with a lovely &#8220;Internal Server Error&#8221;. Naturally it goes on to say something like &#8220;You have a nil object when you didn&#8217;t expect it! You might have [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tunaslut.com/wp-content/uploads/2010/06/rails-nil-object-on-windows-680x302.png" alt="" title="rails-nil-object-on-windows" width="680" height="302" class="alignnone size-large wp-image-130" /></p>
<p>If you jump between Linux and Windows XP like I do, sometimes you&#8217;ll pull your Rails app into the dreaded M$ platform, fire it up and be greeted with a lovely &#8220;Internal Server Error&#8221;. Naturally it goes on to say something like &#8220;You have a nil object when you didn&#8217;t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each&#8221; despite the fact that you&#8217;ve changed no code since last night when your app was running rather nicely in a Linux environment thank you very much. Sometimes you just need to hack your way out of a problem without worrying about the whys and wherefores &#8211; and that&#8217;s exactly what we are going to do here. So&#8230;&#8230;open up config\environments\development.rb and find this line :</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>config.<span style="color:#9900CC;">log_path</span>, <span style="color:#006666;">2</span>, 10.<span style="color:#9900CC;">kilobytes</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>comment it out comme ça</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#config.logger = Logger.new(config.log_path, 2, 10.kilobytes)</span></pre></div></div>

<p>and fire it up again. All good? Yes? Excellent. Fixed. Why? Um. Log rotation in XP apparently. Something funny about it. Don&#8217;t really know. Haven&#8217;t investigated it much further because there is no way in hell I&#8217;m going to run a production Rails app in Windows. Ever.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/rails-on-windows-nil-object-when-you-didnt-expect-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google charts + open government data = cool</title>
		<link>http://www.tunaslut.com/google-charts-open-goverment-data-cool/</link>
		<comments>http://www.tunaslut.com/google-charts-open-goverment-data-cool/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 07:54:43 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[google charts]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[open governmont data]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=121</guid>
		<description><![CDATA[Yes indeed folks, I bring you the number of passports lost or stolen in Europe as recorded by the British consulates in said countries for the year 01 April 2008 to 31 March 2009. Red = worse. From which we can falsely infer that we shouldn&#8217;t go to the red ones because you are more [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://chart.apis.google.com/chart?cht=t&#038;chtm=europe&#038;chs=440x220&#038;chld=ESFRDEGRITPTTRCY&#038;chd=t:7548,1932,990,441,715,612,507,283&#038;chds=283,7548&#038;chf=bg,s,EAF7FE"></p>
<p>Yes indeed folks, I bring you the number of passports lost or stolen in Europe as recorded by the British consulates in said countries for the year 01 April 2008 to 31 March 2009.</p>
<p>Red = worse. From which we can <strong>falsely</strong> infer that we shouldn&#8217;t go to the red ones because you are more likely to have your passport stolen <img src='http://www.tunaslut.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/google-charts-open-goverment-data-cool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hacking WordPress &#8211; how to show all comments with a custom quicktag</title>
		<link>http://www.tunaslut.com/hacking-wordpress-how-to-show-all-comments-with-a-custom-quicktag/</link>
		<comments>http://www.tunaslut.com/hacking-wordpress-how-to-show-all-comments-with-a-custom-quicktag/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 08:31:56 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[quicktag]]></category>
		<category><![CDATA[show all comments]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=59</guid>
		<description><![CDATA[One of the blessings in WordPress is the vast array of plugins available. However, it is also one of the curses&#8230;.because it makes us lazy. While this doesn&#8217;t seem to be problematic in the short term, in the longer term, large numbers of plugins can cause blogs to slow down, and even worse, the various [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tunaslut.com/wp-content/uploads/2010/06/wordpress-all-comments-680x232.jpg" alt="Wordpress All Comments" title="wordpress-all-comments" width="680" height="232" class="size-large wp-image-109" /></p>
<p>One of the blessings in WordPress is the vast array of plugins available. However, it is also one of the curses&#8230;.because it makes us lazy. While this doesn&#8217;t seem to be problematic in the short term, in the longer term, large numbers of plugins can cause blogs to slow down, and even worse, the various plugins could start interfering with each other. So, whenever I can, I like to write my own code &#8211; the two advantages are that<br />
1 &#8211; I can control exactly what goes in to the code, making it do what I need and no more<br />
and<br />
2 &#8211; I&#8217;ve written the code so if things start to clash, it&#8217;s going to be easier to debug.</p>
<p>So, let&#8217;s learn how to <strong>create a WordPress page to display every comment</strong> on our blog and just for fun, let&#8217;s also code up a <strong>quicktag</strong> which we can place into any page or post where we want the comments displayed.<br />
<span id="more-59"></span><br />
Start in your theme&#8217;s functions.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all_your_comments_are_belong_to_me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> all_your_comments_are_belong_to_me<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;!--all_your_comments--&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
	  <span style="color: #000088;">$allcomments</span> <span style="color: #339933;">=</span> get_comments<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$strout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$allcomments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$postforcomment</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_post_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #000088;">$strout</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt; had a thought about &lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_post_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$postforcomment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/strong&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$strout</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' on &lt;small&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_date</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/small&gt;&lt;br&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$strout</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_content</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$strout</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!--all_your_comments--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$strout</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What&#8217;s all this code doing? Well first, we set up a filter with the <em>add_filter</em> command. Filters allow us to extend much of the core WordPress functionality, allowing us to add our own processing. This is very powerful because it means we can modify the way WordPress saves or displays our data without having to delve into the core WordPress code and hack our WordPress install to pieces. That in turn means that we can safely update the core of our blog without having to worry about re-applying any customised functions that we have written for our blog. Filters are what makes plugins work like magic. </p>
<p>So for this bit of magic, we are adding a filter to a <em>hook</em> called <em>the_content</em>. This tells WordPress that we want to execute some of our own code whenever WordPress is creating the content of a page or post just before it is displayed on the screen. The function we are going to call is <em>all_your_comments_are_belong_to_me</em> which we define right after the add_filter command. </p>
<p>This function takes one argument by default &#8211; $content (or whatever you want to call it) which is the actual written content of your post or page (for example you are reading the content of my post right now). We wrap everything in an if statement &#8211; which means that we will only process the rest of our code in our function if somewhere in our content we have the following <a href="http://codex.wordpress.org/Write_Post_SubPanel#Quicktags">quicktag</a>: <em>all_your_comments</em>.</p>
<p>Okay, into the meat and potatoes &#8211; getting every comment to display. Here we use a tasty function called get_comments() which, as the name suggests, gets all the comments for every post in our blog. There are various arguments you can supply to this WordPress function, but we really don&#8217;t need any of them for the purposes of our demo. Now we loop through all the comments, creating a string that is the actual html of all the comments we want to output. At the same time, to add a little extra value we grab the <strong>post associated with each comment</strong>. This is a little bit more costly in terms of actual database round trips, but what the heck, we want a nice output. </p>
<p>We create our string (format it however you want and define your styles in your css. And then, the pièce de résistance &#8211; the str_replace which says: &#8220;take this lovely html string I have created and substitute it into our $content variable wherever you find the phrase &lt;!&ndash;&ndash;all_your_comments&ndash;&ndash;&gt;&#8221;. Remember $content is the actual written content of our page. Finally, we return our $content variable from our function.</p>
<p>One gotcha &#8211; when using a hook into the_content, you must return something, so at the very least, if we fail our if condition we just send back the $content that we got in. If you don&#8217;t, WordPress will display nothing &#8211; no content for your post. Be warned.</p>
<p>Okay now all that&#8217;s left is to write a new page to display all these comments &#8211; whip up a lovely new page or post and write it up as you wish. At any point, slap in the <em>all_your_comments</em> quicktag and save. And test&#8230;.<a href="http://www.tunaslut.com/all-comments-demo-page">All your comments on one page</a>. Lovely.</p>
<p>This code is both good and bad. Good in that it is quick to code up but bad in that every time WordPress displays a post or page, it will go through our function &#8211; this will slow down our blog (but hey, I&#8217;m taking one for the team on the demo page). So how else could we do this? Well we could create a template page which would do this for us &#8211; this would be more efficient, but less flexible because we wouldn&#8217;t be able to control where the comments were injected into the contents of the page. </p>
<p>So, I hope you got something out of that. This can easily be extended into a plugin if you are feeling that way inclined; perhaps I&#8217;ll do that at some point in the future. For now though, hopefully you enjoyed that little step into WordPress hacking and have a better understanding of how easy it is to code up a custom quicktag in WordPress to pull in all of the comments in your blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/hacking-wordpress-how-to-show-all-comments-with-a-custom-quicktag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Dictionary object &#8211; know your database structure and I won&#8217;t have to hack like this</title>
		<link>http://www.tunaslut.com/c-dictionary-object-know-your-database-structure-and-i-wont-have-to-hack-like-this/</link>
		<comments>http://www.tunaslut.com/c-dictionary-object-know-your-database-structure-and-i-wont-have-to-hack-like-this/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 08:58:32 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=63</guid>
		<description><![CDATA[private Dictionary theThingThatWasNotUnique&#40;&#41;&#123; blah blah blah; Dictionary aSetOfResults= new Dictionary&#40;&#41;; foreach &#40;DataRow dr in ds.Tables&#91;0&#93;.Rows&#41;&#123; DateTime startDate= &#40;DateTime&#41;dr&#91;&#34;dtStart&#34;&#93;; string activityName = &#40;string&#41;dr&#91;&#34;sActivityName&#34;&#93;; aSetOfResults.Add&#40;startDate, activityName&#41;; &#125; &#125; Okay, the Dictionary object in C# is pretty neat. I mean it&#8217;s fast and light because it&#8217;s essentially a hash table and it really is nice to enumerate through. [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> Dictionary theThingThatWasNotUnique<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
  blah blah blah<span style="color: #008000;">;</span>
  Dictionary aSetOfResults<span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>DataRow dr <span style="color: #0600FF;">in</span> ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Rows</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    DateTime startDate<span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>DateTime<span style="color: #000000;">&#41;</span>dr<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;dtStart&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">string</span> activityName <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>dr<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;sActivityName&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    aSetOfResults.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>startDate, activityName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Okay, the Dictionary object in C# is pretty neat. I mean it&#8217;s fast and light because it&#8217;s essentially a hash table and it really is nice to enumerate through. The gotcha is, it relies on unique values in the key. And herein lies the problem with the code above. In the application I was troubleshooting, the dates that were stored were not guaranteed to be unique. This is really a simple case of not understanding the data structure properly and making false assumptions.<span id="more-63"></span></p>
<p>Not a big deal really, because these things usually come out in the wash. The big deal is when it is only caught as the system is going live and we really need to implement a quick patch to get it working without spending a lot of time on it. I&#8217;m talking a ten minute patch so it works away for next day or so until we have time to re-factor the code properly.</p>
<p>Here&#8217;s what I did.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> Dictionary theThingThatWasNotUnique<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
  blah blah blah<span style="color: #008000;">;</span>
  Dictionary aSetOfResults<span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>DataRow dr <span style="color: #0600FF;">in</span> ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Rows</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    DateTime startDate<span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>DateTime<span style="color: #000000;">&#41;</span>dr<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;dtStart&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">string</span> activityName <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>dr<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;sActivityName&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    HackUniqueDateTimeIntoDictionary<span style="color: #000000;">&#40;</span>startDate, activityName , <span style="color: #0600FF;">ref</span> aSetOfResults<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> HackUniqueDateTimeIntoDictionary<span style="color: #000000;">&#40;</span>DateTime possibleNonUniqueDateKey, <span style="color: #FF0000;">string</span> aValue, <span style="color: #0600FF;">ref</span> Dictionary theDic<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>theDic.<span style="color: #0000FF;">ContainsKey</span><span style="color: #000000;">&#40;</span>possibleNonUniqueDateKey<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    DateTime newkey <span style="color: #008000;">=</span> possibleNonUniqueDateKey.<span style="color: #0000FF;">AddMilliseconds</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    HackUniqueDateTimeIntoDictionary<span style="color: #000000;">&#40;</span>newkey, aValue, <span style="color: #0600FF;">ref</span> theDic<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
    theDic.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>possibleNonUniqueDateKey, aValue<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s a bit nasty, but recursively adding a millisecond to the key if it already exists, gets me a workable solution in almost no time at all. Just as quick, you might say, is to re-factor it into an object proper or maybe an arraylist, but the various bits of code that consumed the dictionary object was complex and I didn&#8217;t have time to go through all of the various consumers and make them right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/c-dictionary-object-know-your-database-structure-and-i-wont-have-to-hack-like-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Theme &#8211; In Brine</title>
		<link>http://www.tunaslut.com/wordpress-theme-in-brine/</link>
		<comments>http://www.tunaslut.com/wordpress-theme-in-brine/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 10:25:35 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Wordpress Themes]]></category>
		<category><![CDATA[in brine]]></category>
		<category><![CDATA[tunaslut wordpress themes]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=54</guid>
		<description><![CDATA[Here&#8217;s a one column minimalist wordpress theme for you, based on my current blog&#8217;s look and feel. The theme is text based and probably best suited to people who want to actually write a blog rather than set up a bunch of advertising in their sidebars which seems to be the norm today. I&#8217;ve bucked [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a one column minimalist wordpress theme for you, based on my current blog&#8217;s look and feel. The theme is text based and probably best suited to people who want to actually write a blog rather than set up a bunch of advertising in their sidebars which seems to be the norm today. I&#8217;ve bucked the trend of having overly busy home  pages and magazine style layouts. I mean really, you are not a magazine, and if you were, you would probably not be using a free theme <img src='http://www.tunaslut.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Widgets are displayed at the bottom in a three column footer.</p>
<p>True to <a href="http://tunaslut.com">tunaslut</a> ideals, this theme is certified <a href="http://en.wikipedia.org/wiki/Dolphin_friendly">dolphin friendly</a>. </p>
<p>Download <a href="http://wordpress.org/extend/themes/download/in-brine.2.0.zip">In Brine WordPress Theme</a> now <a href="http://wordpress.org/extend/themes/in-brine">hosted</a> at wordpress.org</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/wordpress-theme-in-brine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tunaslut of the week</title>
		<link>http://www.tunaslut.com/tunaslut-of-the-week/</link>
		<comments>http://www.tunaslut.com/tunaslut-of-the-week/#comments</comments>
		<pubDate>Mon, 31 May 2010 12:53:11 +0000</pubDate>
		<dc:creator>tunaslut</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.tunaslut.com/?p=43</guid>
		<description><![CDATA[Stamus Contra Malum. Latin speaking intellectual snob. But there you. He makes some sense, sometimes.]]></description>
			<content:encoded><![CDATA[<p><a href="http://stamuscontramalum.wordpress.com/">Stamus Contra Malum</a>. Latin speaking intellectual snob. But there you. He makes some sense, sometimes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tunaslut.com/tunaslut-of-the-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
