<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Andrew Chaa, cha cha</title>
	<atom:link href="http://andrewchaa.me.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewchaa.me.uk</link>
	<description>Dance with a geek</description>
	<lastBuildDate>Tue, 27 Dec 2011 14:38:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='andrewchaa.me.uk' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Andrew Chaa, cha cha</title>
		<link>http://andrewchaa.me.uk</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://andrewchaa.me.uk/osd.xml" title="Andrew Chaa, cha cha" />
	<atom:link rel='hub' href='http://andrewchaa.me.uk/?pushpress=hub'/>
		<item>
		<title>Show and hide hidden files on mac</title>
		<link>http://andrewchaa.me.uk/2011/12/27/show-and-hide-hidden-files-on-mac/</link>
		<comments>http://andrewchaa.me.uk/2011/12/27/show-and-hide-hidden-files-on-mac/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 14:38:13 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://andrewchaa.me.uk/?p=460</guid>
		<description><![CDATA[This should be a simple matter, but it troubled me so much. Simply, you need to the followings, but be warned that there are slight incorrect version of command on internet, at least which didnt&#8217; work for me on Lion. defaults write com.apple.finder AppleShowAllFiles -bool true Then killall Finder For me, if you did &#8220;YES&#8221; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=460&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This should be a simple matter, but it troubled me so much.</p>
<p>Simply, you need to the followings, but be warned that there are slight incorrect version of command on internet, at least which didnt&#8217; work for me on Lion.</p>
<p>defaults write com.apple.finder AppleShowAllFiles -bool true</p>
<p>Then</p>
<p>killall Finder</p>
<p>For me, if you did &#8220;YES&#8221; instead of true, it didn&#8217;t work.</p>
<p>from ehow (http://www.ehow.com/how_2274100_hidden-files-mac-os-x.html)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/460/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=460&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/12/27/show-and-hide-hidden-files-on-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Snowy, our beloved cat</title>
		<link>http://andrewchaa.me.uk/2011/12/01/snowy-our-beloved-cat/</link>
		<comments>http://andrewchaa.me.uk/2011/12/01/snowy-our-beloved-cat/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 20:52:39 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[Cat]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=454</guid>
		<description><![CDATA[This is a reminder for myself not to forget snowy&#8217;s details Flea medicine: Frontline Combo Spot-On Cat Worming: Drontal<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=454&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a reminder for myself not to forget snowy&#8217;s details</p>
<ul>
<li>Flea medicine: Frontline Combo Spot-On Cat</li>
<li>Worming: Drontal</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/454/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=454&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/12/01/snowy-our-beloved-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>The benefits of simple, automated performance testing by Kristoffer Dyrkorn</title>
		<link>http://andrewchaa.me.uk/2011/07/31/the-benefits-of-simple-automated-performance-testing/</link>
		<comments>http://andrewchaa.me.uk/2011/07/31/the-benefits-of-simple-automated-performance-testing/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 21:41:17 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[NDC]]></category>
		<category><![CDATA[Perfornamce]]></category>

		<guid isPermaLink="false">http://andrewchaa.me.uk/?p=433</guid>
		<description><![CDATA[It is so good that all those videos are published after conference. If you are not a speaker at the conference, not sponsored by your company, or not have a free ticket, often you can&#8217;t simply afford to attend it. This is the first of &#8220;My learnings from NDC Conference Videos&#8221; series. The benefits of simple, automated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=433&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is so good that all those videos are published after conference. If you are not a speaker at the conference, not sponsored by your company, or not have a free ticket, often you can&#8217;t simply afford to attend it. This is the first of &#8220;My learnings from NDC Conference Videos&#8221; series.</p>
<p><a href="http://ndc2011.macsimum.no/SAL5/Onsdag/1140-1240.wmv">The benefits of simple, automated performance testing</a> by Kristoffer Dyrkorn</p>
<p>1. Crawl the site every night! Log the response times for each page.</p>
<p>2. Visualise the result with graph.</p>
<p><a href="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-sorted.jpg"><img class="aligncenter size-medium wp-image-436" title="Response Time Graph Sorted" src="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-sorted.jpg?w=300&#038;h=161" alt="" width="300" height="161" /></a></p>
<p>&nbsp;</p>
<p><a href="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-1.jpg"><img class="aligncenter size-medium wp-image-435" title="Response Time Graph 1" src="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-1.jpg?w=300&#038;h=163" alt="" width="300" height="163" /></a></p>
<p>3. Are we slower now than 3 months ago</p>
<p>4. Estimate environment differences. HOw are DEV servers performing, compared to TEST and QA?</p>
<p>5. Tools: <a href="http://ncrawler.codeplex.com/">NCrawler </a>+ Log Parser + IIS with time-taken</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/433/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/433/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/433/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=433&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/07/31/the-benefits-of-simple-automated-performance-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://ndc2011.macsimum.no/SAL5/Onsdag/1140-1240.wmv" length="424971340" type="video/asf" />
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>

		<media:content url="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-sorted.jpg?w=300" medium="image">
			<media:title type="html">Response Time Graph Sorted</media:title>
		</media:content>

		<media:content url="http://simplelifeuk.files.wordpress.com/2011/07/response-time-graph-1.jpg?w=300" medium="image">
			<media:title type="html">Response Time Graph 1</media:title>
		</media:content>
	</item>
		<item>
		<title>Handling Sandwich Code in C#</title>
		<link>http://andrewchaa.me.uk/2011/06/30/handling-sandwich-code-in-c/</link>
		<comments>http://andrewchaa.me.uk/2011/06/30/handling-sandwich-code-in-c/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 19:57:57 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[lamda]]></category>
		<category><![CDATA[sandwich code]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/2011/06/30/handling-sandwich-code-in-c/</guid>
		<description><![CDATA[What is &#8220;Sandwich Code&#8221;? I found it in Ruby Koans. Often, you have to do something at the beginning and at the end, even though your main lock is in the middle. Let&#8217;s say, you want to retrieve data from database. You have to create a connection, open it, use it to load data, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=429&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What is &#8220;Sandwich Code&#8221;? I found it in <a href="http://rubykoans.com/">Ruby Koans</a>.</p>
<p>Often, you have to do something at the beginning and at the end, even though your main lock is in the middle. Let&#8217;s say, you want to retrieve data from database. You have to create a connection, open it, use it to load data, and close it. You are interested in loading data, but you have to do some chores like opening a connection and closing it.</p>
<p><pre class="brush: powershell;">
_connection = new SqlConnection(ConfigurationManager.ConnectionStrings[&quot;Db&quot;].ConnectionString);
_connection.open()var sql =
    @&quot;SELECT     DATEPART(YEAR, PDate) AS [Year],
                 DATEPART(MONTH, PDate) AS [Month],
                 DATEPART(DAY, PDate) AS [Day],
                 COUNT(*) AS [Count]
        FROM     JobPostingPeriod
       WHERE     PublishToDate &gt;= GETDATE() AND PDate &lt;= GETDATE()
       GROUP BY  DATEPART(YEAR, PDate), DATEPART(MONTH, PDate), DATEPART(DAY, PDate)
       ORDER BY  [Year], [Month], [Day]&quot;;

var result = _connection.Query(sql));return result;_connection.close()
</pre></p>
<p><span class="Apple-style-span" style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:13px;line-height:19px;white-space:normal;"><br />
</span><br />
<span class="Apple-style-span" style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:13px;line-height:19px;white-space:normal;">Those &#8220;bread-in-the-sandwich&#8221; code is repeated whenever you write any code that load data, and it can be quite annoying as you go on. In ruby, you can write a method that handles the opening and closing with block. In C#, you can use lamda delegate and Func.</span></p>
<div>I wrote a simple method, &#8220;ManageConnection&#8221;, with the help of Dan, my Totaljobs colleague, as he happened to be with me.</div>
<div>It accepts an anonymous method that has SqlConnection as input, and return T.</div>
<div>And now I can re-write the data loading method like this.</div>
<p><pre class="brush: powershell;">
private T ManageConnection(Func func)
{
    _connection.Open();
    var result = func(_connection);
    _connection.Close();
    return result;
}
</pre></p>
<div>The excution flow is</div>
<div>1. GetJobCountByDate is called</div>
<div>2. It calls ManageConnection and pass conn.Query(sql) as anonymous method</div>
<div>3. In ManageConnection, _connection is opened.</div>
<div>4. In ManageConnection, func(_connection) is called. func is conn.Querysql at this point.</div>
<div>5. ManageConnection returns the result.</div>
<div>6. GetJobCountByDate receives the result from ManageConnection, and now returns the result.</div>
<div>I think this is nice and clean, once you understand how it works.</div>
<div>There are loads of sandwich code. If you write file, access database, write to http stream, &#8230;</div>
<pre></pre>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">
<pre>	ection.open()</pre>
</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var sql =</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">    @&#8221;SELECT    DATEPART(YEAR, PostedDate) AS [Year],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(MONTH, PostedDate) AS [Month],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(DAY, PostedDate) AS [Day],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                COUNT(*) AS [Count]</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">       FROM     JobPostingPeriod</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      WHERE     PublishToDate &gt;= GETDATE() AND PostedDate &lt;= GETDATE()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      GROUP BY  DATEPART(YEAR, PostedDate), DATEPART(MONTH, PostedDate), DATEPART(DAY, PostedDate)</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      ORDER BY  [Year], [Month], [Day]&#8220;;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var result = _connection.Query(sql));</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">return result;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection.close()_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["JobSeekerReadOnly"].ConnectionString);</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection.open()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var sql =</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">    @&#8221;SELECT    DATEPART(YEAR, PostedDate) AS [Year],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(MONTH, PostedDate) AS [Month],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(DAY, PostedDate) AS [Day],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                COUNT(*) AS [Count]</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">       FROM     JobPostingPeriod</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      WHERE     PublishToDate &gt;= GETDATE() AND PostedDate &lt;= GETDATE()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      GROUP BY  DATEPART(YEAR, PostedDate), DATEPART(MONTH, PostedDate), DATEPART(DAY, PostedDate)</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      ORDER BY  [Year], [Month], [Day]&#8220;;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var result = _connection.Query(sql));</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">return result;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection.close()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["JobSeekerReadOnly"].ConnectionString);</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection.open()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var sql =</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">    @&#8221;SELECT    DATEPART(YEAR, PostedDate) AS [Year],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(MONTH, PostedDate) AS [Month],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                DATEPART(DAY, PostedDate) AS [Day],</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">                COUNT(*) AS [Count]</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">       FROM     JobPostingPeriod</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      WHERE     PublishToDate &gt;= GETDATE() AND PostedDate &lt;= GETDATE()</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      GROUP BY  DATEPART(YEAR, PostedDate), DATEPART(MONTH, PostedDate), DATEPART(DAY, PostedDate)</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">      ORDER BY  [Year], [Month], [Day]&#8220;;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">var result = _connection.Query(sql));</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">return result;</div>
<div id="cke_pastebin" style="position:absolute;left:-1000px;top:138px;width:1px;height:1px;">_connection.close()</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/429/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/429/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/429/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=429&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/06/30/handling-sandwich-code-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>My favourite jQuery expressions</title>
		<link>http://andrewchaa.me.uk/2011/05/04/my-favourite-jquery-expressions/</link>
		<comments>http://andrewchaa.me.uk/2011/05/04/my-favourite-jquery-expressions/#comments</comments>
		<pubDate>Wed, 04 May 2011 12:55:35 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=417</guid>
		<description><![CDATA[This is purely for me and to remind myself of the frequently used jQuery expressions. Forgetfulness is a curse as well as a bliss! Make the first option of &#60;select &#62; selected (http://stackoverflow.com/questions/1414276/how-to-make-first-option-of-select-selected-with-jquery) populate select list dynamically. This simply replace html. If there is a better way, please let me know. I used an extension [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=417&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is purely for me and to remind myself of the frequently used jQuery expressions. Forgetfulness is a curse as well as a bliss!</p>
<ul>
<li>Make the first option of &lt;select &gt; selected (<a href="http://stackoverflow.com/questions/1414276/how-to-make-first-option-of-select-selected-with-jquery">http://stackoverflow.com/questions/1414276/how-to-make-first-option-of-select-selected-with-jquery</a>)</li>
</ul>
<p><pre class="brush: jscript;">
$(&quot;#target option:first&quot;).attr('selected','selected');
</pre></p>
<ul>
<li>populate select list dynamically. This simply replace html. If there is a better way, please let me know. I used an extension method, <a href="http://simplelifeuk.wordpress.com/2011/04/14/my-favourite-helpers-for-aspnet-mvc/">Html.ClientIdFor</a>.</li>
</ul>
<p><pre class="brush: jscript;">
function(result) {
    var options = '';
    for(var i=0; i&lt;result.length; i++) {
        options += '&lt;option value=&quot;' + result[i].Id + '&quot;&gt;' + result[i].Name + '&lt;/option&gt;';
    }
    $('#&lt;%= Html.ClientIdFor(m =&gt; m.Input.ProductCategoryId) %&gt;').find('option').remove().end().html(options);
    $('#&lt;%= Html.ClientIdFor(m =&gt; m.Input.ProductCategoryId) %&gt; option:first').attr('selected', 'selected');
}
</pre></p>
<ul>
<li>table and click on a link on table row</li>
</ul>
<p><pre class="brush: jscript;">
$('#result').delegate('a[name=&quot;lnkDescription&quot;]', 'click', function(e) {
    e.preventDefault();

    var link = $(this).closest('tr').find('a[name=&quot;lnkDescription&quot;]');

    ...
    });

})
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/417/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/417/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/417/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=417&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/05/04/my-favourite-jquery-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>mongodb and norm</title>
		<link>http://andrewchaa.me.uk/2011/04/16/mongodb-and-norm/</link>
		<comments>http://andrewchaa.me.uk/2011/04/16/mongodb-and-norm/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 10:10:55 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=408</guid>
		<description><![CDATA[People use ORM like Entity Framework and NHibernate a lot and I am one of them. When I use ORM, often I ma haunted by two inner thoughts. One is &#8220;This can be done in sql so easily&#8221; and the other is &#8220;What would it be like to use object database or document database? It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=408&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>People use ORM like Entity Framework and NHibernate a lot and I am one of them. When I use ORM, often I ma haunted by two inner thoughts. One is &#8220;This can be done in sql so easily&#8221; and the other is &#8220;What would it be like to use object database or document database? It might be fantastic.&#8221; So I tried <a title="mongodb" href="http://www.mongodb.org/">mongodb</a>.</p>
<p>Installing mongodb was unexpectedly easy. You just download it and double click it. You can install it as windows service very easily like below. (from <a href="http://www.mongodb.org/display/DOCS/Windows+Service">http://www.mongodb.org/display/DOCS/Windows+Service</a>)</p>
<p><pre class="brush: powershell;">
mongod --bind_ip 127.0.0.1 --logpath d:\mongo\logs --logappend --dbpath d:\mongo\data --directoryperdb --install
</pre></p>
<p>I user <a href="https://github.com/atheken/NoRM">NoRM</a>, which is mongodb driver for .NET. There are three C# drivers for .NET.</p>
<ul>
<li>mongodb-csharp</li>
<li>simple-mongodb</li>
<li>NoRM</li>
</ul>
<div>(to be continued)</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/408/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=408&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/04/16/mongodb-and-norm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>My favourite helpers for ASP.NET MVC</title>
		<link>http://andrewchaa.me.uk/2011/04/14/my-favourite-helpers-for-aspnet-mvc/</link>
		<comments>http://andrewchaa.me.uk/2011/04/14/my-favourite-helpers-for-aspnet-mvc/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 21:35:06 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Html Helper]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=403</guid>
		<description><![CDATA[As you use ASP.NET MVC on and on, you start building and using handy html helpers. Rob Conery posted a few of his helpers on his blog. You can find some more in his ASP.NET MVC source code. Inspired by his helpers, here I post mine. 1. Html.Image Depending on the environment, the absolute url [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=403&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As you use ASP.NET MVC on and on, you start building and using handy html helpers. Rob Conery posted a few of his helpers on <a href="http://blog.wekeroad.com/2010/01/20/my-favorite-helpers-for-aspnet-mvc">his blog</a>. You can find some more in his ASP.NET MVC source code. Inspired by his helpers, here I post mine.</p>
<h3>1. Html.Image</h3>
<p>Depending on the environment, the absolute url of an image can change. For example, on the dev machine, it is http://localhost:3107/content/images/cancel.gif. On Integration server, if the server host multiple applications under root with the same port numer, 80, the image path can be like http://intserver/app1/content/images/cancel.gif. In this case, the image would not be rendered. SiteRoot is Rob Conery&#8217;s helper.</p>
<p>To avoid the situation like the above, I reference image suing SiteRoot functionality.</p>
<p><pre class="brush: csharp;">
public static string Image(this HtmlHelper helper, string imageName, string altText)
{
    var builder = new TagBuilder(&quot;img&quot;);
    builder.MergeAttribute(&quot;src&quot;,
        UrlHelpers.SiteRoot(helper.ViewContext.HttpContext) + &quot;/content/images/&quot; + imageName);
    builder.MergeAttribute(&quot;alt&quot;, altText);

    return builder.ToString(TagRenderMode.SelfClosing);
}
</pre></p>
<h3></h3>
<h3>2. Html.ClientIdFor</h3>
<p>In MVC, you pass viewmodel to View. I often refactor the viewmodel and the change involve property name. When you change a property name of a viewmodel, all server side code like Html.TextBoxFor(m =&gt; m.Input.Firstname&#8221; change accordingly, but you have to manually change javascript code.</p>
<p>For example,</p>
<p><pre class="brush: jscript;">
$('#Input_Firstname').change(resetRate);
</pre></p>
<p>You would have to change the id manually. I thought it would be nice to specify clientId with server-side code, and I was not alone. There were guys with <a href="http://stackoverflow.com/questions/5418898/get-the-generated-clientid-for-a-form-field">the same idea</a>. The following is the code for ClientIdFor and I got the code from <a href="http://stackoverflow.com/users/66873/john-landheer">John Landheer</a>&#8216;s <a href="http://stackoverflow.com/questions/5418898/get-the-generated-clientid-for-a-form-field">answer on stackoverflow</a>.</p>
<p><pre class="brush: csharp;">
public static MvcHtmlString ClientIdFor&lt;TModel, TProperty&gt;(this HtmlHelper&lt;TModel&gt; helper, Expression&lt;Func&lt;TModel, TProperty&gt;&gt; expression)
{
    return
        MvcHtmlString.Create(
            helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(
                ExpressionHelper.GetExpressionText(expression)));
}
</pre></p>
<h3></h3>
<h3>3. Script</h3>
<p>This writes javascript include statement.</p>
<p><pre class="brush: csharp;">
public static string Script(this HtmlHelper helper, string fileName)
{
    if (!fileName.EndsWith(&quot;.js&quot;))
        fileName += &quot;.js&quot;;

    return string.Format(&quot;&lt;script src='{0}/{1}/{2}/{3}' type='text/javascript' &gt;&lt;/script&gt;\n&quot;,
        helper.SiteRoot(), PUBDIR, SCRIPTDIR, helper.AttributeEncode(fileName));
}

public static string ScriptIe(this HtmlHelper helper, string fileName)
{
    if (!fileName.EndsWith(&quot;.js&quot;))
        fileName += &quot;.js&quot;;

    return string.Format(&quot;&lt;!--[if lt IE 7]&gt;\n&lt;script src='{0}/{1}/{2}/{3}' defer type='text/javascript' &gt;&lt;/script&gt;\n&lt;![endif]--&gt;&quot;,
        helper.SiteRoot(), PUBDIR, SCRIPTDIR, helper.AttributeEncode(fileName));
}
</pre></p>
<p>&#8211; To be continued &#8211;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/403/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=403&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2011/04/14/my-favourite-helpers-for-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing private method in unit testing</title>
		<link>http://andrewchaa.me.uk/2010/11/02/testing-private-method-in-unit-testing/</link>
		<comments>http://andrewchaa.me.uk/2010/11/02/testing-private-method-in-unit-testing/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 10:21:17 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[NUnit]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=386</guid>
		<description><![CDATA[Ideally, it is not recommended to test private methods, as complex internals should be kept hidden and only interface be tested. Well, in real world, sometimes, you need to test your private methods, as it performs very important operation. In my case, the method was public and later I changed it to private, since it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=386&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ideally, it is not recommended to test private methods, as complex internals should be kept hidden and only interface be tested. Well, in real world, sometimes, you need to test your private methods, as it performs very important operation.</p>
<p>In my case, the method was public and later I changed it to private, since it is better to be hidden. Yet, I still wanted to test it, as it does lots of things &#8211; calling several other private methods and sum up the result.</p>
<p>You can use .Net reflection and easily do it. One nice article I found by googling was <a href="http://www.codeproject.com/KB/cs/testnonpublicmembers.aspx">http://www.codeproject.com/KB/cs/testnonpublicmembers.aspx</a>. Simple and straight-forward.</p>
<p>I created a static helper method. I changed variable names in the above example, as it follows old C++ style. These days, C# guys prefer longer variable name without type prefix.</p>
<p><pre class="brush: csharp;">
public class TestHelper
{
    public static object RunStaticMethod(Type type, string method, object[] parameters)
    {
        return RunMethod(type, method, null, parameters, BindingFlags.Static | BindingFlags.NonPublic);
    }

    public static object RunInstanceMethod(Type type, string method, object instance, object[] parameters)
    {
        return RunMethod(type, method, instance, parameters, BindingFlags.Instance | BindingFlags.NonPublic);
    }

    private static object RunMethod(Type type, string method, object instance, object[] parameters, BindingFlags flags)
    {
        try
        {
            MethodInfo info = type.GetMethod(method, flags);
            return info.Invoke(instance, parameters);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/386/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=386&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2010/11/02/testing-private-method-in-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Using uploadify in ASP.Net MVC application</title>
		<link>http://andrewchaa.me.uk/2010/09/24/using-uploadify-in-asp-net-mvc-application/</link>
		<comments>http://andrewchaa.me.uk/2010/09/24/using-uploadify-in-asp-net-mvc-application/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 11:55:44 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=381</guid>
		<description><![CDATA[Dropbox is getting more and more popular. I use it on my desktop, laptop, iphone, and ipad. Once I went to a post office to post a document, and realised that I don&#8217;t know the address. I had my iphone with me, so used Dropbox to get the address. It was so useful, and ever [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=381&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dropbox.com">Dropbox</a> is getting more and more popular. I use it on my desktop, laptop, iphone, and ipad. Once I went to a post office to post a document, and realised that I don&#8217;t know the address. I had my iphone with me, so used Dropbox to get the address. It was so useful, and ever since, I became a fan of Dropbox.</p>
<p>Anyway, Dropbox has nice Flash-based upload functionality, and I wanted to mimic the feature in my asp.net application. <a href="http://krystalware.com/Products/SlickUpload/">SlickUpload</a> is a very good component, but commercial. I googled and came across <a href="http://www.uploadify.com/">uploadify</a>.</p>
<p>The site has good example code and a link to <a href="http://casonclagg.com/articles/6/video-tutorial-uploadify-asp-net-c-sharp.aspx">asp.net example</a> too. If you want to make your file upload testable, read <a href="http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx">Scott hanselman&#8217;s fantastic post</a> about it.</p>
<p>The below is my code. One thing to note in the code are</p>
<ul>
<li>Url.SiteRoot() is a custom extension method that finds root of the web application. I use it as this application goes under another application. So the url of images is not /public/images/, but /[unknown]/public/images. You would not need Url.SiteRoot() if your application root is the top level directory in iis.</li>
</ul>
<p><pre class="brush: csharp;">
public ActionResult UploadFiles()
{
    foreach (string file in Request.Files)
    {
        var postedFileBase = Request.Files[file];
        if (postedFileBase.ContentLength == 0)
            continue;

        string savedFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                            Path.GetFileName(postedFileBase.FileName));
        postedFileBase.SaveAs(savedFilename);
    }

    return View();
}

</pre></p>
<p><pre class="brush: jscript;">
$(function(){
    $(&quot;#file&quot;).uploadify({
        'uploader': '&lt;%= Url.SiteRoot() %&gt;/public/images/uploadify.swf',
        'script': 'Home/UploadFiles',
        'cancelImg': '&lt;%= Url.SiteRoot() %&gt;/public/images/cancel.png',
        'auto': false,
        'multi': false
    });
})

&lt;h2&gt;Simple file upload.&lt;/h2&gt;
&lt;p&gt;
    
    &lt;form action=&quot;&lt;%= Url.Action(&quot;UploadFiles&quot;, &quot;Home&quot;) %&gt;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
        
        &lt;p&gt;
        &lt;input type=&quot;file&quot; name=&quot;file&quot; id=&quot;file&quot; /&gt;
        &lt;a href=&quot;javascript:$('#file').uploadifyUpload();&quot;&gt;Upload Files&lt;/a&gt;
        &lt;/p&gt;
        
    &lt;/form&gt;
&lt;/p&gt;

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/381/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=381&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2010/09/24/using-uploadify-in-asp-net-mvc-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Outputting to pdf using iTextSharp</title>
		<link>http://andrewchaa.me.uk/2010/08/25/outputting-to-pdf-using-itextsharp/</link>
		<comments>http://andrewchaa.me.uk/2010/08/25/outputting-to-pdf-using-itextsharp/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:47:57 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C# iTextSharp]]></category>

		<guid isPermaLink="false">http://simplelifeuk.wordpress.com/?p=374</guid>
		<description><![CDATA[Recently, I moved to Barclays. My job is still development, though. Totaljobs is a good company, and I enjoyed its casual, IT geek culture. It&#8217;s the thing I miss in my new job, as I work with quants. The web application here has generally more complex UI. On public web page, you would not normally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=374&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I moved to Barclays. My job is still development, though. Totaljobs is a good company, and I enjoyed its casual, IT geek culture. It&#8217;s the thing I miss in my new job, as I work with quants.</p>
<p>The web application here has generally more complex UI. On public web page, you would not normally demand user to put in more than 20 textboxes or dropdowns. On financial application, it seems to be common. Nice graphs are often mandatory.</p>
<p>Anyway, one of my recent task was to let user download a report in pdf format. A colleague in the team told me we already used iTextSharp. I haven&#8217;t used it before, but it seems to be popular in java community, and ported to .Net as well. It looks like great component, but has poor documentation. It&#8217;s not easy to find good code examples.</p>
<p>One good working code is <a href="http://ozzieperez.net/blog/?p=255">http://ozzieperez.net/blog/?p=255</a>. I was lucky to find a code dealing with multi-columns and fixed column table. (<a href="http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns">http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns</a>) This article greatly helped me.</p>
<p>I want to share my code too, to help other guys who may feel frustrated without any code sample. I changed variable names and also removed most part of the code, but it shouldn&#8217;t matter.</p>
<p><pre class="brush: csharp;">

public class ExportService
{
    private const int LEFT = 0;
    private const int CENTER = 1;

    private pcService _pSvc;
    private BaseFont _verdanaBase;
    private Font _verdanaNormal, _verdanaHeading, _verdanaTitle;
    private BaseColor _textColor, _lineColor, _backgroundColor;

    public ExportService()
    {
        _pSvc = new pcService();

        _textColor = new BaseColor(ColorTranslator.FromHtml(&quot;#003366&quot;));
        _lineColor = new BaseColor(ColorTranslator.FromHtml(&quot;#00a4e8&quot;));
        _backgroundColor = new BaseColor(ColorTranslator.FromHtml(&quot;#eeeeee&quot;));
        
        _verdanaBase = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        _verdanaNormal = new Font(_verdanaBase, 10, Font.NORMAL, _textColor);
        _verdanaHeading = new Font(_verdanaBase, 12, Font.NORMAL, _textColor);
        _verdanaTitle = new Font(_verdanaBase, 24, Font.ITALIC, _textColor);
    }

    public MemoryStream GetPdfStream(int pcId, string logoPath)
    {
        var memoryStream = new MemoryStream();

        var pageSize = new Rectangle(PageSize.A4);
        var document = new Document(pageSize, 36, 36, 50, 50);

        SetMetadata(document);
        EncryptPdf(document, memoryStream);

        document.Open();
        
        document.Add(GetLogo(document, logoPath));

        var title = new Paragraph(&quot;Report&quot;, _verdanaTitle);
        title.SetAlignment(&quot;Center&quot;);

        document.Add(title);
        document.Add(new Paragraph(&quot;\n&quot;));
        document.Add(new Paragraph(&quot;\n&quot;));

        var table = GetTable(_pSvc.Get(pcId));
        document.Add(table);
        document.Close();

        return memoryStream;
    }

    private PdfPTable GetTable(Pc pc)
    {
        var table = new PdfPTable(4);
        var widths = new[] { 110f, 120f, 110f, 120f };
        table.TotalWidth = 460f;
        table.LockedWidth = true;
        table.SetWidths(widths);


        AddHeading(table, &quot;Global Settings&quot;);
        AddCell(table, &quot;Country: &quot;, pc.OCountry, &quot;Country: &quot;, pc.OperatingAssetsCountry);
        AddCell(table, &quot;Currency: &quot;, pc.Currency, &quot;Date: &quot;, pc.ValuationDateString);

        AddHeading(table, &quot;Customer&quot;);
        AddCell(table, &quot;Customer Name: &quot;, pc.Customer.Name, &quot;Customer ID: &quot;, pc.Customer.Id.ToString());
        AddCell(table, &quot;Bc: &quot;, pc.Customer.Bc.ToString(), &quot;Sales Turnover (m): &quot;, pc.Customer.Sales.TwoDpText());

        ...

        AddHeading(table, &quot;Valuation Identification Number: &quot; + pc.Id);
        return table;
    }

    private void AddHeading(PdfPTable table, string heading)
    {
        PdfPCell cell = new PdfPCell(new Phrase(heading, _verdanaHeading));
        cell.Colspan = 4;
        cell.BackgroundColor = _backgroundColor;
        cell.HorizontalAlignment = CENTER;
        cell.Border = iTextSharp.text.Rectangle.BOX;
        cell.BorderColor = _lineColor;
        cell.MinimumHeight = 22;
        cell.VerticalAlignment = 1;
        table.AddCell(cell);
    }

    private void AddCell(PdfPTable table, string label1, string text1, string label2, string text2)
    {
        var labelCell = GetLabelCell();
        var textCell = GetTextCell();

        labelCell.Phrase = new Phrase(label1, _verdanaNormal);
        table.AddCell(labelCell);

        textCell.Phrase = new Phrase(text1, _verdanaNormal);
        table.AddCell(textCell);

        labelCell.Phrase = new Phrase(label2, _verdanaNormal);
        table.AddCell(labelCell);

        textCell.Phrase = new Phrase(text2, _verdanaNormal);
        table.AddCell(textCell);
    }

    private void AddCell(PdfPTable table, string label, string text)
    {
        var labelCell = GetLabelCell();
        var textCell = GetTextCell();

        labelCell.Phrase = new Phrase(label, _verdanaNormal);
        table.AddCell(labelCell);

        textCell.Phrase = new Phrase(text, _verdanaNormal);
        table.AddCell(textCell);

        labelCell.Phrase = new Phrase(string.Empty, _verdanaNormal);
        table.AddCell(labelCell);

        textCell.Phrase = new Phrase(string.Empty, _verdanaNormal);
        table.AddCell(textCell);
    }

    private PdfPCell GetTextCell()
    {
        return new PdfPCell
                   {
                       Border = Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER,
                       BorderColor = _lineColor,
                       MinimumHeight = 20,
                       HorizontalAlignment = LEFT,
                   };
    }

    private PdfPCell GetLabelCell()
    {
        return new PdfPCell
                   {
                       Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER,
                       BorderColor = _lineColor,
                       MinimumHeight = 20,
                       HorizontalAlignment = LEFT,
                       PaddingLeft = 3
                   };
    }

    private Image GetLogo(Document document, string logoPath)
    {
        var logo = Image.GetInstance(logoPath);
        logo.ScalePercent(48f);
        logo.SetAbsolutePosition(document.PageSize.Width - 36f - 130f, document.PageSize.Height - 36f - 15.36f);
        return logo;
    }

    private void SetMetadata(Document document)
    {
        document.AddAuthor(&quot;Wordpress&quot;);
        document.AddSubject(&quot;Report&quot;);
        document.AddKeywords(&quot;Report;Wordpress&quot;);
    }

    private void EncryptPdf(Document document, MemoryStream memoryStream)
    {
        var writer = PdfWriter.GetInstance(document, memoryStream);
        writer.SetEncryption(PdfWriter.STRENGTH128BITS, null, null, PdfWriter.AllowCopy | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS);
    }

}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simplelifeuk.wordpress.com/374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simplelifeuk.wordpress.com/374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simplelifeuk.wordpress.com/374/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewchaa.me.uk&amp;blog=1833431&amp;post=374&amp;subd=simplelifeuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewchaa.me.uk/2010/08/25/outputting-to-pdf-using-itextsharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c311c181986feead6c7cb43fb9844b32?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simplelifeuk</media:title>
		</media:content>
	</item>
	</channel>
</rss>
