<?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>Melbourne Web Developer, Website Design &#38; Development &#187; Lab</title>
	<atom:link href="http://blog.koumei.net/category/lab/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.koumei.net</link>
	<description>-(unichar) fn: (unichar)n{ return n ^ 0xFFFF004B == 0? n : [self fn:(n-0x1)]}</description>
	<lastBuildDate>Thu, 02 Jun 2011 02:46:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jCarousel Lite Mouse Hover Event Improvement</title>
		<link>http://blog.koumei.net/2011/06/01/jcarousel-lite-mouse-hover-event-improvement/</link>
		<comments>http://blog.koumei.net/2011/06/01/jcarousel-lite-mouse-hover-event-improvement/#comments</comments>
		<pubDate>Tue, 31 May 2011 22:37:35 +0000</pubDate>
		<dc:creator>Koumei</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.koumei.net/?p=732</guid>
		<description><![CDATA[jCarousel Lite is a fantastic jQuery plug-in to display photo gallery. You can have a look at the demo at: http://www.gmarwaha.com/jquery/jcarousellite/#demo
On this demo, the photo gallery will only scroll left or right when you click on the left arrow and right arrow. On jCarousel&#8217;s document, we can initialize the carousel start scrolling when the page [...]]]></description>
			<content:encoded><![CDATA[<p>jCarousel Lite is a fantastic jQuery plug-in to display photo gallery. You can have a look at the demo at: <a href="http://www.gmarwaha.com/jquery/jcarousellite/#demo" target="_blank">http://www.gmarwaha.com/jquery/jcarousellite/#demo</a></p>
<p>On this demo, the photo gallery will only scroll left or right when you click on the left arrow and right arrow. On jCarousel&#8217;s document, we can initialize the carousel start scrolling when the page finishes loading by specify the option: auto</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">$(&quot;.slider&quot;).jCarouselLite({
visible: 4,
&lt;strong&gt;auto: true&lt;/strong&gt;,
speed: 2000
});</pre></div></div>

<p>What if I want it to stop when my mouse hover on any of the images? Oh, jCarousel does not originally handle mouse hover event. Well, DIY time.</p>
<h2>Firstly, download the carousel <a href="http://www.gmarwaha.com/jquery/jcarousellite/#download" target="_blank">original source code</a> from the official website</h2>
<p>open that file (jcarousellite_1.0.1.js)</p>
<h2>Second, add a code block between line &#8220;function go(to){&#8221; (about line 292):</h2>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">//&amp;lt;!--add by koumei
var isMouseOver = false;
$(this).mouseover(function(){
isMouseOver = true;
}).mouseout(function(){
isMouseOver = false;
});
//add by koumei--&amp;gt;
function go(to) {
...
...</pre></div></div>

<h2>Third, modify function go: (around line 293)</h2>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">Change &quot;if(!running)&quot; to &quot;if(!running &amp;amp;&amp;amp; !isMouseOver)&quot;</pre></div></div>

<h2>Fourth, DONE.</h2>
<p>Quite simple, I hope the author will consider this function to the next release. <img src='http://blog.koumei.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You can also download my modified version and the demo at:</p>
<p><a href="http://koumei.net/download/carousel-demo.zip" target="_blank">http://koumei.net/download/carousel-demo.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koumei.net/2011/06/01/jcarousel-lite-mouse-hover-event-improvement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Html5 Drama Update Episode 2</title>
		<link>http://blog.koumei.net/2010/07/27/html5-drama-episode-2-update/</link>
		<comments>http://blog.koumei.net/2010/07/27/html5-drama-episode-2-update/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 14:10:24 +0000</pubDate>
		<dc:creator>Koumei</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[iDEA]]></category>

		<guid isPermaLink="false">http://blog.koumei.net/?p=626</guid>
		<description><![CDATA[Html5 Drama Episode 2
Foreword:
Anonymous&#8217; ID seems to be unveiled on this update. Well, the anonymous sends Koumei a photo image, Koumei is shocked after he knows who anonymous really is.
Summary:
2D context API is quite useful and interesting. The HTML5 canvas is absolutely fantastic!
Pre-requisition:
Firefox 3.6+ or Google Chrome. Internet Explorer 8 does not support
]]></description>
			<content:encoded><![CDATA[<p><em><strong><span style="text-decoration: underline;"><a title="Html5 Drama Episode 2" href="html5.html" target="_blank">Html5 Drama Episode 2</a></span></strong></em></p>
<p><strong>Foreword:</strong></p>
<p>Anonymous&#8217; ID seems to be unveiled on this update. Well, the anonymous sends Koumei a photo image, Koumei is shocked after he knows who anonymous really is.</p>
<p><strong>Summary:</strong></p>
<p>2D context API is quite useful and interesting. The HTML5 canvas is absolutely fantastic!</p>
<p><strong>Pre-requisition:</strong></p>
<p>Firefox 3.6+ or Google Chrome. Internet Explorer 8 does not support</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koumei.net/2010/07/27/html5-drama-episode-2-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use of Lambda Expression to Create Complicated Query</title>
		<link>http://blog.koumei.net/2010/03/10/use-lambda-expression-to-create-complicated-query/</link>
		<comments>http://blog.koumei.net/2010/03/10/use-lambda-expression-to-create-complicated-query/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 07:12:31 +0000</pubDate>
		<dc:creator>Koumei</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Tech.]]></category>

		<guid isPermaLink="false">http://blog.koumei.net/?p=465</guid>
		<description><![CDATA[.NET FX introduces a powerful weapon for creating the compact, breezy and elegant code in your project. The weapon&#8217;s name is as complicated as the mathematical stuff, called Lambda expression.
As the name implies, the great convenience comes great complication inside. Lambda expression is too important to understand, it is useful and I think it is [...]]]></description>
			<content:encoded><![CDATA[<p>.NET FX introduces a powerful weapon for creating the compact, breezy and elegant code in your project. The weapon&#8217;s name is as complicated as the mathematical stuff, called Lambda expression.</p>
<p>As the name implies, the great convenience comes great complication inside. Lambda expression is too important to understand, it is useful and I think it is good to know how it works. Well, it&#8217;s not as complicated as we think, just a little bit confusing when using it.</p>
<p>First of all, Lambda is used for 2 purposes. 1 is to simplify delegation, 2 is to create expression tree. In my case, I need to create lambda expression to create dynamic query.</p>
<p>Imagine the following usecase:</p>
<p>In your product table, there is a field called &#8220;Tags&#8221; and it&#8217;s used for storing the CSV (comma separated value) like &#8220;car, mazda, suv, luxury&#8221;, you have many records:</p>
<p>Product Table: (Table name: ProductTable)</p>
<p><span style="text-decoration: underline;"><strong>ID    ProductName    Tags</strong></span><br />
1    Tow bar        car,mazda,suv,luxury<br />
2    Cup holder    car,luxury<br />
3    Phone holder    car,mazda<br />
4    FM Transmitter    car,suv<br />
5    Queens bed    luxury<br />
6    DVD Burner    car,BMW,x5,luxury</p>
<p>When your searching criteria is<br />
&#8220;mazda&#8221; and &#8220;luxury&#8221;, the following records would be selected out:</p>
<p><span style="text-decoration: underline;"><strong>ID    ProductName    Tags</strong></span><br />
1    Tow bar        car,mazda,suv,luxury<br />
2    Cup holder    car,luxury<br />
3    Phone holder    car,mazda<br />
5    Queens bed    luxury<br />
6    DVD Burner    car,BMW,x5,luxury</p>
<p>In ancient SQL age, you would probably write a SQL like this:</p>
<address>string SQL = &#8220;SELECT * FORM ProductTable WHERE Tags LIKE&#8217;%mazda%&#8217; OR Tags LIKE &#8216;%luxury%&#8217;&#8221;;</address>
<p>It is IMpossible to create SQL like above except the project scope tells you the fixed keywords that would be used, the keywords should flexible. Then the code would be as much as:</p>
<address>string[] tags = new string[]{&#8220;mazda&#8221;, &#8220;luxury&#8221;};</address>
<address>string SQL = &#8220;SELECT * FROM ProductTable WHERE 1=1&#8243;;<br />
foreach(string tag in tags)<br />
{<br />
SQL += string.format(@&#8221; AND Tags like &#8216;%{0}%&#8217;&#8221;, tag);<br />
}</address>
<p>You must be very exciting that your code supports as many keywrods as it can. (I did before, I mean I would be very exciting when the code filled with logical stuff, LOL, of course, not now, that&#8217;s what geek did before~ )</p>
<p>Back to the reality, to the modern age, with the lambda expression, what you need to do is:</p>
<p>(pre-condition: you have created corresponding domain model which mapped to the database.)<br />
The domain object or entity would look like:</p>
<address>[Table("ProductTable")] Class ProductTable{<br />
[Column]public int Id{get; set;}<br />
[Column]public string ProductName{get; set;}<br />
[Column]public string Tags{get; set;}<br />
}</address>
<p>to fullfill the same kind of logic as the stone-aged people do, you just need to</p>
<address>DataContext db = new DataContext(&#8220;&lt;connection-string&gt;&#8221;);<br />
Table&lt;ProductTable&gt; table = db.GetTable&lt;ProductTable&gt;();</address>
<address>string tag1 = &#8220;mazda&#8221;;<br />
string tag2 = &#8220;luxury&#8221;;</address>
<address>var data = table.where(x=&gt;x.Tags.Contains(tag1)).where(x=&gt;x.Tags.Contains(tag2)) select new ProductTable;<br />
return data.AsQueryable();</address>
<p>Since so far, you still feel comfortable with this, but after minute, you would probably wanna go back stone age, how do we dynamically create the query in this case? Unfortunately, there is no short-cut for this, but many people provide lots of solutions on the Internet. We can either download some source codes about dynamically query on Internet or just grab the codes from the blogger&#8217;s website.( Most of time, you can&#8217;t use all of their codes posted on the blog, the codes are broken and bad structure, remember what Koumei always suggests, absorb the mind from the other coders, do not copy the code they provided. )</p>
<p>But in here, I would rather to use Expression Tree to implement the dynamic query.</p>
<p>First of all, we need to create an expression, because it would be applied to IQueryable.Where(Expression&lt;Func&lt;ProductTable, bool&gt;&gt; expression), so the expression should be defined as:</p>
<address>public static System.Linq.Expressions.Expression&lt;Func&lt;ProductTable, bool&gt;&gt; ApplyTags(IEnumerable&lt;string&gt; tags) //parameter is the collection of tags<br />
{</address>
<address>ParameterExpression c = Expression.Parameter(typeof(ProductTable), &#8220;c&#8221;); //Get the parameter from Func&lt;ProductTable, bool&gt;, remember? this is the advanced and lazy version of delegation, we need to craete ParameterExpression to hold this</address>
<address>var tagsProperty = Expression.Property(c, typeof(ProductTable).GetProperty(&#8220;Tags&#8221;)); //Here is the expression for get the Tags value from ProductTable object</address>
<address>Type[] ContainsTypes = new Type[1];</address>
<address>ContainsTypes[0] = typeof(string);</address>
<address>System.Reflection.MethodInfo myContainsInfo = typeof(string).GetMethod(&#8220;Contains&#8221;, ContainsTypes);</address>
<address>//Create the expression collection (based on the tags collection from parameter)<br />
List&lt;Expression&gt; myTagExpressions = new List&lt;Expression&gt;();</address>
<address>foreach (var t in tags)<br />
{<br />
myTagExpressions.Add(Expression.Call(Expression.Call(tagsProperty, &#8220;ToString&#8221;, null, null), myContainsInfo, Expression.Constant(t)));<br />
}</address>
<address>Expression OrExpression = null;</address>
<address>foreach (Expression myTagExpression in myTagExpressions)<br />
{<br />
if (OrExpression == null)<br />
{<br />
OrExpression = myTagExpression;<br />
}<br />
else<br />
{<br />
//Need to implement OR relationship among all the expressions<br />
OrExpression = Expression.Or(myTagExpression, OrExpression);<br />
}<br />
}</address>
<address>//This is how Expression would be extracted to expression tree later on.<br />
Expression&lt;Func&lt;ProductTable, bool&gt;&gt; predicate = Expression.Lambda&lt;Func&lt;ProductTable, bool&gt;&gt;(OrExpression, c);</address>
<address>return predicate;</address>
<address>}</address>
<p>Again, you can&#8217;t copy the code, since you would NOT have the same object like ProductTable and the same &#8220;Tags&#8221; property as I do. Luckily, you still can copy the code that I provide later, which is using the magic of template or generic programming. Before that, let us see how to use it:</p>
<address>IQueryable all = table.Where(ApplyTags(new List{&#8220;mazda&#8221;,&#8221;luxury&#8221;})).AsQueryable();</address>
<p>Since so far, I am 100% sure you can do it like refactoring, re-structuring to optimize your code. However, I would like to provide the code which can be general used:</p>
<address>public static System.Linq.Expressions.Expression&lt;Func&lt;T, bool&gt;&gt; ApplyFilter&lt;T&gt;(IEnumerable&lt;string&gt; filters, string property)<br />
{<br />
//Get parameter<br />
ParameterExpression c = Expression.Parameter(typeof(T), &#8220;c&#8221;);</address>
<address>//Get property from &lt;T&gt;<br />
var tagsProperty = Expression.Property(c, typeof(T).GetProperty(property));</address>
<address>Type[] ContainsTypes = new Type[1];<br />
ContainsTypes[0] = typeof(string);<br />
System.Reflection.MethodInfo myContainsInfo = typeof(string).GetMethod(&#8220;Contains&#8221;, ContainsTypes);<br />
List&lt;Expression&gt; myTagExpressions = new List&lt;Expression&gt;();<br />
foreach (var t in filters)<br />
{<br />
myTagExpressions.Add(Expression.Call(Expression.Call(tagsProperty, &#8220;ToString&#8221;, null, null), myContainsInfo, Expression.Constant(t)));<br />
}<br />
Expression OrExpression = null;<br />
foreach (Expression myTagExpression in myTagExpressions)<br />
{<br />
if (OrExpression == null)<br />
{<br />
OrExpression = myTagExpression;<br />
}<br />
else<br />
{<br />
OrExpression = Expression.Or(myTagExpression, OrExpression);<br />
}<br />
}<br />
Expression&lt;Func&lt;T, bool&gt;&gt; predicate = Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(OrExpression, c);<br />
return predicate;<br />
}</address>
<p>The usage is similiar:</p>
<address>IQueryable all = table.Where(ApplyFilter&lt;ProductTable&gt;(new List{&#8220;mazda&#8221;,&#8221;luxury&#8221;}, &#8220;Tags&#8221;)).AsQueryable();</address>
<p>Not that hard, right?</p>
<p>Enjoy the powerful weapon, but don&#8217;t hurt yourself, bacause the deadline is ahead!</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 114px; width: 1px; height: 1px;">6    DVD Burner    car,BMW,x5,luxury</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.koumei.net/2010/03/10/use-lambda-expression-to-create-complicated-query/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lab &#8211; Analysis Utility for Dentist &#8211; Schwartz-Korkhaus Model</title>
		<link>http://blog.koumei.net/2009/11/11/lab-analysis-utility-for-dentist-schwartz-korkhaus-model/</link>
		<comments>http://blog.koumei.net/2009/11/11/lab-analysis-utility-for-dentist-schwartz-korkhaus-model/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 10:07:29 +0000</pubDate>
		<dc:creator>Koumei</dc:creator>
				<category><![CDATA[Lab]]></category>

		<guid isPermaLink="false">http://blog.koumei.net/?p=324</guid>
		<description><![CDATA[Idea for creating this gadget is to minimize the time for calculating the data gathering from the dental study model. My existence is to reduce the repetition and complexity.  
Email me if you need such gadget. It&#8217;s free to use for all the dentists.
After input the data of A,B,C,D,B1 and C1, the gadget can [...]]]></description>
			<content:encoded><![CDATA[<p>Idea for creating this gadget is to minimize the time for calculating the data gathering from the dental study model. My existence is to reduce the repetition and complexity. <img src='http://blog.koumei.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Email me if you need such gadget. It&#8217;s free to use for all the dentists.</p>
<p>After input the data of A,B,C,D,B1 and C1, the gadget can print it as PDF and the filename is set to patient&#8217;s name automatically.</p>
<p><a href="http://blog.koumei.net/wp-content/uploads/2009/11/11-11-2009-8-49-28-pm.png"><img class="alignnone size-full wp-image-325" title="11-11-2009-8-49-28-pm" src="http://blog.koumei.net/wp-content/uploads/2009/11/11-11-2009-8-49-28-pm.png" alt="11-11-2009-8-49-28-pm" width="641" height="323" /></a></p>
<p><a href="http://blog.koumei.net/wp-content/uploads/2009/11/11-11-2009-8-50-23-pm.png"><img class="alignnone size-full wp-image-326" style="border: 1px solid black;" title="11-11-2009-8-50-23-pm" src="http://blog.koumei.net/wp-content/uploads/2009/11/11-11-2009-8-50-23-pm.png" alt="11-11-2009-8-50-23-pm" width="373" height="497" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.koumei.net/2009/11/11/lab-analysis-utility-for-dentist-schwartz-korkhaus-model/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

