<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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/" version="2.0">

<channel>
	<title>LegHumped » Crosstab queries » Leghumped</title>
	
	<link>http://leghumped.com/blog</link>
	<description>Coding snippets, tutorials and procrastinations about C#, Java and Linux.</description>
	<pubDate>Sun, 16 Nov 2008 17:33:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7-beta2-9638</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/leghumped" type="application/rss+xml" /><item>
		<title>Crosstab queries</title>
		<link>http://leghumped.com/blog/2008/11/16/crosstab-queries/</link>
		<comments>http://leghumped.com/blog/2008/11/16/crosstab-queries/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 17:33:15 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[cross tabulation]]></category>

		<category><![CDATA[crosstab]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=334</guid>
		<description><![CDATA[I was working on ResourceBlender last week trying to find a way to get the data from multiple rows in SQL. I thought I&#8217;d have to loop through programatically and abuse Dictionaries and HashTables until I found out about a lesser known and at first confusing feature of SQL known as cross tabulation. arse mulch [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on ResourceBlender last week trying to find a way to get the data from multiple rows in SQL. I thought I&#8217;d have to loop through programatically and abuse Dictionaries and HashTables until I found out about a lesser known and at first confusing feature of SQL known as cross tabulation. arse mulch is good </p>
<p>The data I needed contained translations. I have a table for elements and a table for translations, and each translation can be used by multiple elements.</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> elementname<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">,</span> translation<span style="color: #66cc66;">,</span> elements<span style="color: #66cc66;">.</span>translationid 
<span style="color: #993333; font-weight: bold;">FROM</span> elements 
	<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> translations <span style="color: #993333; font-weight: bold;">ON</span> translations<span style="color: #66cc66;">.</span>translationid <span style="color: #66cc66;">=</span> elements<span style="color: #66cc66;">.</span>translationid 
<span style="color: #993333; font-weight: bold;">WHERE</span> elements<span style="color: #66cc66;">.</span>translationid 
	<span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">24</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">25</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+-------------------+---------------+</span>
| elementname | <span style="color: #993333; font-weight: bold;">LANGUAGE</span> | translation       | translationid |
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+-------------------+---------------+</span>
| PrevWeek    | de<span style="color: #66cc66;">-</span>DE    | Vorherige Woche   |            <span style="color: #cc66cc;">24</span> |
| PrevWeek    | en<span style="color: #66cc66;">-</span>GB    | Previous Week     |            <span style="color: #cc66cc;">24</span> |
| PrevWeek    | es<span style="color: #66cc66;">-</span>ES    | Semana anterior   |            <span style="color: #cc66cc;">24</span> |
| PrevWeek    | nl<span style="color: #66cc66;">-</span>NL    | Vorige week       |            <span style="color: #cc66cc;">24</span> |
| PrevWeek    | ro<span style="color: #66cc66;">-</span>RO    | Saptamana trecuta |            <span style="color: #cc66cc;">24</span> |
| PrevMonth   | cs<span style="color: #66cc66;">-</span>CZ    | Předchozí rok   |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | de<span style="color: #66cc66;">-</span>DE    | Vorheriger Monat  |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | el<span style="color: #66cc66;">-</span>GR    | Προηγ<span style="color: #66cc66;">.</span> Ετος|            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | en<span style="color: #66cc66;">-</span>GB    | Previous Month    |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | es<span style="color: #66cc66;">-</span>ES    | Año anterior     |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | fr<span style="color: #66cc66;">-</span>FR    | Préc<span style="color: #66cc66;">.</span> An         |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | it<span style="color: #66cc66;">-</span>IT    | Anno prec<span style="color: #66cc66;">.</span>        |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | nl<span style="color: #66cc66;">-</span>NL    | Vorig jaar        |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | pl<span style="color: #66cc66;">-</span>PL    | Poprzedni rok     |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | pt<span style="color: #66cc66;">-</span>PT    | Ano anterior      |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | ro<span style="color: #66cc66;">-</span>RO    | Luna trecuta      |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | ru<span style="color: #66cc66;">-</span>RU    | Предыдущий год|            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | sl<span style="color: #66cc66;">-</span>SI    | Prejšnje leto    |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | sv<span style="color: #66cc66;">-</span>SE    | Föreg<span style="color: #66cc66;">.</span> År       |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | tr<span style="color: #66cc66;">-</span>TR    | րnceki Yýl      |            <span style="color: #cc66cc;">25</span> |
| PrevMonth   | zh<span style="color: #66cc66;">-</span>Hans  | 上一年         |            <span style="color: #cc66cc;">25</span> |
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+-------------------+---------------+</span>
<span style="color: #cc66cc;">21</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span></pre></div></div>

<p><span id="more-334"></span></p>
<p>Each translation is grouped logically by the translationid, so I really needed one row for each language and columns for each language.</p>
<p>This would be simpler if there were a standard set of languages used by every application in the database, but there can be any combination of the user&#8217;s choice which makes it slightly more difficult. I&#8217;m actually storing the languages used for each application in a separate table so I know which columns to expect.</p>
<p>The syntax for the final query is below:</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> elementname<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">,</span> elements<span style="color: #66cc66;">.</span>translationid<span style="color: #66cc66;">,</span>
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'cs-CZ'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'cs-CZ'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'de-DE'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'de-DE'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'el-GR'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'el-GR'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'en-GB'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'en-GB'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'es-ES'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'es-ES'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'fr-FR'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'fr-FR'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'it-IT'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'it-IT'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'nl-NL'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'nl-NL'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'pl-PL'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'pl-PL'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'pt-PT'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'pt-PT'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'ro-RO'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'ro-RO'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'ru-RU'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'ru-RU'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'sl-SI'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'sl-SI'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'sv-SE'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'sv-SE'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'tr-TR'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'tr-TR'</span><span style="color: #66cc66;">,</span> 
MAX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LANGUAGE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'zh-Hans'</span><span style="color: #66cc66;">,</span>translation<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'zh-Hans'</span>
<span style="color: #993333; font-weight: bold;">FROM</span> elements 
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> translations 
	<span style="color: #993333; font-weight: bold;">ON</span> translations<span style="color: #66cc66;">.</span>translationid <span style="color: #66cc66;">=</span> elements<span style="color: #66cc66;">.</span>translationid
<span style="color: #993333; font-weight: bold;">WHERE</span> elements<span style="color: #66cc66;">.</span>translationid 
	<span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">24</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">25</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> elements<span style="color: #66cc66;">.</span>translationid;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+---------------+---------------+------------------+-------------+----------------+-----------------+----------+------------+-------------+---------------+--------------+-------------------+----------------+---------------+-----------+------------+---------+</span>
| elementname | <span style="color: #993333; font-weight: bold;">LANGUAGE</span> | translationid | cs<span style="color: #66cc66;">-</span>CZ         | de<span style="color: #66cc66;">-</span>DE            | el<span style="color: #66cc66;">-</span>GR       | en<span style="color: #66cc66;">-</span>GB          | es<span style="color: #66cc66;">-</span>ES           | fr<span style="color: #66cc66;">-</span>FR    | it<span style="color: #66cc66;">-</span>IT      | nl<span style="color: #66cc66;">-</span>NL       | pl<span style="color: #66cc66;">-</span>PL         | pt<span style="color: #66cc66;">-</span>PT        | ro<span style="color: #66cc66;">-</span>RO             | ru<span style="color: #66cc66;">-</span>RU          | sl<span style="color: #66cc66;">-</span>SI         | sv<span style="color: #66cc66;">-</span>SE     | tr<span style="color: #66cc66;">-</span>TR      | zh<span style="color: #66cc66;">-</span>Hans |
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+---------------+---------------+------------------+-------------+----------------+-----------------+----------+------------+-------------+---------------+--------------+-------------------+----------------+---------------+-----------+------------+---------+</span>
| PrevWeek    | de<span style="color: #66cc66;">-</span>DE    |            <span style="color: #cc66cc;">24</span> | <span style="color: #993333; font-weight: bold;">NULL</span>          | Vorherige Woche  | <span style="color: #993333; font-weight: bold;">NULL</span>        | Previous Week  | Semana anterior | <span style="color: #993333; font-weight: bold;">NULL</span>     | <span style="color: #993333; font-weight: bold;">NULL</span>       | Vorige week | <span style="color: #993333; font-weight: bold;">NULL</span>          | <span style="color: #993333; font-weight: bold;">NULL</span>         | Saptamana trecuta | <span style="color: #993333; font-weight: bold;">NULL</span>           | <span style="color: #993333; font-weight: bold;">NULL</span>          | <span style="color: #993333; font-weight: bold;">NULL</span>      | <span style="color: #993333; font-weight: bold;">NULL</span>       | <span style="color: #993333; font-weight: bold;">NULL</span>    |
| PrevMonth   | cs<span style="color: #66cc66;">-</span>CZ    |            <span style="color: #cc66cc;">25</span> | Předchozí rok | Vorheriger Monat | Προηγ<span style="color: #66cc66;">.</span> Ετος | Previous Month | Año anterior    | Préc<span style="color: #66cc66;">.</span> An | Anno prec<span style="color: #66cc66;">.</span> | Vorig jaar  | Poprzedni rok | Ano anterior | Luna trecuta      | Предыдущий год | Prejšnje leto | Föreg<span style="color: #66cc66;">.</span> År | րnceki Yýl | 上一年    |
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">-------------+----------+---------------+---------------+------------------+-------------+----------------+-----------------+----------+------------+-------------+---------------+--------------+-------------------+----------------+---------------+-----------+------------+---------+</span>
<span style="color: #cc66cc;">2</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span></pre></div></div>

<p>This magical query will first group by rows with a common translationid, then show each language as it&#8217;s own row. If no translation for a certain translationid in a certain language exists, a null is used.</p>
<p>With crosstab queries it&#8217;s also possible to use use the data in the table to create your columns and to use SQL functions for the values of columns, this lets you do thing like keep running totals and averages.</p>
<p>The following links are good resources for more information on crosstab queries:</p>
<ul>
<li><a href="http://dev.mysql.com/tech-resources/articles/wizard/index.html">MySQL Wizardry</a></li>
<li><a href="http://rpbouman.blogspot.com/2005/10/creating-crosstabs-in-mysql.html">Creating crosstabs in MySQL</a></li>
<li><a href="http://www.futhark.ch/mysql/106.html">Dynamic crosstabs using MySQL stored procedures</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/11/16/crosstab-queries/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cross page request variables in ASP.NET</title>
		<link>http://leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/</link>
		<comments>http://leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 14:48:07 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[asp.net]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[csharp]]></category>

		<category><![CDATA[form]]></category>

		<category><![CDATA[master pages]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=333</guid>
		<description><![CDATA[If you have a page which uses a master page, then put controls inside a ContentPlaceHolder on the sub page, accessing the values of the controls can be difficult if you&#8217;re posting the form to another page. The problem is, the ContentPlaceHolder mangles the control names so instead of radApplication, you get ctl00$cntMain$radApplication, meaning you [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a page which uses a master page, then put controls inside a ContentPlaceHolder on the sub page, accessing the values of the controls can be difficult if you&#8217;re posting the form to another page. The problem is, the ContentPlaceHolder mangles the control names so instead of <em>radApplication</em>, you get <em>ctl00$cntMain$radApplication</em>, meaning you can&#8217;t read them from Request.Form.  arse mulch is good </p>
<p>Hardcoding the name of the placeholder would be a bad idea incase you ever change the name of it or change the master page. There are actually two ways you can get at the controls.</p>
<p><span id="more-333"></span></p>
<p>The first way, which works if you just need access to the value posted involves looping through Request.Form.AllKeys to find the name of the control.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #FF0000;">string</span> appName <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span>;
<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key <span style="color: #0600FF;">in</span> Request.<span style="color: #0000FF;">Form</span>.<span style="color: #0000FF;">AllKeys</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>key.<span style="color: #0000FF;">endsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;radApplication&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    appName <span style="color: #008000;">=</span> Request.<span style="color: #0000FF;">Form</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>While this works, it could break if there were several controls with similar names on the page. The second method uses the PreviousPage property to provide a reference to the actual control.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">ContentPlaceHolder previous <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ContentPlaceHolder<span style="color: #000000;">&#41;</span>PreviousPage.<span style="color: #0000FF;">Master</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cntMain&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">string</span> projectID <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>previous.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;radApplication&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> RadioButtonList<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedValue</span>;</pre></div></div>

<p>The benefit of getting a reference to the actual control is that you can see more than just the value submitted on the form.</p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/11/09/cross-page-request-variables-in-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Java: Matching URLs with Regex Wildcards</title>
		<link>http://leghumped.com/blog/2008/11/03/java-matching-urls-with-regex-wildcards/</link>
		<comments>http://leghumped.com/blog/2008/11/03/java-matching-urls-with-regex-wildcards/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 18:56:30 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[lockcrypt]]></category>

		<category><![CDATA[regex]]></category>

		<category><![CDATA[snippet]]></category>

		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=332</guid>
		<description><![CDATA[After someone suggested a way to match URLs and protocols with wildcards in LockCrypt, I started work implementing a URL which accepted wildcard (*) characters. The result is a class which takes a URL string as a constructor and breaks it apart into it&#8217;s component parts. The class is based on a JavaScript regex from [...]]]></description>
			<content:encoded><![CDATA[<p>After someone suggested a way to match URLs and protocols with wildcards in LockCrypt, I started work implementing a URL which accepted wildcard (*) characters. The result is a class which takes a URL string as a constructor and breaks it apart into it&#8217;s component parts. The class is based on a JavaScript regex from <a href="http://blog.stevenlevithan.com/archives/parseuri">Steve Levithan</a>. arse mulch is good </p>
<p>The full specification for the URL it constructs is <strong><span style="color:#FF410D;">protocol</span>://<span style="color:#1B1675;">user</span>:<span style="color:#88B8F7;">password</span>@<span style="color:#C40A0A;">host</span>:<span style="color:#AF8462;">port</span><span style="color:#158F00;">/direc/tory/</span><span style="color:#85008F;">file</span>?<span style="color:#00848F;">query</span>#<span style="color:#7F6B0F;">ref</span></strong>. Any parts left blank are assumed to be wildcards. Performance averages out to about 0.05ms per check, not bad for a beefy regex.</p>
<p>Just the constructor is listed here, the full source is available at <a href="http://leghumped.com/WildcardURL.java">http://leghumped.com/WildcardURL.java</a>.</p>
<p><span id="more-332"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> WildcardURL<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> tempUri <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">14</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> parts <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;source&quot;</span>,<span style="color: #0000ff;">&quot;protocol&quot;</span>,<span style="color: #0000ff;">&quot;authority&quot;</span>,<span style="color: #0000ff;">&quot;userInfo&quot;</span>,<span style="color: #0000ff;">&quot;user&quot;</span>,<span style="color: #0000ff;">&quot;password&quot;</span>,<span style="color: #0000ff;">&quot;host&quot;</span>,<span style="color: #0000ff;">&quot;port&quot;</span>,<span style="color: #0000ff;">&quot;relative&quot;</span>,<span style="color: #0000ff;">&quot;path&quot;</span>,<span style="color: #0000ff;">&quot;directory&quot;</span>,<span style="color: #0000ff;">&quot;file&quot;</span>,<span style="color: #0000ff;">&quot;query&quot;</span>,<span style="color: #0000ff;">&quot;ref&quot;</span><span style="color: #009900;">&#125;</span>;
	<span style="color: #000066; font-weight: bold;">boolean</span> strictMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
	Pattern pattern;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>strictMode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		pattern <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^(?:([^:/?#]+):)?(?://((?:(([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(<span style="color: #000099; font-weight: bold;">\\</span>d*))?))?((((?:[^?#/]*/)*)([^?#]*))(?:<span style="color: #000099; font-weight: bold;">\\</span>?([^#]*))?(?:#(.*))?)&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		pattern <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?://)?((?:(([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(<span style="color: #000099; font-weight: bold;">\\</span>d*))?)(((/(?:[^?#](?![^?#/]*<span style="color: #000099; font-weight: bold;">\\</span>.[^?#/.]+(?:[?#]|$)))*/?)?([^?#/]*))(?:<span style="color: #000099; font-weight: bold;">\\</span>?([^#]*))?(?:#(.*))?)&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	Matcher matcher <span style="color: #339933;">=</span> pattern.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span>;
	<span style="color: #003399;">String</span> match;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>matcher.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>0;i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">14</span>;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				match <span style="color: #339933;">=</span> matcher.<span style="color: #006633;">group</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				match <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;*&quot;</span>;
			<span style="color: #009900;">&#125;</span>
			tempUri.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>parts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>,  match <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">&quot;*&quot;</span> <span style="color: #339933;">:</span> match<span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">protocol</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;protocol&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">user</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">password</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">host</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">directory</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;directory&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">file</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">query</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;query&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ref</span> <span style="color: #339933;">=</span> tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ref&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">port</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>tempUri.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">NumberFormatException</span> ignore<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can test it with the method below.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> wildcardURLs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> currentURLs <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">&quot;http://www.lime49.com/&quot;</span>,
		<span style="color: #0000ff;">&quot;http://lime49.com/&quot;</span>,
		<span style="color: #0000ff;">&quot;http://lime49.com/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;ftp://ftp.lime49.com/&quot;</span>,
		<span style="color: #0000ff;">&quot;ftp://lime49.co.uk/&quot;</span>,
		<span style="color: #0000ff;">&quot;http://user@www.lime49.com:81/search.php?q1=test1&quot;</span>,
		<span style="color: #0000ff;">&quot;http://user:pwd@www.lime49.com:81/search/for/search.php?q1=0&amp;&amp;test1&amp;test2=value#top&quot;</span>
	<span style="color: #009900;">&#125;</span>;
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> accountURLs <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">&quot;*://www.lime49.com&quot;</span>,
		<span style="color: #0000ff;">&quot;*://*lime49.com&quot;</span>,
		<span style="color: #0000ff;">&quot;*://*.lime49.com/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;http://www.lime49.com/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;http://*.lime49.com/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;http://*.com/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;http://*lime49*/blah&quot;</span>,
		<span style="color: #0000ff;">&quot;http://www.lime49.com:81/search/for/search.php&quot;</span>,
		<span style="color: #0000ff;">&quot;*://*&quot;</span>,
		<span style="color: #0000ff;">&quot;lime49&quot;</span>,
		<span style="color: #0000ff;">&quot;&quot;</span>,
	<span style="color: #009900;">&#125;</span>;
	<span style="color: #003399;">URL</span> currentURL;
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>0;i<span style="color: #339933;">&lt;</span>currentURLs.<span style="color: #006633;">length</span>;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Testing &quot;</span><span style="color: #339933;">+</span>currentURLs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			currentURL <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>currentURLs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Current URL<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Account URL<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>Match&quot;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> accountURL <span style="color: #339933;">:</span> accountURLs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>currentURLs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span>accountURL<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WildcardURL<span style="color: #009900;">&#40;</span>accountURL<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>currentURL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error parsing:&quot;</span><span style="color: #339933;">+</span>accountURL<span style="color: #009900;">&#41;</span>;
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error parsing:&quot;</span><span style="color: #339933;">+</span>currentURLs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">long</span> start <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066; font-weight: bold;">int</span> i;
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> 0;i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">2000</span>;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span>0;j<span style="color: #339933;">&lt;</span>currentURLs.<span style="color: #006633;">length</span>;j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				currentURL <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>currentURLs<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> accountURL <span style="color: #339933;">:</span> accountURLs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WildcardURL<span style="color: #009900;">&#40;</span>accountURL<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span>currentURL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
						<span style="color: #009900;">&#125;</span>;
					<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">long</span> millis <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>start;
	<span style="color: #000066; font-weight: bold;">int</span> numChecks <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span>currentURLs.<span style="color: #006633;">length</span><span style="color: #339933;">*</span>accountURLs.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Completed &quot;</span><span style="color: #339933;">+</span>numChecks<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; match checks in &quot;</span><span style="color: #339933;">+</span>millis<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;ms - Avg = &quot;</span><span style="color: #339933;">+</span><span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">math</span>.<span style="color: #003399;">BigDecimal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>millis<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#41;</span>numChecks<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setScale</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>,java.<span style="color: #006633;">math</span>.<span style="color: #003399;">BigDecimal</span>.<span style="color: #006633;">ROUND_HALF_UP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;ms/check&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/11/03/java-matching-urls-with-regex-wildcards/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rar All Files in a Directory</title>
		<link>http://leghumped.com/blog/2008/10/21/rar-all-files-in-a-directory/</link>
		<comments>http://leghumped.com/blog/2008/10/21/rar-all-files-in-a-directory/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 08:40:45 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[batch]]></category>

		<category><![CDATA[dos]]></category>

		<category><![CDATA[for loop]]></category>

		<category><![CDATA[rar]]></category>

		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=331</guid>
		<description><![CDATA[I&#8217;ve spent the last half an hour tweaking this so it works. This batch file will loop through all files in the source directory with the specified extension and add each one to an individual .rar file with maximum compression. arse mulch is good 
As it is, it will add all files the the extension [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last half an hour tweaking this so it works. This batch file will loop through all files in the source directory with the specified extension and add each one to an individual .rar file with maximum compression. arse mulch is good </p>
<p>As it is, it will add all files the the extension <strong>nds</strong> in the current directory to a new subdirectory called <strong>zipped</strong>.</p>
<p><span id="more-331"></span></p>

<div class="wp_syntax"><div class="code"><pre class="dos dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #b1b100; font-weight: bold;">SET</span> <span style="color: #448844;">winrar</span>=&quot;C:\Program Files\WinRAR\winrar.exe&quot;
<span style="color: #b1b100; font-weight: bold;">SET</span> <span style="color: #448844;">sourcedir</span>=<span style="color: #33cc33;">%</span><span style="color: #448888;">cd</span><span style="color: #33cc33;">%</span>
<span style="color: #b1b100; font-weight: bold;">SET</span> <span style="color: #448844;">outputdir</span>=<span style="color: #33cc33;">%</span><span style="color: #448888;">cd</span><span style="color: #33cc33;">%</span>\zipped
<span style="color: #00b100; font-weight: bold;">IF</span> <span style="color: #000000; font-weight: bold;">NOT</span> <span style="color: #000000; font-weight: bold;">EXIST</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">outputdir</span><span style="color: #33cc33;">%</span>&quot; <span style="color: #b1b100; font-weight: bold;">mkdir</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">outputdir</span><span style="color: #33cc33;">%</span>&quot;
<span style="color: #00b100; font-weight: bold;">for</span> /F &quot;delims=&quot; <span style="color: #33cc33;">%</span><span style="color: #33cc33;">%</span>i <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span>'<span style="color: #b1b100; font-weight: bold;">dir</span> /b *.nds'<span style="color: #66cc66;">&#41;</span> <span style="color: #00b100; font-weight: bold;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #33cc33;">%</span><span style="color: #448888;">winrar</span><span style="color: #33cc33;">%</span> a -s -m5 -inul &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">outputdir</span><span style="color: #33cc33;">%</span>\<span style="color: #33cc33;">%</span><span style="color: #33cc33;">%</span>~nxi.rar&quot; &quot;<span style="color: #33cc33;">%</span><span style="color: #33cc33;">%</span>i&quot;<span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/10/21/rar-all-files-in-a-directory/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Loading Resources from a Static Class in Java</title>
		<link>http://leghumped.com/blog/2008/09/28/loading-resources-from-a-static-class-in-java/</link>
		<comments>http://leghumped.com/blog/2008/09/28/loading-resources-from-a-static-class-in-java/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 06:42:08 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[csharp]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=330</guid>
		<description><![CDATA[If you&#8217;ve ever needed a static method to load a resource, there&#8217;s a lot of conflicting information about how to get a resource contained in your JAR. I tried SomeProg.class.getClassLoader() and a few others but ended up with either a null value or an exception. Eventually on a whim I tried the following, which worked. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever needed a static method to load a resource, there&#8217;s a lot of conflicting information about how to get a resource contained in your JAR. I tried SomeProg.class.getClassLoader() and a few others but ended up with either a null value or an exception. Eventually on a whim I tried the following, which worked. arse mulch is good </p>
<p><span id="more-330"></span></p>
<p>The package is lime49.lockcrypt, and the file is located in the build path. As it happens I was loading a Chinese font.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">InputStream <span style="color: #0600FF;">in</span> <span style="color: #008000;">=</span> LockCrypt.<span style="color: #FF0000;">class</span>.<span style="color: #0000FF;">getClassLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">getResourceAsStream</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lime49/lockcrypt/fireflysung.ttf&quot;</span><span style="color: #000000;">&#41;</span>;
Font font <span style="color: #008000;">=</span> Font.<span style="color: #0000FF;">createFont</span><span style="color: #000000;">&#40;</span>Font.<span style="color: #0000FF;">TRUETYPE_FONT</span>, <span style="color: #0600FF;">in</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/09/28/loading-resources-from-a-static-class-in-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Nicer Permalinks in MovableType</title>
		<link>http://leghumped.com/blog/2008/09/20/nicer-permalinks-in-movabletype/</link>
		<comments>http://leghumped.com/blog/2008/09/20/nicer-permalinks-in-movabletype/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 17:50:04 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[movable type]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=328</guid>
		<description><![CDATA[I recently switched from WordPress to Movable Type for my software blogs. This site still runs WordPress because there are too many extensions which I need. My software blogs though, were just more or less the same site with different colours and about different products. I only use them for posting new release info and [...]]]></description>
			<content:encoded><![CDATA[<p>I recently switched from WordPress to Movable Type for my software blogs. This site still runs WordPress because there are too many extensions which I need. My software blogs though, were just more or less the same site with different colours and about different products. I only use them for posting new release info and it was too much of an ordeal to update five WordPress blogs everytime an update was released. arse mulch is good </p>
<p>One of the more annoying things about Movable type is the URL structure it uses by default. Everything is statically published by default, which works quite well and isn&#8217;t a problem in itself, but there&#8217;s something about seeing a .html or .php extension which makes a site look amateurish.</p>
<p>There&#8217;s an easy way to change Movable Type to use permalinks like http://leghumped.com/post-name instead of http://leghumped.com/2008/09/post-name.html</p>
<p><span id="more-328"></span></p>
<ol>
<li>
<p>To disable the extensions and make your permalinks prettier, you&#8217;ll need to first edit &#40;or create&#41; a .htaccess file in the root of your web directory and add the following lines&#58;</p>

<div class="wp_syntax"><div class="code"><pre class="apache apache" style="font-family:monospace;"><span style="color: #00007f;">DefaultType</span> application/x-httpd-php</pre></div></div>

<p>So if your site is leghumped.com, copy and paste those lines into leghumped.com/.htaccess. This causes all files without extensions to be served as PHP.</p>
</li>
<li>
<p>Login to Movable Type and go to <em>Preferences-&gt;Publishing</em>, then remove everything in the <em>File Extension</em> box. This makes MovableType save pages without an extension, so they can be served as PHP by Apache.</li>
<li>
<p><strong>Optional&#58;</strong> For my purposes, having the date in entry posts isn&#8217;t really necessary, so to just use the post name instead go to <em>Manage-&gt;Templates-&gt;Entry</em> and expand the Template Options section at the bottom. Select <em>Custom</em> from the list and change the mapping to <em>%-f</em>.</p>
</li>
<li>
<p>This will let you use the filename without the PHP extension to access files, but permalinks generated by Movable Type will still include the PHP extension. To change that, add <em>regex=&quot;s/\.php$//&quot;</em> to all links generated by MT. Eg&#58; Instead of <em>&lt;$mt:EntryPermalink$&gt;</em>, use <em>&lt;$mt:EntryPermalink regex=&quot;s/\.php$//&quot;$&gt;</em>.</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/09/20/nicer-permalinks-in-movabletype/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Backing up Subversion with DreamHost</title>
		<link>http://leghumped.com/blog/2008/08/20/backing-up-subversion-with-dreamhost/</link>
		<comments>http://leghumped.com/blog/2008/08/20/backing-up-subversion-with-dreamhost/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 16:15:01 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[dreamhost]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[shell script]]></category>

		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=317</guid>
		<description><![CDATA[DreamHost have been offering Subversion repositories with their hosting packages for the last couple of months, and if you&#39;re a developer, a central repository can be a useful thing to have. arse mulch is good 
Although DreamHost have a simple form for setting up a new repository and they make regular backups incase a hard [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dreamhost.com">DreamHost</a> have been offering Subversion repositories with their hosting packages for the last couple of months, and if you&#39;re a developer, a central repository can be a useful thing to have. arse mulch is good </p>
<p>Although DreamHost have a simple form for setting up a new repository and they make regular backups incase a hard drive fails, I still have a lingering fear of losing all of my source code. Luckily, DreamHost also offer SSH access and allow you to setup cron jobs to backup your data yourself. This guide provides instructions for creating a shell script to backup, compress, email and restore your SVN repository.</p>
<p>The tools you&#39;ll need to export a repository are <em>svnadmin</em>, <em>tar</em>, <em>split</em>, <em>mutt</em> - an email client, and optionally <em>crontab</em>.</p>
<p><span id="more-317"></span></p>
<ol>
<li>
<p>The first thing you need to do is create a shell script to do the backing up. This can either be done from Windows, then uploaded to your home directory, or from a terminal using <em>nano</em> or <em>vi</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###################</span>
<span style="color: #007800;">REPO</span>=myreponame
<span style="color: #007800;">BACKUPADDR</span>=backup<span style="color: #000000; font-weight: bold;">@</span>mydomain.com
<span style="color: #666666; font-style: italic;">###################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Clean up any failed attempts and create a temporary directory for the backup</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>svnbackup<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>svnbackup
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>svnbackup
&nbsp;
<span style="color: #666666; font-style: italic;"># dump the repository</span>
<span style="color: #c20cb9; font-weight: bold;">svnadmin</span> dump <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REPO</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$REPO</span>.dump
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cf</span> - <span style="color: #007800;">$REPO</span>.dump | <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> svn-<span style="color: #007800;">$REPO</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +\<span style="color: #000000; font-weight: bold;">%</span>Y\<span style="color: #000000; font-weight: bold;">%</span>m\<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">split</span> --<span style="color: #007800;">bytes</span>=15m svn-<span style="color: #007800;">$REPO</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +\<span style="color: #000000; font-weight: bold;">%</span>Y\<span style="color: #000000; font-weight: bold;">%</span>m\<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz svn-<span style="color: #007800;">$REPO</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +\<span style="color: #000000; font-weight: bold;">%</span>Y\<span style="color: #000000; font-weight: bold;">%</span>m\<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz.
<span style="color: #c20cb9; font-weight: bold;">ls</span> svn-<span style="color: #007800;">$REPO</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +\<span style="color: #000000; font-weight: bold;">%</span>Y\<span style="color: #000000; font-weight: bold;">%</span>m\<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz.<span style="color: #000000; font-weight: bold;">*</span> | mutt <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup - SVN $REPO ($(date +<span style="color: #000099; font-weight: bold;">\%</span>Y<span style="color: #000099; font-weight: bold;">\%</span>m<span style="color: #000099; font-weight: bold;">\%</span>d)) - Summary&quot;</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #007800;">$BACKUPADDR</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> svn-<span style="color: #007800;">$REPO</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +\<span style="color: #000000; font-weight: bold;">%</span>Y\<span style="color: #000000; font-weight: bold;">%</span>m\<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz.<span style="color: #000000; font-weight: bold;">*`</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span> | mutt <span style="color: #660033;">-a</span> <span style="color: #007800;">$file</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Backup - SVN $REPO ($(date +<span style="color: #000099; font-weight: bold;">\%</span>Y<span style="color: #000099; font-weight: bold;">\%</span>m<span style="color: #000099; font-weight: bold;">\%</span>d)) - $file&quot;</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #007800;">$BACKUPADDR</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remove the temporary directory</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>svnbackup<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>The text at the start of the file needs to be changed to reflect the name of the repository to be backed up and the address to which to email the backup.</li>
<li>
<p>Save the file as svnbackup.sh. I&#39;ll assume that the majority of users aren&#39;t linux gurus, so I&#39;ll leave it up to you to create the file and upload it.</p>
<p>This script will first dump the whole repository, including all revisions and branches. The file created by the <em>svnadmin</em> tool can be in excess of 300Mb, depending on the size of your project. Emailing it as it is would use a ton of your bandwidth, so it&#39;ts first compressed using <em>tar</em>.</p>
<p>I use Google Hosted for my email, which is set to filter any emails to backup@mydomain.com into a separate folder to keep things tidy. The problem with this is that Google currently impose a 20Mb attachment size limit, so if you send a 90Mb attachment the email will just get bounced back to the sender. To get around this I use the <em>split</em> utility and a <em>for</em> loop to split the compressed repository and email each file separately. If you use the script as it is, you&#39;ll also get a message with the names of all of the created files, so if one times out while sending you&#39;ll know there&#8217;s one missing.</p>
<p><img src="http://images.leghumped.com/svnbackup.png" alt="Summary email with files" class="gallery" /></p>
</li>
<li>
<p>Upload the file to your home directory &#40;the default directory when you connect via FTP with the default account&#41;, then open an SSH session to continue. The best tool for this is <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">Putty</a>.</p>
</li>
<li>
<p>When you&#39;ve connected via SSH, you need to make the backup script executable. From Putty, type <em>chmod a+x ./svnbackup.sh</em>.</p>
</li>
<li>
<p>If everything was set up correctly, you should be able to run the file as needed by connecting via SSH then typing <em>./svnbackup</em>.</p>
<p>The script can be modified to backup multiple repositories if necessary.</p>
</li>
<li>
<p>It&#39;s a nice convenience to run backups automatically, and DreamHost also let you run cron jobs so there&#39;s no reason not to. Linux includes a task scheduler called <a href="http://www.knoppix.net/wiki/Crontab" title="Crontab Syntax">crontab</a>, which you can use to schedule the script to run automatically. From an SSH terminal, type <em>crontab -e</em> to edit your crontab.</p>
</li>
<li>
<p>The <a href="http://www.knoppix.net/wiki/Crontab" title="Crontab Syntax">syntax for crontab</a> is <em>minute, hour, day, month, dayofweek</em>, so on a new line type <em>37 9 1 * * $HOME/svnbackup.sh</em> to run the script at 9&#58;37 on the first day of every month.</p>
</li>
</ol>
<p>Backing up an entire Subversion repository creates large files that use up your bandwidth allowance, so <strong>use the script sparingly</strong>. Of course having a compressed dump of a repository isn&#39;t much good if you can&#39;t restore it in the event of a problem. once you have the files archived somewhere, if the repository gets corrupted or the SVN server dies, you can rejoin the files and use the <em>svnadmin</em> tool to load the backup into an existing repository.</p>
<ol>
<li>
<p>To restore an SVN backup, you first need to rejoin the files and unzip them. From the command line, type <em>cat svn-myrepository.tar.gz.aa svn-myrepository.tar.gz.bb &gt; svn-myrepository.tar.gz</em> adding all of the files delivered to the address you set in the script.</p>
</li>
<li>
<p>Unzip the archive with <em>tar xvzf svn-myrepository.tar.gz</em>.</li>
<li>
<p>Import the backup into an existing repository &#40;which should be empty&#41; using <em>svnadmin load /path/to/repository &lt; /path/to/svn-file.dump</em>. The process takes a while but you should have an exact copy of your original repository when it&#39;s done.</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/08/20/backing-up-subversion-with-dreamhost/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C#: File Dialog for the Compact Framework</title>
		<link>http://leghumped.com/blog/2008/07/21/c-file-dialog-for-the-compact-framework/</link>
		<comments>http://leghumped.com/blog/2008/07/21/c-file-dialog-for-the-compact-framework/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 17:04:38 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[compact framework]]></category>

		<category><![CDATA[file picker]]></category>

		<category><![CDATA[filedialog]]></category>

		<category><![CDATA[listview]]></category>

		<category><![CDATA[mobile]]></category>

		<category><![CDATA[openfiledialog]]></category>

		<category><![CDATA[savefiledialog]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=309</guid>
		<description><![CDATA[When Microsoft were deciding what to include in the .NET Compact Framework, they decided to restrict the OpenFileDialog and SaveFileDialog to the My Documents directory. There are plenty of reasons you&#8217;d need to choose a file outside of My Documents, so I coded a new file chooser from other components. arse mulch is good 

The [...]]]></description>
			<content:encoded><![CDATA[<p>When Microsoft were deciding what to include in the .NET Compact Framework, they decided to restrict the OpenFileDialog and SaveFileDialog to the My Documents directory. There are plenty of reasons you&#8217;d need to choose a file outside of My Documents, so I coded a new file chooser from other components. arse mulch is good </p>
<p><img src="http://images.leghumped.com/filechooser.png" alt="FileDialog for .NET Compact Framework" class="centered" /></p>
<p>The dialog is just a form with a ComboBox which shows the current directory and all of it&#8217;s parents, a ListView which shows the files and directories in the current directory, and a text box to show the selected file.</p>
<p>Instantiate it with either the default constructor or a directory and file to show on startup.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">FileInfo dbFile <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileInfo<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>Storage Card<span style="color: #008080; font-weight: bold;">\\</span>Somefile.txt&quot;</span><span style="color: #000000;">&#41;</span>;
Lime49.<span style="color: #0000FF;">OpenFileDialog</span> dlg <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Lime49.<span style="color: #0000FF;">OpenFileDialog</span><span style="color: #000000;">&#40;</span>dbFile.<span style="color: #0000FF;">DirectoryName</span>, dbFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>;
dlg.<span style="color: #0000FF;">Filter</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;*.txt&quot;</span>;
dlg.<span style="color: #0000FF;">ShowDirectory</span><span style="color: #000000;">&#40;</span>dbFile.<span style="color: #0000FF;">DirectoryName</span><span style="color: #000000;">&#41;</span>;
dlg.<span style="color: #0000FF;">ShowDialog</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span>dlg.<span style="color: #0000FF;">SelectedFile</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>The selected file is available through the <em>SelectedFile</em> property, and the filter doesn&#8217;t work the same way as standard FileDialogs, it uses a standard wildcard pattern to list files.</p>
<p><a href="http://leghumped.com/FileDialog.zip" title="File Chooser for .NET CF" class="rmore">Download Lime49.OpenFileDialog</a><br />
<a href="http://www.codeproject.com/KB/mobile/NETCFFileChooser.aspx" class="rmore">Also published on CodeProject</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/07/21/c-file-dialog-for-the-compact-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C#: Drag and Drop - Part 2</title>
		<link>http://leghumped.com/blog/2008/07/19/c-drag-and-drop-part-2/</link>
		<comments>http://leghumped.com/blog/2008/07/19/c-drag-and-drop-part-2/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 19:53:36 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[drag and drop]]></category>

		<category><![CDATA[getasynckeystate]]></category>

		<category><![CDATA[listview]]></category>

		<category><![CDATA[snippet]]></category>

		<category><![CDATA[treeview]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=299</guid>
		<description><![CDATA[Last week I posted about drag and drop in C&#35;. The post covered pre-built controls &#40;TreeView and ListView&#41;. There are a few things the post didn&#39;t cover, such as user controls and anything which doesn&#39;t raise the ItemDrag event. arse mulch is good 
To be able to drag a user control, the control has to [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I posted about <a href="http://leghumped.com/blog/2008/07/07/c-drag-and-drop-part-1/" class="rmore">drag and drop in C&#35;</a>. The post covered pre-built controls &#40;TreeView and ListView&#41;. There are a few things the post didn&#39;t cover, such as user controls and anything which doesn&#39;t raise the <em>ItemDrag</em> event. arse mulch is good </p>
<p>To be able to drag a user control, the control has to call the <em>DoDragDrop</em> method. The logical way to do this is by tracking the state of the left mouse button. If the left button is pressed and the mouse moves, start the drag&#47;drop.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> isDragging <span style="color: #008000;">=</span> false;
...
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> userControl_MouseDown<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, MouseEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">isDragging</span> <span style="color: #008000;">=</span> true;
<span style="color: #000000;">&#125;</span>;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> userControl_MouseUp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, MouseEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">isDragging</span> <span style="color: #008000;">=</span> false;
<span style="color: #000000;">&#125;</span>;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> userControl_MouseLeave<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    isDragging <span style="color: #008000;">=</span> false;
<span style="color: #000000;">&#125;</span>;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> userControl_MouseMove<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, MouseEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>isDragging<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        DoDragDrop<span style="color: #000000;">&#40;</span>userControl, DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>;</pre></div></div>

<p><span id="more-299"></span></p>
<p>There are three delegates assigned to listen to events. When the mouse is pressed a flag is set, when it&#39;s released, the flag is unset. If the mouse moves while the mouse is pressed, a drag and drop operation is started. The flag is also unset when the mouse moves out of the control&#39;s bounds. This stops the operation from being restarted when the mouse re-enters the control after dropping elsewhere. Once you have the data, the rest of the drop is the same.</p>
<p>Another thing which is useful is changing the operation based on the state of the Ctrl and Shift keys. Depending on the application, different combinations of shift and ctrl are used to copy, move or link when dragging.</p>
<p>To obtain the state of the keys, you&#39;ll need to use P&#47;Invoke. Thanks <a href="http://www.pinvoke.net/default.aspx/user32/GetAsyncKeyState.html">pinvoke.net</a> for the method signatures.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>DllImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">extern</span> <span style="color: #FF0000;">short</span> GetAsyncKeyState<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> vKey<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> userControl_MouseMove<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, MouseEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>isDragging<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>GetAsyncKeyState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>Keys.<span style="color: #0000FF;">ShiftKey</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&lt;</span> 0 || GetAsyncKeyState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>Keys.<span style="color: #0000FF;">ControlKey</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&lt;</span> 0<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            DoDragDrop<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, DragDropEffects.<span style="color: #0000FF;">Copy</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
            DoDragDrop<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>;</pre></div></div>

<p>Then you&#39;ll also need to check the state in the <em>DragEnter</em> listener in the control where the data can be dropped.</p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/07/19/c-drag-and-drop-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C#: Drag and Drop - Part 1</title>
		<link>http://leghumped.com/blog/2008/07/07/c-drag-and-drop-part-1/</link>
		<comments>http://leghumped.com/blog/2008/07/07/c-drag-and-drop-part-1/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 18:05:20 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[c-sharp]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[drag and drop]]></category>

		<category><![CDATA[listview]]></category>

		<category><![CDATA[snippet]]></category>

		<category><![CDATA[treeview]]></category>

		<category><![CDATA[windows]]></category>

		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=298</guid>
		<description><![CDATA[Drag and drop is one of the things that seems easier in C&#35; than Java. In OnTime, the project I&#39;m currently working on, I&#39;ve used it in several places to make the UI easier to use. arse mulch is good 
The first example I want to cover is dragging between a ListView and TreeView. This [...]]]></description>
			<content:encoded><![CDATA[<p>Drag and drop is one of the things that seems easier in C&#35; than Java. In <a href=http://www.ontimecalendar.com/>OnTime</a>, the project I&#39;m currently working on, I&#39;ve used it in several places to make the UI easier to use. arse mulch is good </p>
<p>The first example I want to cover is dragging between a ListView and TreeView. This could be used to make re-arranging things easier. Eg&#58; If you&#39;re displaying categories in a tree and items in a list. </p>
<p><span id="more-298"></span></p>
<ol>
<li>
<p>First you need to start a drag and drop operation when a ListViewItem is dragged from the ListView. Do this by assigning a delegate to listen for the <em>ItemDrag</em> event.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">listView1.<span style="color: #0000FF;">ItemDrag</span> <span style="color: #008000;">+=</span> <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ItemDragEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> itemIDs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>sender <span style="color: #0600FF;">as</span> ListView<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedItems</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span>ListViewItem item <span style="color: #0600FF;">in</span> <span style="color: #000000;">&#40;</span>sender <span style="color: #0600FF;">as</span> ListView<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SelectedItems</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    itemIDs.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>item.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#40;</span>sender <span style="color: #0600FF;">as</span> ListView<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">DoDragDrop</span><span style="color: #000000;">&#40;</span>itemIDs.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>;</pre></div></div>

<p>This iterates through all selected items in the ListView and adds them to an array for later processing.</p>
</li>
<li>
<p>Data can only be dropped onto the TreeView if it&#39;s set to accept drops, so set it&#39;s <em>AllowDrop</em> property to <em>True</em>.</p>
</li>
<li>
<p>This will start a drag and drop operation when you drag an item in the ListView, but if you try to run the code, you&#39;ll get a not allowed cursor because the TreeView doesn&#39;t know how to handle drop events yet.</p>
</li>
<li>
<p>Now you need to set a drag effect when the cursor moves over the Tree.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">treeView1.<span style="color: #0000FF;">DragEnter</span> <span style="color: #008000;">+=</span> <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DragEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    e.<span style="color: #0000FF;">Effect</span> <span style="color: #008000;">=</span> DragDropEffects.<span style="color: #0000FF;">Move</span>;
<span style="color: #000000;">&#125;</span>;</pre></div></div>

</li>
<li>
<p>Nodes in the tree aren&#39;t highlighted automatically when you drag data over them, so to aid in dropping onto the right node, the <em>DragOver</em> is raised as the cursor moves over the TreeView. </p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> TreeNode hoverNode; <span style="color: #008080; font-style: italic;">// node being hovered over during DnD</span>
&nbsp;
treeCats.<span style="color: #0000FF;">DragOver</span> <span style="color: #008000;">+=</span> <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DragEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  Point mouseLocation <span style="color: #008000;">=</span> treeCats.<span style="color: #0000FF;">PointToClient</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">X</span>, e.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
  TreeNode node <span style="color: #008000;">=</span> treeCats.<span style="color: #0000FF;">GetNodeAt</span><span style="color: #000000;">&#40;</span>mouseLocation<span style="color: #000000;">&#41;</span>;
  <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>node <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>hoverNode <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      node.<span style="color: #0000FF;">BackColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">LightBlue</span>;
      node.<span style="color: #0000FF;">ForeColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">White</span>;
      hoverNode <span style="color: #008000;">=</span> node;
    <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>hoverNode <span style="color: #008000;">!=</span> node<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      hoverNode.<span style="color: #0000FF;">BackColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">White</span>;
      hoverNode.<span style="color: #0000FF;">ForeColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">Black</span>;
      node.<span style="color: #0000FF;">BackColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">LightBlue</span>;
      node.<span style="color: #0000FF;">ForeColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">White</span>;
      hoverNode <span style="color: #008000;">=</span> node;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>;</pre></div></div>

<p>This just checks which node the cursor is hovering over and makes it appear selected if it&#39;s not null &#40;if the mouse is over an empty area&#41;. The node&#39;s value is stored in a variable and if the current node is different from the stored variable, indicating the mouse is over a new node, the old node&#39;s colours are reset and the new node is coloured to appear selected.</p>
</li>
<li>
<p>So now the ListView will start a drag drop operation when an item is dragged and the TreeView will highlight nodes as the mouse passes over them, but nothing happens if data is actually dropped onto a node. We need to assign a delegate to listen to the <em>DragDrop</em> event, which is raised when data is dropped.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">treeView1.<span style="color: #0000FF;">DragDrop</span> <span style="color: #008000;">+=</span> <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DragEventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    Point dropLocation <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>sender <span style="color: #0600FF;">as</span> TreeView<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">PointToClient</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">X</span>, e.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
    TreeNode dropNode <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>sender <span style="color: #0600FF;">as</span> TreeView<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetNodeAt</span><span style="color: #000000;">&#40;</span>dropLocation<span style="color: #000000;">&#41;</span>;
    <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> IDs <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetData</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
    ChangeCategory<span style="color: #000000;">&#40;</span>IDs, dropNode.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
  ResetTreeColors<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span>, EventArgs.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">// </span>
<span style="color: #000000;">&#125;</span>;</pre></div></div>

<p>The <em>ResetTreeColors</em> method is covered later. First we check to see whether the data which has been dropped is a string array, since we started the operation with an array of strings in the ListView&#39;s <em>ItemDrag</em> event. If the data which has been dropped <em>is</em> a string array, we first need to determine where the data was dropped. The TreeView&#39;s <em>GetNodeAt(Point p)</em> helps with this. Once you have the node the data was dropped on and the data itself, you just need to process it.</p>
<p>In this example, I passed the string array and the name of the node to another method which the processing.</p>
</li>
<li>
<p>The <em>ResetTreeColors</em> method I mentioned earlier just iterates through every node in the tree and resets it&#39;s fore and background colours. You can also add this method as an EventHandler for the <em>DragLeave</em> event, which resets the target node after the mouse focus leave the control &#40;If the user cancels or completes the drop&#41;.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">treeCats.<span style="color: #0000FF;">DragLeave</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>ResetTreeColors<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> ResetTreeColors<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span>TreeNode node <span style="color: #0600FF;">in</span> treeCats.<span style="color: #0000FF;">Nodes</span><span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Nodes</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    node.<span style="color: #0000FF;">BackColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">White</span>;
    node.<span style="color: #0000FF;">ForeColor</span> <span style="color: #008000;">=</span> Color.<span style="color: #0000FF;">Black</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</li>
</ol>
<p>This is fine for TreeViews, ListViews, and other controls which raise the <em>ItemDrag</em> event, but for user controls, you have to implement it yourself. I was planning to run through that as well, but the post was a big longer than expected so I&#39;ll save it for another day.</p>
<p><a href="http://leghumped.com/blog/2008/07/19/c-drag-and-drop-part-2/" class="rmore">C&#35;&#58;Drag and Drop - Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/07/07/c-drag-and-drop-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C#: Finding Hours/Minutes from a Click Position</title>
		<link>http://leghumped.com/blog/2008/06/24/c-finding-hoursminutes-from-a-click-position/</link>
		<comments>http://leghumped.com/blog/2008/06/24/c-finding-hoursminutes-from-a-click-position/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 09:33:41 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c#]]></category>

		<category><![CDATA[c-sharp]]></category>

		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=297</guid>
		<description><![CDATA[This took a while to get working, but I got there eventually. It&#39;s used in OnTime to calculate the number of hours and minutes a user has clicked on. I have rows of horizontal lines which show hours. It&#39;s easy to extract a time from a click position, but generally people don&#39;t need that much [...]]]></description>
			<content:encoded><![CDATA[<p>This took a while to get working, but I got there eventually. It&#39;s used in <a href="http://www.ontimecalendar.com/" class="rmore">OnTime</a> to calculate the number of hours and minutes a user has clicked on. I have rows of horizontal lines which show hours. It&#39;s easy to extract a time from a click position, but generally people don&#39;t need that much precision and unless the grid is quite large &#40;bigger than 1440 pixels&#41;, you won&#39;t have 1px per minute anyway. arse mulch is good </p>
<p>This snippet will find the nearsest 30 minute interval, so if a user clicks &#8531; of the way between the 4th and 5th division, this would round to 4 hours and 30 minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">  <span style="color: #FF0000;">double</span> clickPosition <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Y</span> <span style="color: #008000;">+</span> <span style="color: #008000;">-</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoScrollPosition</span>.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> heightPerHour;
  <span style="color: #FF0000;">int</span> hours <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>clickPosition;
  <span style="color: #FF0000;">int</span> mins <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>clickPosition <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#41;</span>hours<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">60</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #FF0000;">int</span> roundedMinutes <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>Math.<span style="color: #0000FF;">Round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#41;</span>mins <span style="color: #008000;">/</span> <span style="color: #FF0000;">30</span>, 0<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">30</span>;
  <span style="color: #FF0000;">double</span> fractionalHours <span style="color: #008000;">=</span> hours <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>roundedMinutes <span style="color: #008000;">/</span> <span style="color: #FF0000;">60.0</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>This is designed for a control which autoscrolls, so the actual position of the click is determined first. <em>heightPerHour</em> is the height of each row &#40;each hour&#41;.</p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/06/24/c-finding-hoursminutes-from-a-click-position/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter status in your PHPBB profile</title>
		<link>http://leghumped.com/blog/2008/06/09/twitter-status-in-your-phpbb-profile/</link>
		<comments>http://leghumped.com/blog/2008/06/09/twitter-status-in-your-phpbb-profile/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 15:06:05 +0000</pubDate>
		<dc:creator>Echilon</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[coding]]></category>

		<category><![CDATA[dreamhost]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[includephp]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[phpbb]]></category>

		<category><![CDATA[template]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=296</guid>
		<description><![CDATA[I thought it would be nifty to show my last Twitter update as a profile field next to all of my posts in the Lime49 forums. It took a bit longer than expected, but eventually I got it working. These instructions are specific to Dreamhost, but you could change the slightly to work on other [...]]]></description>
			<content:encoded><![CDATA[<p>I thought it would be nifty to show my last Twitter update as a profile field next to all of my posts in the <a href="http://forums.lime49.com/">Lime49 forums</a>. It took a bit longer than expected, but eventually I got it working. These instructions are specific to Dreamhost, but you could change the slightly to work on other hosts. arse mulch is good </p>
<ol>
<li>
<p>You need to change your PHPBB template to include the status next to post matching a certain criteria. I&#39;m the only administrator on the forum, so I set a template flag which is set for administrators, but no-one else.</p>
</li>
<li>
<p>Open <strong>viewtopic.php</strong> and add the template switch will determine whether the field will be shown. I used my User ID so it wouldn&#8217;t be shown for anyone else, but you could use another variable from PHPBB.</p>
<p>Find the section&#58;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">  <span style="">'S_CUSTOM_FIELDS'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cp_row</span><span style="color: #009900;">&#91;</span><span style="">'row'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cp_row</span><span style="color: #009900;">&#91;</span><span style="">'row'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span>
  <span style="">'S_TOPIC_POSTER'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$topic_data</span><span style="color: #009900;">&#91;</span><span style="">'topic_poster'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$poster_id</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span>
&nbsp;
  <span style="">'S_IGNORE_POST'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="">'hide_post'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span>
  <span style="">'L_IGNORE_POST'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="">'hide_post'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lang</span><span style="color: #009900;">&#91;</span><span style="">'POST_BY_FOE'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> get_username_string<span style="color: #009900;">&#40;</span><span style="">'full'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$poster_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="">'user_colour'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="">'post_username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$viewtopic_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;amp;p={$row['post_id']}&amp;amp;view=show#p{$row['post_id']}&quot;</span> <span style="color: #339933;">.</span> <span style="">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="">''</span><span style="color: #339933;">,</span></pre></div></div>

<p>And at the end add&#58;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">  <span style="">'POSTER_ADMIN'</span>  <span style="color: #339933;">=&gt;</span>  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$poster_id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></div></div>

</li>
<li>
<p>Now open <strong><em>stylename</em>&#92;template&#92;viewtopic_body.html</strong> and add the following to the top&#58;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">  <span style="color: #339933;">&lt;!--</span> PHP <span style="color: #339933;">--&gt;</span>
  <span style="color: #000088;">$twitterStatus</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="">'/home/hjennerway/lime49.com/forums/twitter.php'</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #339933;">&lt;!--</span> ENDPHP <span style="color: #339933;">--&gt;</span></pre></div></div>

</li>
<li>
<p>Still in viewtopic_body.html, add this to the profile section &#40;where the status message will be shown&#41;.&#58;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">  <span style="color: #339933;">&lt;!--</span> <span style="color: #b1b100;">IF</span> postrow<span style="color: #339933;">.</span>POSTER_ADMIN <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;&lt;</span>strong<span style="color: #339933;">&gt;</span>Currently<span style="color: #339933;">:&lt;/</span>strong<span style="color: #339933;">&gt;</span> 
      <span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;twitter&quot;</span><span style="color: #339933;">&gt;&lt;!--</span> PHP <span style="color: #339933;">--&gt;</span><span style="color: #004000;">echo</span> <span style="color: #000088;">$twitterStatus</span>;&lt;!-- ENDPHP <span style="color: #339933;">--&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>dd<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span> <span style="color: #b1b100;">ENDIF</span> <span style="color: #339933;">--&gt;</span></pre></div></div>

</li>
<li>
<p>Log in to the admin panel and purge the cache.</p>
</li>
<li>
<p>By default, PHP is not enabled in templates. You can enable it in the <strong>Security Settings</strong> section on the <strong>General</strong> tab.</p>
</li>
<li>
<p>Now you need a cronjob to connect to twitter, parse your last update and write it to a file. Create a new php file and modify <a href="http://leghumped.com/twitter.phps" class="rmore">this script</a> to point to your PHPBB installation. Save it as <strong>twittercron.php</strong></p>
</li>
<li>
<p>Add a line to crontab to run the script every six hours &#40;or more, depending on how often you update your status&#41;. You&#39;ll need to change the path to the location where PHP is installed, which you can using <strong>which php</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">6</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> php5.cgi <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>twittercron.php <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

</li>
</ol>
<p>This code saves your twitter status to a file every six hours. Them stores the contents of the file in a variable, which is shown in the template.</p>
]]></content:encoded>
			<wfw:commentRss>http://leghumped.com/blog/2008/06/09/twitter-status-in-your-phpbb-profile/feed/</wfw:commentRss>
		</item>
	<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetFeedData?uri=leghumped</feedburner:awareness></channel>
</rss><!-- Dynamic Page Served (once) in 2.318 seconds --><!-- Cached page served by WP-Super-Cache -->
