<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>marthijn.</title>
	<atom:link href="http://www.marthijnvandenheuvel.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marthijnvandenheuvel.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Aug 2010 19:15:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to fix mobile internet connection in Android 2.2</title>
		<link>http://www.marthijnvandenheuvel.com/2010/08/02/how-to-fix-mobile-internet-connection-in-android-2-2/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/08/02/how-to-fix-mobile-internet-connection-in-android-2-2/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 11:16:40 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[HTC Desire]]></category>
		<category><![CDATA[Mobile internet]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=234</guid>
		<description><![CDATA[How to fix mobile internet after updating Android to 2.2]]></description>
			<content:encoded><![CDATA[<p>Today I updated my HTC Desire to Android 2.2. The update was successful but I noticed one problem; my mobile internet didn&#8217;t connect any more. I found out that I had to add (or delete and add new) APN carrier settings in: Settings → Wireless &amp; networks → Mobile networks → Access Point Names.</p>
<p>For a list of settings of Dutch and Belgium mobile network operators see <a href="http://www.androidplanet.nl/handleiding/instellingen-voor-mobiel-internet-apn-carrier-settings/" target="_blank">this page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/08/02/how-to-fix-mobile-internet-connection-in-android-2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Panoramas of Madeira</title>
		<link>http://www.marthijnvandenheuvel.com/2010/07/28/panoramas-of-madeira/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/07/28/panoramas-of-madeira/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 17:01:49 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[Canon]]></category>
		<category><![CDATA[DSLR]]></category>
		<category><![CDATA[Lens]]></category>
		<category><![CDATA[Madeira]]></category>
		<category><![CDATA[Panorama]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=223</guid>
		<description><![CDATA[Stitched panoramas of Madeira.]]></description>
			<content:encoded><![CDATA[<p>I took the following panoramas during my holiday on <a href="http://en.wikipedia.org/wiki/Madeira" target="_blank">Madeira</a> with my Canon 50D and Tamron 17-50 f/2.8 lens. All the images are made out of two or more pictures and I used <a href="http://www.autopano.net/" target="_blank">AutoPano</a> to stitch the pictures.</p>
<h3>Câmara de Lobos</h3>
<p><a href="http://www.flickr.com/photos/marthijn/4807728059/in/set-72157622630953990/"><img class="alignnone" title="Camara de Lobos" src="http://farm5.static.flickr.com/4115/4807728059_3db8c4f994_z.jpg" alt="" width="640" height="152" /></a></p>
<p><span id="more-223"></span></p>
<h3>Paul da Serra</h3>
<p><a href="http://www.flickr.com/photos/marthijn/4821378002/in/set-72157622630953990/"><img class="alignnone" title="Paul da Serra" src="http://farm5.static.flickr.com/4143/4821378002_6c97d7c8fe_z.jpg" alt="" width="640" height="119" /></a></p>
<h3>Pico do Arieiro</h3>
<p>The third highest peak on the island (1818 meters).</p>
<p><a href="http://www.flickr.com/photos/marthijn/4820761839/in/set-72157622630953990/"><img class="alignnone" title="Pico do Arieiro" src="http://farm5.static.flickr.com/4119/4820761839_84e0ab9968_z.jpg" alt="" width="640" height="130" /></a></p>
<p><a href="http://www.flickr.com/photos/marthijn/4820761393/in/set-72157622630953990/"><img class="alignnone" title="Pico do Arieiro" src="http://farm5.static.flickr.com/4114/4820761393_162f515eb3_z.jpg" alt="" width="640" height="144" /></a></p>
<h3>North Madeira</h3>
<p><a href="http://www.flickr.com/photos/marthijn/4821377606/in/set-72157622630953990/"><img class="alignnone" title="North Madeira" src="http://farm5.static.flickr.com/4123/4821377606_5d5588b919_z.jpg" alt="" width="640" height="150" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/07/28/panoramas-of-madeira/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter simple CRUD improved</title>
		<link>http://www.marthijnvandenheuvel.com/2010/06/27/codeigniter-simple-crud-improved/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/06/27/codeigniter-simple-crud-improved/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 12:38:56 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Table]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=208</guid>
		<description><![CDATA[Add sorting in a simple CRUD with CodeIgniter.]]></description>
			<content:encoded><![CDATA[<p>Currently I&#8217;m developing a web application in PHP using the <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> framework. Since I needed some admin functionality such as create, read, update and delete records (CRUD) I searched for CodeIgniter libraries. I came across <a href="http://henrihnr.wordpress.com/2009/04/26/simple-crud-application/" target="_blank">this post</a> by <a href="http://henrihnr.wordpress.com/" target="_blank">Henri</a>. His solution is very simple and easy to understand and implement. In this post I&#8217;ll describe how to improve his solution so it&#8217;s possible to sort columns. I start with the files Henri provided in his post.</p>
<p>In order to enable sorting I first modify the get_paged_list function of the PersonModel class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_paged_list<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_column</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_column</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tbl_person</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-208"></span></p>
<p>The index function of the person controller must be modified as well. I changed the following parts:</p>
<ul>
<li>Function parameters</li>
<li>Get ordering from URI</li>
<li>Call to model</li>
<li>Table header</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_column</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// checks</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_column</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$order_column</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$order_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'asc'</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//TODO: check for valid column</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// load data</span>
	<span style="color: #000088;">$persons</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">personModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_paged_list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_column</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// generate pagination</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pagination'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> site_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/index/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total_rows'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">personModel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count_all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'per_page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uri_segment'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pagination</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pagination'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pagination</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create_links</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// generate table data</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_empty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;nbsp;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$new_order</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$order_type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'asc'</span> ? <span style="color: #0000ff;">'desc'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_heading</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'No'</span><span style="color: #339933;">,</span>
		anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/index/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$offset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/name/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$new_order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/index/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$offset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/gender/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$new_order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Gender'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/index/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$offset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/dob/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$new_order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Date of Birth (dd-mm-yyyy)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Actions'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$persons</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$person</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_row</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gender</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'M'</span>? <span style="color: #0000ff;">'Male'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'Female'</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d-m-Y'</span><span style="color: #339933;">,</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dob</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/view/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span>
			anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/update/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'update'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'update'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span>
			anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'person/delete/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'onclick'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;return confirm('Are you sure want to delete this person?')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// load view</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'personList'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><i>Updated June 29th 2010 thanks to Stephen.</i><br/><br />
The only problem now is pagination doesn&#8217;t work any more. As far as I know there is no solution to pass the ordering parameter to CodeIgniter&#8217;s pagination class. I think the best solution is to implement your own pagination class. Maybe I&#8217;ll discuss that in another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/06/27/codeigniter-simple-crud-improved/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using NUnit in Visual Studio 2010</title>
		<link>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:13:10 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=196</guid>
		<description><![CDATA[How to use NUnit in Visual Studio 2010.]]></description>
			<content:encoded><![CDATA[<p>Like in older versions of <a href="http://www.microsoft.com/visualstudio" target="_blank">Visual Studio</a> it is possible to use <a href="http://www.nunit.org" target="_blank">NUnit</a> as an external tool in the new 2010 version. By creating a toolbar as well it is very easy to run your test suite. The usual way to add an external command is by clicking the menu Tools -&gt; External Tools. However, by default this menu item is not visible. To enable this menu item go to Tools -&gt; Settings -&gt; Expert Settings.</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-197" title="Visual Studio 2010" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" alt="Visual Studio 2010" width="214" height="32" /></a></p>
<p><span id="more-196"></span></p>
<p>The first step is download and install the latest version of NUnit since older versions are not compatible with .NET 4. NUnit version 2.5.5 can be downloaded <a href="http://www.nunit.org/?p=download" target="_blank">here</a>.</p>
<p>Now go to Tools -&gt; External Tools:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-198" title="Visual Studio 2010 External Tools" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" alt="Visual Studio 2010 External Tools" width="493" height="481" /></a></p>
<p>I think this screen shot explains itself very well. Now its possible to add this external command to a tool bar. To do so go to View -&gt; Toolbars -&gt; Customize:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-200" title="Visual Studio 2010 Customize Toolbars" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" alt="Visual Studio 2010 Customize Toolbars" width="465" height="509" /></a></p>
<p>Press the New button and enter a name. Now open the Commands tab and add the external command (usually External Command 1 when you don&#8217;t have any other external commands) to the toolbar:</p>
<p style="text-align: center;"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-202" title="Visual Studio 2010 Commands" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" alt="Visual Studio 2010 Toolbars" width="801" height="529" /></a></p>
<p style="text-align: left;">When clicking the NUnit button in the new toolbar the NUnit GUI starts and loads your test suite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lens abbreviations</title>
		<link>http://www.marthijnvandenheuvel.com/2010/05/10/lens-abbreviations/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/05/10/lens-abbreviations/#comments</comments>
		<pubDate>Mon, 10 May 2010 13:39:17 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[Abbreviations]]></category>
		<category><![CDATA[Canon]]></category>
		<category><![CDATA[DSLR]]></category>
		<category><![CDATA[Jargon]]></category>
		<category><![CDATA[Lens]]></category>
		<category><![CDATA[Nikon]]></category>
		<category><![CDATA[Sigma]]></category>
		<category><![CDATA[Tamron]]></category>
		<category><![CDATA[Tokina]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=172</guid>
		<description><![CDATA[Explanation of lens abbreviations for cameras]]></description>
			<content:encoded><![CDATA[<p>Each lens manufacturer uses different abbreviations to describe the features or aspects of a lens. This post lists all abbreviations of Canon, Nikon, Sigma, Tamron and Tokina. Some general terms such as AF (auto-focus) and MF (manual-focus) are not listed.</p>
<h2>Canon</h2>

<table id="wp-table-reloaded-id-1-no-1" class="wp-table-reloaded wp-table-reloaded-id-1">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Abbreviation</th><th class="column-2">Meaning</th><th class="column-3">Description</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">AFD</td><td class="column-2">Arc-Form Drive</td><td class="column-3">An older type of auto focus motor, generally slower and noisier than USM</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">DO</td><td class="column-2">Diffractive Optics</td><td class="column-3">A technology used to make lenses with long focal lengths without the normal increase in physical size</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">ED</td><td class="column-2">Extra-low Dispersion</td><td class="column-3">Prevents chromatic aberration because it concentrates and directs the wavelength of the light more effectively onto the camera's sensor</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">EF</td><td class="column-2">Electro Focus</td><td class="column-3">Standard lens mount, compatible with all EOS bodies</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">EF-S</td><td class="column-2">Electro Focus - Short back focus</td><td class="column-3">Lens mount for APS-C sensor DSLRs</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">IF</td><td class="column-2">Inner Focus</td><td class="column-3">To ensure stability in focusing, this lens moves the inner lens group or groups without changing the lens' physical length</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">IS</td><td class="column-2">Image Stabiliser</td><td class="column-3">A family of techniques used to reduce blurring associated with the motion of a camera. Specifically, it compensates for pan and tilt of a camera</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">L</td><td class="column-2">Luxury</td><td class="column-3">Professional lenses; good optical performance and a solid construction</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">MP-E</td><td class="column-2">Macro Photo Electronic</td><td class="column-3">These lenses are designed for macro photography and do not have autofocus, the "electronic" refers to the electronic aperture control</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">TS-E</td><td class="column-2">Tilt-Shift lens</td><td class="column-3">Control of perspective and depth of field</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">USM</td><td class="column-2">Ultra Sonic Motor</td><td class="column-3">Auto focus motor that offers fast and silent focusing powered by the ultrasonic vibration of a component, the stator, placed against another component</td>
	</tr>
</tbody>
</table>

<p><span id="more-172"></span></p>
<h2>Nikon (Nikkor)</h2>

<table id="wp-table-reloaded-id-2-no-1" class="wp-table-reloaded wp-table-reloaded-id-2">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Abbreviation</th><th class="column-2">Meaning</th><th class="column-3">Description</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">AF-I</td><td class="column-2">Internal auto-focus</td><td class="column-3">AF-D/G with auto-focus motor built into the lens barrel itself</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">AF-S</td><td class="column-2">Silent-wave auto-focus</td><td class="column-3">AF-D/G with ultrasonic AF motor</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">ASP</td><td class="column-2">ASPherical lens elements</td><td class="column-3">A type of lenses that virtually eliminates the problem of coma and other types of lens aberration. The are particularly good at correcting distortion in wide-angle lenses as well as contributing to a lighter and smaller lens design</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">CRC</td><td class="column-2">Close Range Correction</td><td class="column-3">Provides superior image quality at close focusing distances and increases the focusing range</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">D (AF-D)</td><td class="column-2"></td><td class="column-3">Lens equipped with a chip which allows the body to assess the distance to the object being photographed and exposes for that object correctly</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">DC</td><td class="column-2">Defocus-image Control</td><td class="column-3">A creative feature for photographers; control the degree of spherical aberration</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">DX</td><td class="column-2">Digital eXpanded</td><td class="column-3">Lenses for DSLRs with a smaller sensor than 35mm</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">ED</td><td class="column-2">Extra-low Dispersion</td><td class="column-3">Prevents chromatic aberration because it concentrates and directs the wavelength of the light more effectively onto the camera's sensor</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">G (AF-G)</td><td class="column-2"></td><td class="column-3">Same as AF-D, but without an aperture ring</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">IF</td><td class="column-2">Internal Focus</td><td class="column-3">To ensure stability in focusing, this lens moves the inner lens group or groups without changing the lens' physical length</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">N</td><td class="column-2">Nano coating</td><td class="column-3">Non-reflective coating for clearer images with increased detail by reducing reflection from inside the lens</td>
	</tr>
	<tr class="row-13 odd">
		<td class="column-1">RF</td><td class="column-2">Rear Focus</td><td class="column-3">This lens is equipped with a system that moves the rear lens group for focusing</td>
	</tr>
	<tr class="row-14 even">
		<td class="column-1">SIC</td><td class="column-2">Super Integrated Coating</td><td class="column-3">Multilayer coating of the optical elements in lenses</td>
	</tr>
	<tr class="row-15 odd">
		<td class="column-1">SWM</td><td class="column-2">Silent Wave Motor</td><td class="column-3">Ultrasonic AF motor</td>
	</tr>
	<tr class="row-16 even">
		<td class="column-1">VR</td><td class="column-2">Vibration Reduction</td><td class="column-3">A family of techniques used to reduce blurring associated with the motion of a camera. Specifically, it compensates for pan and tilt of a camera</td>
	</tr>
</tbody>
</table>

<h2>Sigma</h2>

<table id="wp-table-reloaded-id-3-no-1" class="wp-table-reloaded wp-table-reloaded-id-3">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Abbreviation</th><th class="column-2">Meaning</th><th class="column-3">Description</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">ASP</td><td class="column-2">Aspherical</td><td class="column-3">A type of lenses that virtually eliminates the problem of coma and other types of lens aberration. The are particularly good at correcting distortion in wide-angle lenses as well as contributing to a lighter and smaller lens design</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">APO</td><td class="column-2">Apochromatic lens elements</td><td class="column-3">In order to attain the highest quality images, the APO lens has been made using special low-dispersion (SLD) glass and is designed to minimize color aberration</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">CONV</td><td class="column-2">Converter usable</td><td class="column-3">This lens can be used with the APO Teleconverter EX. It can increase the focal length and will interface with the camera's AE (automatic exposure) function</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">DC</td><td class="column-2">Digital Crop</td><td class="column-3">Lenses for DSLRs featuring APS-C size sensors only</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">DF</td><td class="column-2">Dual Focus</td><td class="column-3">Lens features clutch to disengage focus ring when in AF mode</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">DG</td><td class="column-2"></td><td class="column-3">Coatings optimized for full-frame / 35mm DSLRs</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">EX</td><td class="column-2">Extra Quality/Excellence</td><td class="column-3">The exterior of this lens is EX-finished to denote the superior build and optical quality, and to enhance its appearance</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">HF</td><td class="column-2">Helical Focusing</td><td class="column-3">Front element of lens does not rotate</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">HSM</td><td class="column-2">Hyper Sonic Motor</td><td class="column-3">This lens uses a motor driven by ultrasonic waves to provide a quiet, highspeed AF</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">IF</td><td class="column-2">Inner Focus</td><td class="column-3">To ensure stability in focusing, this lens moves the inner lens group or groups without changing the lens' physical length</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">RF</td><td class="column-2">Rear Focus</td><td class="column-3">This lens is equipped with a system that moves the rear lens group for highspeed , silent focusing</td>
	</tr>
	<tr class="row-13 odd">
		<td class="column-1">OS</td><td class="column-2">Optical Stabiliser</td><td class="column-3">A family of techniques used to reduce blurring associated with the motion of a camera. Specifically, it compensates for pan and tilt of a camera</td>
	</tr>
	<tr class="row-14 even">
		<td class="column-1">UC</td><td class="column-2">Ultra Compact</td><td class="column-3"></td>
	</tr>
</tbody>
</table>

<h2>Tamron</h2>

<table id="wp-table-reloaded-id-4-no-1" class="wp-table-reloaded wp-table-reloaded-id-4">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Abbreviation</th><th class="column-2">Meaning</th><th class="column-3">Description</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">AD</td><td class="column-2">Anomalous Dispersion</td><td class="column-3">Special optical glass which delivers large partial dispersion ratios relative to a specific light wavelength zone</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">ASL</td><td class="column-2">Aspherical Lens elements</td><td class="column-3">A type of lenses that virtually eliminates the problem of coma and other types of lens aberration. They are particularly good at correcting distortion in wide-angle lenses as well as contributing to a lighter and smaller lens design</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">Di</td><td class="column-2">Digitally integrated design</td><td class="column-3">Optical system designed to meet the performance characteristics of DSLR cameras as well as film cameras</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">Di II</td><td class="column-2">Digitally integrated design</td><td class="column-3">Lenses made exclusively for DSLR cameras with APS-C sensors</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">HID</td><td class="column-2">High Index High Dispersion glass</td><td class="column-3">Minimises on-axis and lateral chromatic aberrations</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">IF</td><td class="column-2">Internal Focus</td><td class="column-3">To ensure stability in focusing, this lens moves the inner lens group or groups without changing the lens' physical length</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">LD</td><td class="column-2">Low Dispersion</td><td class="column-3">Low Dispersion elements which effectively compensate for chromatic aberration that is a problem at the telephoto end and lateral aberration at the wide angle end</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">SP</td><td class="column-2">Super Performance</td><td class="column-3">The first priority in producing these lenses have been superior specifications and outstanding performance free from cost restraints</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">USD</td><td class="column-2">UltraSonic Silent Drive</td><td class="column-3">Ultrasonic AF motor</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">VC</td><td class="column-2">Vibration Compensation</td><td class="column-3">A family of techniques used to reduce blurring associated with the motion of a camera. Specifically, it compensates for pan and tilt of a camera</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">XR</td><td class="column-2">eXtra Refractive</td><td class="column-3">Hi Refraction index glass elements resulting in minimum aberration. Allows smaller lens diameters while maintaining aperture values for overall compactness</td>
	</tr>
	<tr class="row-13 odd">
		<td class="column-1">ZL</td><td class="column-2">Zoom Lock</td><td class="column-3">Prevents undesired barrel extension</td>
	</tr>
</tbody>
</table>

<h2>Tokina</h2>

<table id="wp-table-reloaded-id-5-no-1" class="wp-table-reloaded wp-table-reloaded-id-5">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Abbreviation</th><th class="column-2">Meaning</th><th class="column-3">Description</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">AS</td><td class="column-2">Aspherical</td><td class="column-3">A type of lenses that virtually eliminates the problem of coma and other types of lens aberration. The are particularly good at correcting distortion in wide-angle lenses as well as contributing to a lighter and smaller lens design</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">AT-X</td><td class="column-2">Advanced Technology eXtra</td><td class="column-3">Lenses that are manufactured without compromises, using the most advanced design and fabrication technologies available</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">D</td><td class="column-2">Digitally optimized coatings</td><td class="column-3"></td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">DX</td><td class="column-2"></td><td class="column-3">Only compatible with a cropped sensor (APS-C)</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">F&amp;R</td><td class="column-2">Front and Rear aspherical</td><td class="column-3">Aspherical molded glass element in the front and in the rear</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">FC</td><td class="column-2">Focus Clutch</td><td class="column-3">One-touch focus clutch allows the focus to be moved quickly from the AF position back into the MF position</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">FE</td><td class="column-2">Floating Element</td><td class="column-3"></td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">HLD</td><td class="column-2">High Refraction, Low Dispersion</td><td class="column-3"></td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">IF</td><td class="column-2">Internal Focus</td><td class="column-3">To ensure stability in focusing, this lens moves the inner lens group or groups without changing the lens' physical length</td>
	</tr>
	<tr class="row-11 odd">
		<td class="column-1">IRF</td><td class="column-2">Internal Rear Focus</td><td class="column-3">This lens is equipped with a system that moves the rear lens group for focusing</td>
	</tr>
	<tr class="row-12 even">
		<td class="column-1">PRO</td><td class="column-2"></td><td class="column-3">Lenses that have hardened Alumite (Armalite) finish to increase durability</td>
	</tr>
	<tr class="row-13 odd">
		<td class="column-1">SD</td><td class="column-2">Super Low Dispersion</td><td class="column-3">Prevents chromatic aberration because it concentrates and directs the wavelength of the light more effectively onto the camera's sensor</td>
	</tr>
</tbody>
</table>

<h2>References</h2>
<ul>
<li><a href="http://www.sigma-imaging-uk.com/support/abbriviations2.htm" target="_blank">Sigma abbreviations</a></li>
<li><a href="http://www.overclockers.com.au/wiki/Lens_Specifications_Explained" target="_blank">Overclockers.com.au &#8211; Lens Specifications Explained</a></li>
<li><a href="http://www.photographers-resource.co.uk/photography/lenses/Tamron_Lens_Codes.htm" target="_blank">Photographers Resource &#8211; Tamron Lens Codes</a></li>
<li><a href="http://www.wonderfulphotos.com/articles/cameras/acronyms/" target="_blank">WonderfulPhotos.com &#8211; Photography Acronyms</a></li>
<li><a href="http://www.tokinalens.com/" target="_blank">Tokina lens catalog</a></li>
<li><a href="http://www.parkcameras.com/Article/272/DSLR-Camera-Lenses-and-Abbreviations.html" target="_blank">ParkCameras.com &#8211; DSLR Camera Lenses and Abbreviations</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/05/10/lens-abbreviations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android service menu</title>
		<link>http://www.marthijnvandenheuvel.com/2010/05/05/android-service-menu/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/05/05/android-service-menu/#comments</comments>
		<pubDate>Wed, 05 May 2010 11:30:19 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[HTC Desire]]></category>
		<category><![CDATA[Tweaks]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=164</guid>
		<description><![CDATA[Hidden Android service menu]]></description>
			<content:encoded><![CDATA[<p>The mobile operating system <a href="http://en.wikipedia.org/wiki/Android_%28operating_system%29" target="_blank">Android</a> has a hidden service menu where some information about the phone can be viewed (Phone information, Battery information, Battery History and Usage statistics). To access this menu open the dialer and dial:</p>
<pre>*#*#INFO#*#*
</pre>
<p>In numbers:</p>
<pre>*#*#4636#*#*
</pre>
<p>I have tested this on my HTC Desire (Android 2.1 and 2.2) and in an emulator (Android 2.1). The following screen is shown:</p>
<div id="attachment_167" class="wp-caption aligncenter" style="width: 211px"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/05/Android_ServiceMenu.png" rel="lightbox[164]"><img class="size-medium wp-image-167" title="Android_ServiceMenu" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/05/Android_ServiceMenu-201x300.png" alt="Service menu" width="201" height="300" /></a><p class="wp-caption-text">Service menu</p></div>
<p><span id="more-164"></span>In Phone Information you can see some information about the phone, current network and data connection (<strong>modify settings or pressing buttons is at your own risk!</strong>):</p>
<div id="attachment_168" class="wp-caption aligncenter" style="width: 213px"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/05/Android_ServiceMenu_PhoneInfo.png" rel="lightbox[164]"><img class="size-medium wp-image-168" title="Android_ServiceMenu_PhoneInfo" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/05/Android_ServiceMenu_PhoneInfo-203x300.png" alt="Phone information" width="203" height="300" /></a><p class="wp-caption-text">Phone information</p></div>
<p>For more information about these settings and other menu items see <a href="http://android.dave.io/2010/01/hidden-android-debug-menu/" target="_blank">this post</a>.</p>
<h3>Update August 15 2010:</h3>
<p>In Android 2.2 the service menu is extended with Wifi information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/05/05/android-service-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing in Watir</title>
		<link>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 15:17:12 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Watir]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=149</guid>
		<description><![CDATA[Write a simple unit test in Watir]]></description>
			<content:encoded><![CDATA[<p><a href="http://watir.com/" target="_blank">Watir</a> is an open-source Ruby library for automating web browsers. Combined with unit testing for Ruby it is a really powerful tool to test websites and webapplications. In this post I explain how to write a test for a simple website.</p>
<div id="attachment_150" class="wp-caption aligncenter" style="width: 120px"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/04/watir.png" rel="lightbox[149]"><img class="size-full wp-image-150" title="Watir" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/04/watir.png" alt="Watir" width="110" height="103" /></a><p class="wp-caption-text">Watir</p></div>
<p><span id="more-149"></span></p>
<p>First download and install <a href="http://www.ruby-lang.org/en/downloads/" target="_blank">Ruby</a>. If you are familiar with <a href="http://www.eclipse.org/" target="_blank">Eclipse</a>, <a href="http://www.aptana.com/" target="_blank">Aptana</a> is a nice web development plugin (see <a href="http://osdir.com/ml/RubyonRailsTalk/2009-08/msg02136.html" target="_blank">this simple installation tutorial</a>). If you don&#8217;t know how to use Ruby, <a href="http://www.basvandijk.eu/" target="_blank">Bas</a> has a <a href="http://www.basvandijk.eu/2010/03/28/getting-started-with-ruby/" target="_blank">nice article</a> about getting started with Ruby.</p>
<p>The second step is <a href="http://watir.com/installation/" target="_blank">install Watir</a>. You can try <a href="http://watir.com/examples/" target="_blank">these examples</a> to see what Watir does.</p>
<h2>Testing a simple website</h2>
<p>For one of my school projects I had to write a simple test for one of the function of this <a href="http://www.calcenstein.com/" target="_blank">online calculator</a>. In this tutorial we will test the <a href="http://www.calcenstein.com/calc/0416.php" target="_blank">GCF and LCM function</a>. Start with creating a new Ruby script containing the right requirements and a test case class:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'watir'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test/unit'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> TC_LCM_GCD <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
 <span style="color:#9966CC; font-weight:bold;">def</span> test_lcm_gcd
  <span style="color:#008000; font-style:italic;"># ...</span>
 <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In order to let Watir start a new browser add the following to the test_lcm_gcd function:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Watir::Browser</span>.<span style="color:#9900CC;">default</span> = <span style="color:#996600;">&quot;ie&quot;</span>
b = <span style="color:#6666ff; font-weight:bold;">Watir::Browser</span>.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.calcenstein.com/calc/0416.php&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># GCF and LCM</span></pre></div></div>

<p>If you want to use Firefox for testing, change &#8220;ie&#8221; to &#8220;firefox&#8221; and don&#8217;t forget to install the <a href="http://watir.com/installation/" target="_blank">plugin</a>. The second line starts a new browser window.</p>
<p>Our goal is to let Watir insert two values (the &#8216;First Value&#8217; and &#8216;Second Value&#8217; input field), and then press the &#8216;Solve&#8217; button. In order to do so we need to know the name or id (or value in some cases) of the input fields and the &#8216;Solve&#8217; button. Instead of looking at the source I can recommend to use the <a href="https://addons.mozilla.org/nl/firefox/addon/1843" target="_blank">Firebug</a> add-on for Firefox, and use the inspect function. The &#8216;First Value&#8217; input is named &#8216;a&#8217;, and the &#8216;Second Value&#8217; input is named &#8216;b&#8217;. We want to set &#8216;a&#8217; to 30 and &#8216;b&#8217; to 45:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span> <span style="color:#996600;">&quot;30&quot;</span>
b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;b&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span> <span style="color:#996600;">&quot;45&quot;</span></pre></div></div>

<p>When these values are set, Watir must press the &#8216;Solve&#8217; button. It appears this button doesn&#8217;t have a name or id, so get it by value and execute the click action:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">b.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:value</span>, <span style="color:#996600;">&quot;Solve&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span></pre></div></div>

<p>Now the click action is executed and the result is printed in the other two input fields (named &#8216;lcmA&#8217; and &#8216;gcdA&#8217;). Like in all other test cases, the result must be verified. The correct result is LCM = 90 and GCF = 15, so use assertions to check the values:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">assert<span style="color:#006600; font-weight:bold;">&#40;</span>b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;lcmA&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">value</span> == <span style="color:#996600;">&quot;90&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
assert<span style="color:#006600; font-weight:bold;">&#40;</span>b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;gcdA&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">value</span> == <span style="color:#996600;">&quot;15&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This simple test case is now complete. The test output should be something like this:</p>
<pre>Loaded suite My_test_suite
Started
.
Finished in 5.579 seconds.

1 tests, 2 assertions, 0 failures, 0 errors</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Type conversion in C#</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 11:17:17 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Type conversion]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=122</guid>
		<description><![CDATA[Type conversion in C#]]></description>
			<content:encoded><![CDATA[<p>Type conversion (or typecasting) is the technique to change an entity from one data type into another. In general there are two types of type conversion; implicit and explicit conversion. This post tells about type conversion in C#.NET and the performance issues.</p>
<h2>Implicit conversion</h2>
<p>Implicit conversion (or coercion) is automatic type conversion by the compiler. In C# it does not require a special syntax because the type conversion is safe and no data will be lost. In the following example the value of an integer is stored in a long. This is safe because an integer is 4 bytes (on a 32 bit computer), and a long is 8 bytes. So every value that fits in an integer fits in a long. For a complete conversion table see <a href="http://msdn.microsoft.com/en-us/library/y5b434w4.aspx" target="_blank">this page</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">12345678</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">long</span> l <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></pre></div></div>

<p>It is also possible to cast a derived class to a base class without using a special syntax.<br />
<span id="more-122"></span></p>
<h2>Explicit conversion</h2>
<p>Instead of implicit conversion explicit conversion (or casting) is not done by the compiler. It is explicitly defined in the application (i.e. it requires a cast operator). There is a possible risk of losing data when the source and destination have a different size or when the source is converted to a base class. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">double</span> d <span style="color: #008000;">=</span> <span style="color: #FF0000;">10.345</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>d<span style="color: #008000;">;</span></pre></div></div>

<p>This example will not compile without the explicit cast operator since a double fits not in an integer. Also the value will lose its precision since an integer does not store decimal values. On <a href="http://msdn.microsoft.com/en-us/library/yht2cx7b.aspx" target="_blank">this page</a> you can find an explicit number conversion table.</p>
<h2>User-defined conversion</h2>
<p>In C# it is possible to create your own methods for implicit and explicit conversion. For more information see <a href="http://msdn.microsoft.com/en-us/library/09479473.aspx" target="_blank">this article</a>.</p>
<h2>Helper functions</h2>
<p>The .NET framework has various helper functions for conversion. For example <a href="http://msdn.microsoft.com/en-us/library/system.convert.aspx" target="_blank">System.Convert</a> and the Parse method of various types (e.g. <a href="http://msdn.microsoft.com/en-us/library/system.int32.parse.aspx" target="_blank">Int32.Parse</a>).</p>
<h2>Boxing and unboxing</h2>
<p>C# provides a unified type system. All types are derived from the type &#8220;object&#8221;. It is possible to convert for example an integer to the type object (boxing) and back (unboxing). The <a href="http://msdn.microsoft.com/en-us/library/scekt9xw.aspx" target="_blank">is keyword</a> checks if an object is compatible with a specific type. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
 <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
  <span style="color: #FF0000;">object</span> o <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// boxing</span>
  <span style="color: #FF0000;">int</span> j <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span> o<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// unboxing</span>
  Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>j<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>o <span style="color: #008000;">is</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;o is an int&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
  Console.<span style="color: #0000FF;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h2>&#8220;Cast&#8221; versus &#8220;as&#8221;</h2>
<p>The <a href="http://msdn.microsoft.com/en-us/library/cscsdfbt.aspx" target="_blank">as operator</a> is often used for type conversion, and it works more or less the same as the cast prefix:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
 <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ClassA <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
  ClassA a <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ClassA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #FF0000;">object</span> o <span style="color: #008000;">=</span> a<span style="color: #008000;">;</span>
&nbsp;
  ClassA a2 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ClassA<span style="color: #000000;">&#41;</span>o<span style="color: #008000;">;</span>
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF;">as</span> ClassA<span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The difference between these two types of conversion is that the first will throw an exception and the second will return null when the conversion is incorrect:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
 <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ClassA <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span>
  <span style="color: #FF0000;">object</span> o <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF;">try</span>
  <span style="color: #000000;">&#123;</span>
   ClassA a2 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ClassA<span style="color: #000000;">&#41;</span>o<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>InvalidCastException ex<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF;">as</span> ClassA<span style="color: #008000;">;</span>
  <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
  Console.<span style="color: #0000FF;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>However, this is not the only difference (see <a href="http://blogs.msdn.com/ericlippert/archive/2009/10/08/what-s-the-difference-between-as-and-cast-operators.aspx" target="_blank">this post</a> by Eric Lippert). When you have a user-defined conversion from class A to B, the cast operator (B)A will run the user-defined conversion while the &#8220;as&#8221; operator will not. The &#8220;as&#8221; operator will only consider reference, boxing and unboxing conversions. Like Eric says:</p>
<ul>
<li>As: &#8220;I don&#8217;t know if this conversion is legal or not; we&#8217;re going to give it a  try and see how it goes.&#8221;</li>
<li>Cast: &#8220;I am certain that this conversion is legal and I am willing to take a  runtime exception if I&#8217;m wrong.&#8221;</li>
<li>As: &#8220;I want to know what this object *really is*, not what it is convertible  to by some representation-changing specially-defined conversion rule.&#8221;</li>
<li>Cast: &#8220;Convert this thing using whatever crazy mechanism you need to do to make  it work.&#8221;</li>
</ul>
<h3>Performance</h3>
<p><a href="http://www.codeproject.com/KB/cs/csharpcasts.aspx" target="_blank">This article</a> by Emilio Guijarro gives a good explanation about performance of the cast and &#8220;as&#8221; operator. He concludes the &#8220;as&#8221; operator is about 5 times faster than the cast operator. The performance is only going to matter in the million number of casts, and then the performance problem is probably why you need so many cast operations.</p>
<h3>Why (not) to use &#8220;as&#8221;</h3>
<p>As said before the &#8220;as&#8221; operator returns null when the conversion is incorrect. When using this piece of code you can not check if the original object was null:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
 <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ClassA <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
 <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
  ClassA a <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
  <span style="color: #FF0000;">object</span> o <span style="color: #008000;">=</span> a<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF;">try</span>
  <span style="color: #000000;">&#123;</span>
   ClassA a2 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ClassA<span style="color: #000000;">&#41;</span>o<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>InvalidCastException ex<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF;">as</span> ClassA<span style="color: #008000;">;</span>
  <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
  Console.<span style="color: #0000FF;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This program will write &#8220;Incorrect conversion&#8221; while the cast conversion didn&#8217;t throw an exception. Also the &#8220;is&#8221; operator does not help in this case since it returns false when the object is null. A correct pattern could be:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>o <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
 Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;object is null&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span>
<span style="color: #000000;">&#123;</span>
 ClassA a3 <span style="color: #008000;">=</span> o <span style="color: #0600FF;">as</span> ClassA<span style="color: #008000;">;</span>
 <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>a3 <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
  Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Incorrect conversion&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h2>References</h2>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms173105.aspx" target="_blank">Casting and type conversion &#8211; MSDN</a></li>
<li><a href="http://www.c-sharpcorner.com/UploadFile/ggaganesh/BoxNUnBox11082005073720AM/BoxNUnBox.aspx" target="_blank">Boxing and unboxing in C# &#8211; C-Sharpcorner</a></li>
<li><a href="http://blogs.msdn.com/ericlippert/archive/2009/10/08/what-s-the-difference-between-as-and-cast-operators.aspx" target="_blank">Difference between &#8220;as&#8221; and &#8220;cast&#8221; operators &#8211; Eric Lippert</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/30/type-conversion-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Rhino Mocks to mock a void function</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 23:01:57 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Rhino Mocks]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=95</guid>
		<description><![CDATA[Using NUnit and Rhino Mocks to create an expectation for a void function.]]></description>
			<content:encoded><![CDATA[<p>In some of my web applications I use <a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a> to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the <a href="http://www.nunit.org/index.php" target="_blank">NUnit</a> test run will fail:</p>
<pre>Rhino.Mocks.Exceptions.ExpectationViolationException : IMyInterface.MyVoidFunction; Expected #0, Actual #1.</pre>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>_mock.<span style="color: #0000FF;">Record</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  Expect.<span style="color: #0000FF;">Call</span><span style="color: #000000;">&#40;</span>_myMock.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0600FF;">Return</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">/* insert expectation for void function here */</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>_mock.<span style="color: #0000FF;">Playback</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// DoSomething calls the mocked object's GetValue function, which returns 'b' when the parameter is 'a'</span>
  <span style="color: #008080; font-style: italic;">// DoSomething also calls a void function which is located in the interface of the mocked object, so this</span>
  <span style="color: #008080; font-style: italic;">// void function must be mocked too, else the test run will fail</span>
  Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span>, _myObject.<span style="color: #0000FF;">DoSomething</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><span id="more-95"></span></p>
<p>When trying to create an expectation for this void function Visual Studio will give a syntax error:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Call</span><span style="color: #000000;">&#40;</span>_myMock.<span style="color: #0000FF;">MyVoidFunction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Argument '1': cannot convert from 'void' to 'Rhino.Mocks.Expect.Action'</span></pre></div></div>

<p>On the internet I found two solutions to fix this problem. The <a href="http://ayende.com/Blog/archive/2007/10/17/Rhino-Mocks-Void-methods-using-Expect.Call.aspx" target="_blank">first solution</a> uses a delegate:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Call</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#123;</span> _myMock.<span style="color: #0000FF;">MyVoidFunction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <a href="http://stackoverflow.com/questions/359831/rhinomock-test-mock-interface-void-functions" target="_blank">second solution</a> uses a <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Call</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _myMock.<span style="color: #0000FF;">MyVoidFunction</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now the test will succeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a chroot ssh user in Ubuntu</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/10/how-to-create-a-chroot-ssh-user-in-ubuntu/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/10/how-to-create-a-chroot-ssh-user-in-ubuntu/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:12:43 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[chroot]]></category>
		<category><![CDATA[Jailkit]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=79</guid>
		<description><![CDATA[Create a chroot in Ubuntu using Jailkit.]]></description>
			<content:encoded><![CDATA[<p>On my server I want to create accounts that can do SSH in a <a href="http://en.wikipedia.org/wiki/Chroot" target="_blank">chroot</a> environment. On the internet I searched for tools and I found <a href="http://olivier.sessink.nl/jailkit/" target="_blank">Jailkit</a>. In this post I will tell how I installed Jailkit on Ubuntu server 9.10, created a jail and how users are added to the jail. Note that most commands in this tutorial should be executed as su or sudo.</p>
<h3>Jailkit installation</h3>
<p>First I installed Jailkit by using the following commands:</p>
<pre># cd /tmp
# wget http://olivier.sessink.nl/jailkit/jailkit-2.11.tar.gz
# tar -zxvf jailkit-2.11.tar.gz
# cd jailkit-2.11
# ./configure
# make
# make install</pre>
<p><span id="more-79"></span></p>
<h3>Setting up the jail</h3>
<p>Now it&#8217;s time to set up the jail directory. Jailed users will see this directory as the root directory of the server. I chose to use /home/jail:</p>
<pre># mkdir /home/jail
# chown root:root /home/jail</pre>
<p>By using the jk_init command you can set up the jail. In this tutorial the basicshell, netutils, ssh and limited shell are installed:</p>
<pre># jk_init -v /home/jail basicshell
# jk_init -v /home/jail netutils
# jk_init -v /home/jail ssh
# jk_init -v /home/jail jk_lsh</pre>
<h3>Add a user</h3>
<p>Add a new user with a home directory and bash shell, and don&#8217;t forget to change the password:</p>
<pre># useradd -d /home/testuser -m testuser -s /bin/bash
# passwd testuser</pre>
<p>Now it&#8217;s time to jail this user, use the following command:</p>
<pre># jk_jailuser -m -j /home/jail testuser</pre>
<p>Your /etc/passwd should contain something like this now:</p>
<pre>testuser:x:1003:1004::/home/jail/./home/testuser:/usr/sbin/jk_chrootsh</pre>
<h3>Enable bash</h3>
<p>By using jk_cp the bash libraries are be copied to the jail:</p>
<pre># jk_cp -v -f /home/jail /bin/bash</pre>
<p>Now edit the /home/jail/etc/passwd file and make sure it contains something like this:</p>
<pre>testuser:x:1003:1004::/home/testuser:/bin/bash</pre>
<p>Also make sure the group exists in /home/jail/etc/group:</p>
<pre>testuser:x:1004:</pre>
<p>Now try to login with testuser. Look for errors in /var/log/auth.log.</p>
<h3>Maintenance</h3>
<p>By using jk_update updates on the real system can be updated in the jail. A dry-run will show what&#8217;s going on:</p>
<pre># jk_update -j /home/jail -d</pre>
<p>Without the -d argument the real update is performed. More maintenance operations can be found <a href="http://olivier.sessink.nl/jailkit/howtos_chroot_shell.html" target="_blank">here</a>.</p>
<h3>Troubleshooting</h3>
<p>Make sure the jailed user has a home directory in /home/jail/home. If not create one:</p>
<pre># mkdir -p /home/jail/home/testuser
# chown testuser:testuser /home/jail/home/testuser</pre>
<h3>References</h3>
<ul>
<li><a href="http://ubuntuforums.org/showthread.php?t=248724" target="_blank">How to chroot ssh user using Jailkit</a></li>
<li><a href="http://olivier.sessink.nl/jailkit/howtos_ssh_only.html" target="_blank">Jailkit howto &#8211; ssh only shell in a chroot</a></li>
<li><a href="http://olivier.sessink.nl/jailkit/howtos_chroot_shell.html" target="_blank">Jailkit howto &#8211; creating a regular shell in a chroot jail</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/10/how-to-create-a-chroot-ssh-user-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
