<?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>.NET Tips and Tricks &#187; Tips and Tricks</title>
	<atom:link href="http://kossovsky.net/index.php/tag/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://kossovsky.net</link>
	<description>C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks</description>
	<lastBuildDate>Thu, 13 May 2010 13:02:50 +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>jTemplates &#8211; jQuery Template Engine</title>
		<link>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/</link>
		<comments>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 22:46:51 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dom template]]></category>
		<category><![CDATA[dynamic template]]></category>
		<category><![CDATA[endless event]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[event handlers]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript library]]></category>
		<category><![CDATA[javascript templates]]></category>
		<category><![CDATA[jquery templates]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[js template]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[rapid web development]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[server side code]]></category>
		<category><![CDATA[side requests]]></category>
		<category><![CDATA[support parameters]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[template engine]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[time manipulation]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[usable features]]></category>
		<category><![CDATA[web template]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=789</guid>
		<description><![CDATA[jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.
The syntax is very simple and  intuitive. It's support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (10 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/' rel='bookmark' title='Permanent Link: IE Memory Leak &#8211; jQuery Fix'>IE Memory Leak &#8211; jQuery Fix</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>About a year ago i had to architucture some web application with a very rich client side UI.</p>
<p>ASP.NET was an easy choise for a server side code, but what about client side ?<br />
The heavy viewstate, endless event handlers and infinity number of server side requests just to make the GUI  friendly &#8211; well, it just didn&#8217;t sound as a proper way to do it.</p>
<p><span id="more-789"></span>So, what do we have ?<br />
.NET as a server side platform, but despite  all it&#8217;s powerful abilities it has nothing to do with client side. At the end of the day all those fancy control are just HTML and JavaScript.</p>
<p> JavaScript is still the engine that runs at the client side and it&#8217;s great, but we all know how many lines of code we have to write and time to spend to make it fast, modular and cross browser.</p>
<p><a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a> &#8211; it&#8217;s a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.</p>
<p>Indeed, we can do a many things with jQuery and it realy simplify the coding, but what if we have to build a product list with complicated HMTL, complex logic and real time manipulation ?</p>
<p>As i mentioned before, ASP.NET and UpdatePanels are just to heavy and JavaScript is to long.</p>
<p>So, i did some research and find a couple of JavaScript Template Engines.<br />
The first one i bumped in was <a href="http://plugins.jquery.com/project/jsrepeater" target="_blank">jsRepeater</a>. At first it seemed like a great solution but after a few tests i found all kinds of bugs related to the syntax conflicts with HTML and JavaScript.</p>
<p>After a few days of googling, tests and googling again i found the one and only &#8211;  <a title="jTemplates" href="http://jtemplates.tpython.com/" target="_blank">jTemplates</a>.<br />
jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.<br />
The syntax is very simple and  intuitive. It&#8217;s support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.</p>
<p>Let&#8217;s say we want to list all our products. What we have to do is to write the template (HTML), pass the data and we have a product list.</p>
<p>
<div><span style="color: #0000ff;">{#foreach $T.Product as P}</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span> <span style="color: #008000;">style</span>=&#8221;float:left;width:150px;height:150px&#8221;<span style="color: #0000ff;">&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span><strong>{$T.P.Title}</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">img</span> <span style="color: #008000;">src</span>=&#8221;<strong>{$T.P.Url}</strong>&#8221; <span style="color: #008000;">alt</span>=&#8221;<strong>{$T.P.Title}</strong>&#8221; style=&#8221;width:10px;height:10px&#8221; <span style="color: #0000ff;">/&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;hr /&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span>Price : <strong>{$T.P.Price}$</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span></div>
<div><span style="color: #0000ff;">{#/for}</span></div>
</p>
<p>Look how easy this is. You just write HTML and werever you need to insert some data you put {$.T.P.ColumnName}.</p>
<p>So, how we use it ?<br />
Just add some textarea to your page, give it some id, set it&#8217;s display style to none and write your template inside.</p>
<pre class="html" name="code">
&lt;textarea cols="0" rows ="0" style="display:none;" id="ProductListTemplate"&gt;&lt;!--
{#foreach $T.Product as P}
	&lt;div style=”float:left;width:150px;height:150px”&gt;
		&lt;div>{$T.P.Title}&lt;/div&gt;
		&lt;img src=”{$T.P.Url}” alt=”{$T.P.Title}” style=”width:10px;height:10px” /&gt;
		&lt;hr /&gt;
		&lt;div>Price : {$T.P.Price}$&lt;/div&gt;
	&lt;/div&gt;
{#/for}
--&gt;&lt;/textarea&gt;
</pre>
<p>Add some empty container that will hold the result.</p>
<pre class="html" name="code">
&lt;div id="ProductListContainer"&gt;&lt;/div&gt;
</pre>
<p>Execute setTemplateElement and execute processTemplate while passing the data into it as a parameter</p>
<pre class="javascript" name="code">
$("#ProductListContainer").setTemplateElement("ProductListTemplate");
$("#ProductListContainer").processTemplate(data);
</pre>
<p>Easy, isn&#8217;t it ?<br />
I must say that the above example is a simple one, but I&#8217;ve been using jTemplates to create complicated lists, grids, trees, popups and even an image editing web application. Use it, I&#8217;m sure you will love it.</p>
<div style="margin-top:-15px;margin-bottom:15px;"><script type="text/javascript">
var dzone_url = 'http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/';
var dzone_style = '1';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (10 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F10%2Fjtemplates-jquery-template-engine%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/' rel='bookmark' title='Permanent Link: IE Memory Leak &#8211; jQuery Fix'>IE Memory Leak &#8211; jQuery Fix</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>C# Set method timeout using Generics</title>
		<link>http://kossovsky.net/index.php/2009/07/csharp-how-to-limit-method-execution-time/</link>
		<comments>http://kossovsky.net/index.php/2009/07/csharp-how-to-limit-method-execution-time/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 18:30:17 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[execution]]></category>
		<category><![CDATA[file ext]]></category>
		<category><![CDATA[func]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[httpwebrequest]]></category>
		<category><![CDATA[ins]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[lt]]></category>
		<category><![CDATA[milliseconds]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[quick solution]]></category>
		<category><![CDATA[remote computer]]></category>
		<category><![CDATA[return result]]></category>
		<category><![CDATA[synchronous]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[unc]]></category>
		<category><![CDATA[unc path]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=687</guid>
		<description><![CDATA[I&#8217;m pretty sure all of you know the WebRequest and it&#8217;s derived class HttpWebRequest. And what a marvelous property both of them have &#8211; the TimeOut. Yesterday I had to write some app that reads files located on some remote computer. As I knew already this ins&#8217;t such a good practice, because your code can [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.7" /></div><div>Rating: 4.7/<strong>5</strong> (15 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/cshar-protected-internal/' rel='bookmark' title='Permanent Link: C# Protected Internal'>C# Protected Internal</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/' rel='bookmark' title='Permanent Link: C# LINQ Teaser'>C# LINQ Teaser</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pretty sure all of you know the WebRequest and it&#8217;s derived class HttpWebRequest.<br />
And what a marvelous property both of them have &#8211; the TimeOut.</p>
<p><span id="more-687"></span></p>
<p>Yesterday I had to write some app that reads files located on some remote computer.<br />
As I knew already this ins&#8217;t such a good practice, because your code can just hang/freeze for seconds waiting for that UNC path to become available or just checking it&#8217;s existence.</p>
<p>Still, I had to provide some quick solution and &#8220;hoping for the best&#8221; wasn&#8217;t good enough.<br />
So, this is what I came up with.</p>
<pre class="c-sharp" name="code">
        public static T Limex&lt;T&gt;(Func&lt;T&gt; F, int Timeout, out bool Completed)
        {
            T result = default(T);
            Thread thread = new Thread(() =&gt; result = F());
            thread.Start();
            Completed = thread.Join(Timeout);
            if (!Completed) thread.Abort();
            return result;
        }

        // Overloaded method, for cases when we don't
        // need to know if the method was terminated
        public static T Limex&lt;T&gt;(Func&lt;T&gt; F, int Timeout)
        {
            bool Completed;
            return Limex(F, Timeout, out Completed);
        }
</pre>
<p>The usage is very simple, just pass any method (declared or anonymous) and the desired Timeout in milliseconds to the Limex. </p>
<p>Example :</p>
<pre class="c-sharp" name="code">
bool Completed;
string Content = Limex(() => File.ReadAllText(@"\\unc\dir\file.ext")
                       ,100 // milliseconds
                       ,out Completed);

if (Completed)
   // Do something
else
  // Do something else
</pre>
<p>Comments and suggestions for improvement are welcome and will be gratefully appreciated</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.7" /></div><div>Rating: 4.7/<strong>5</strong> (15 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fcsharp-how-to-limit-method-execution-time%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/cshar-protected-internal/' rel='bookmark' title='Permanent Link: C# Protected Internal'>C# Protected Internal</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/' rel='bookmark' title='Permanent Link: C# LINQ Teaser'>C# LINQ Teaser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/csharp-how-to-limit-method-execution-time/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>C# Parsing HTML with HtmlAgilityPack</title>
		<link>http://kossovsky.net/index.php/2009/07/csharp-html-parser-htmlagilitypack/</link>
		<comments>http://kossovsky.net/index.php/2009/07/csharp-html-parser-htmlagilitypack/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 16:00:02 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[googling]]></category>
		<category><![CDATA[great library]]></category>
		<category><![CDATA[hn]]></category>
		<category><![CDATA[html document]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[mshtml]]></category>
		<category><![CDATA[optimizations]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[selectnodes]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[webbrowser control]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=508</guid>
		<description><![CDATA[Let&#8217;s say you have to parse some HTML, find all images or some other DOM elements make some changes/optimizations and save the result. What can you do ? Well, i needed something like that a few days ago and after Googling for couple of hours I ran across this this great library called HtmlAgilityPack. Sure, [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (11 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/' rel='bookmark' title='Permanent Link: C# Image Processing with AForge.NET Framework'>C# Image Processing with AForge.NET Framework</a></li>
<li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/string-empty-versus-empty-quotes/' rel='bookmark' title='Permanent Link: C# string.Empty vs &#8220;&#8221;'>C# string.Empty vs &#8220;&#8221;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you have to parse some HTML, find all images or some other DOM elements make some changes/optimizations and save the result. What can you do ?</p>
<p>Well, i needed something like that a few days ago and after Googling for couple of hours I ran across this this great library called <a href="http://htmlagilitypack.codeplex.com" target="_blank">HtmlAgilityPack</a>.</p>
<p><span id="more-508"></span></p>
<p>Sure, you can do it by using C# WebBrowser control or MSHTML, but you will have to forget about performance or multithreading &#8211; it will eat all your memory and the CPU won&#8217;t know what&#8217;s hit it.</p>
<p>Now, back to the HtmlAgilityPack.<br />
The usage is very simple, and the performance is great ( at least for my needs ).</p>
<p>Following is an example how we can find all images without an &#8220;alt&#8221; attribute, add it and resave the Html document.</p>
<pre class="c-sharp" name="code">
            HtmlDocument HD = new HtmlDocument();
            HD.Load (@"e:\test.htm");
            var NoAltElements = HD.DocumentNode.SelectNodes("//img[not(@alt)]");
            if (NoAltElements != null)
            {
                foreach (HtmlNode HN in NoAltElements)
                {
                    HN.Attributes.Append("alt", "no alt image");
                }
            }

            HD.Save(@"e:\test.htm");
</pre>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (11 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fcsharp-html-parser-htmlagilitypack%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/' rel='bookmark' title='Permanent Link: C# Image Processing with AForge.NET Framework'>C# Image Processing with AForge.NET Framework</a></li>
<li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/string-empty-versus-empty-quotes/' rel='bookmark' title='Permanent Link: C# string.Empty vs &#8220;&#8221;'>C# string.Empty vs &#8220;&#8221;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/csharp-html-parser-htmlagilitypack/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Javascript boolean interpretation</title>
		<link>http://kossovsky.net/index.php/2009/07/javascript-boolean-interpretation/</link>
		<comments>http://kossovsky.net/index.php/2009/07/javascript-boolean-interpretation/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 08:16:27 +0000</pubDate>
		<dc:creator>Maxim</dc:creator>
				<category><![CDATA[Browser]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[about true]]></category>
		<category><![CDATA[alert message]]></category>
		<category><![CDATA[boolean interpretation]]></category>
		<category><![CDATA[boolean values]]></category>
		<category><![CDATA[document write]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[javascript boolean]]></category>
		<category><![CDATA[javascript browser]]></category>
		<category><![CDATA[principle]]></category>
		<category><![CDATA[simple questions]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=613</guid>
		<description><![CDATA[How to deal with JavaScript boolean values, what will be evaluated as true and what as false !!!!.<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have two simple questions for you about boolean values in Javascript.<br />
When will  browser show alert message:</p>
<pre class="javascript" name="code">
        if (a-b) alert("it's true!");
</pre>
<p>And another one<br />
<span id="more-613"></span><br />
What will be printed as result of running this script:</p>
<pre class="javascript" name="code">
	for (var n=10; n; n-- )
	{
		document.write (n + ",");
	}
</pre>
<p>The answer for both questions relies on the same principle of what JavaScript engine will evaluate as true and what as false.</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=5.0" /></div><div>Rating: 5.0/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fjavascript-boolean-interpretation%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/javascript-boolean-interpretation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript pseudo protocol (is EVIL)</title>
		<link>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/</link>
		<comments>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 18:35:42 +0000</pubDate>
		<dc:creator>Maxim</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[href javascript]]></category>
		<category><![CDATA[javascript problems]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[script type]]></category>
		<category><![CDATA[span style]]></category>
		<category><![CDATA[style color]]></category>
		<category><![CDATA[style text]]></category>
		<category><![CDATA[text decoration]]></category>
		<category><![CDATA[text element]]></category>
		<category><![CDATA[text javascript]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[type javascript]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=586</guid>
		<description><![CDATA[This post is somehow related to my previous post about javascript function context.  Recently I helped one of my friends to debug a very funny problem. He told me that his inline event handler doen&#8217;t work, because he could not pass this object to his function. You probably wonder what did I find? &#60;script type="text/javascript"&#62; function [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
<li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This post is somehow related to my previous post about <a href="http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/" target="_blank">javascript function context</a>.  Recently I helped one of my friends to debug a very funny problem. He told me that his inline event handler doen&#8217;t work, because he could not pass <strong><em>this</em></strong> object to his function.<br />
You probably wonder what did I find? <img src='http://kossovsky.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<span id="more-586"></span></p>
<pre class="javascript" name="code">    &lt;script type="text/javascript"&gt;
        function doSomething(obj) {
            obj.style.color = '#cc0000';
        }
    &lt;/script&gt;
    &lt;a href="javascript:doSomething(this)"&gt;Link&lt;/a&gt;</pre>
<p><strong><em>this</em></strong> keyword in his case was not A object as expected but <strong><em>window</em></strong>.<br />
Having javascript:  in href attribute is like running JavaScript from address bar of your browser. It will run in <strong><em>window</em></strong> context.<br />
Only if my friend was writing his code like this:</p>
<pre class="javascript" name="code">   ...
    &lt;a onclick="doSomething(this)"&gt;Link&lt;/a&gt;</pre>
<p>it would work like charm.</p>
<p>But I never use <strong><em>javascript:</em></strong> at all in my markup. Why?<br />
1. If you need text element that is clickable use span, any visual styling like text-decoration or cursor can be achieved using CSS.<br />
2. If you don&#8217;t have actual link behind you shouldn&#8217;t use A tag. As far as I know it&#8217;s not good for SEO.<br />
3. Javascript problems as i described above can arise<br />
I would write the code above like this:</p>
<pre class="javascript" name="code">    ...
    &lt;span style="text-decoration:underline;cursor:pointer;"
                 onclick="doSomething(this)"&gt;Link&lt;/span&gt;</pre>
<p>The only reason I know to use A for JavaScript  triggers is to achieve hover effect without use of JavaScript.<br />
If you know another reason why you should/shouldn&#8217;t use links as JavaScript triggers you&#8217;re welcome to comment.<br />
After this post you can get an impression that I don&#8217;t like javascript: notation and you will be wrong,  actually there are very usefull tricks I use all the time:<br />
1. Check some JS value on your page. Type javascript:alert(yourvariable) in the address bar and press enter.<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/1.jpg" alt="" width="299" height="35" /></p>
<p>You will get :<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/2.jpg" alt="" width="187" height="134" /></p>
<p>2. Or let&#8217;s say you have function somewhere on the page and you have to see it quick without searching through all your scripts. Or you wan&#8217;t to <span style="text-decoration: line-through">steal</span> see how someone implemented something <img src='http://kossovsky.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
Just type  javascript:alert(yourdesiredfunction) and voila:<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/3.jpg" alt="" width="283" height="44" /></p>
<p><img src="http://kossovsky.net/wp-content/uploads/2009/07/4.jpg" alt="" width="260" height="140" /></p>
<p>UPD:<br />
Just googled good page with JS best practices, it has Javascript: pseudoprotocol part that says almost exactly the same as my conclusions.<br />
<a href="http://www.javascripttoolbox.com/bestpractices/">http://www.javascripttoolbox.com/bestpractices/</a></p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fjavascript-pseudo-protocol-is-evil%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
<li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C# LINQ Teaser</title>
		<link>http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/</link>
		<comments>http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 09:31:00 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Teasers]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[interview question]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[lt]]></category>
		<category><![CDATA[main string]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[Puzzle]]></category>
		<category><![CDATA[puzzles]]></category>
		<category><![CDATA[string args]]></category>
		<category><![CDATA[tezer]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[toarray]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=517</guid>
		<description><![CDATA[Another great interview question. Will the following code compile and if yes what will be the result of it ? static void Main(string[] args) { int[] array = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Func&#60;int, int&#62; func = i =&#62; { Console.Write(array[i]); return i; }; var result = array.Where(e =&#62; [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.8" /></div><div>Rating: 4.8/<strong>5</strong> (9 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/csharp-byte-iteration-question/' rel='bookmark' title='Permanent Link: C# Byte Iteration Question'>C# Byte Iteration Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-the-double-trouble/' rel='bookmark' title='Permanent Link: C# The &#8220;double&#8221; trouble'>C# The &#8220;double&#8221; trouble</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Another great interview question.</p>
<p>Will the following code compile and if yes what will be the result of it ?<br />
<span id="more-517"></span></p>
<pre class="c#" name="code">static void Main(string[] args)
{
    int[] array = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    Func&lt;int, int&gt; func = i =&gt; {
                          Console.Write(array[i]);
                          return i;
                     };

    var result = array.Where(e =&gt; e &lt;= func(2)).ToArray ();
}</pre>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.8" /></div><div>Rating: 4.8/<strong>5</strong> (9 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fcsharp-linq-teaser%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/csharp-byte-iteration-question/' rel='bookmark' title='Permanent Link: C# Byte Iteration Question'>C# Byte Iteration Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-the-double-trouble/' rel='bookmark' title='Permanent Link: C# The &#8220;double&#8221; trouble'>C# The &#8220;double&#8221; trouble</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</title>
		<link>http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/</link>
		<comments>http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 21:18:20 +0000</pubDate>
		<dc:creator>Maxim</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Callback]]></category>
		<category><![CDATA[fellow programmer]]></category>
		<category><![CDATA[javascript object]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[lame question]]></category>
		<category><![CDATA[request data]]></category>
		<category><![CDATA[script type]]></category>
		<category><![CDATA[server data]]></category>
		<category><![CDATA[solution number]]></category>
		<category><![CDATA[testthis]]></category>
		<category><![CDATA[text javascript]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=519</guid>
		<description><![CDATA[How many times you had problem or were asked about what happened to this object in your function? Or why this is not an object you expect it to be? Probably these times you have to remind yourself or your fellow programmer about function context. First of all I have to ask you all a [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (8 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-boolean-interpretation/' rel='bookmark' title='Permanent Link: Javascript boolean interpretation'>Javascript boolean interpretation</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How many times you had problem or were asked about what happened to <strong><em>this</em></strong> object in your function? Or why <strong><em>this</em></strong> is not an object you expect it to be? Probably these times you have to remind yourself or your fellow programmer about function context.<br />
First of all I have to ask you all a pretty lame question. If you write function in JS block right inside your HTML, what <strong><em>this</em></strong> keyword will refer to?</p>
<pre class="javascript" name="code">&lt;script type="text/javascript"&gt;
		function testThis(){
		  //who is "this"
		}
&lt;/script&gt;</pre>
<p>And now to the real example.<br />
<span id="more-519"></span><br />
Let’s say you build a simple Javascript object:</p>
<pre class="javascript" name="code">&lt;script type="text/javascript"&gt;
		var mathObj = {
			pi: 3.14,
			getCircumference : function(data) {
				alert(this.pi * 2 * data.radius);
			}
		}

		mathObj.getCircumference(10);
&lt;/script&gt;</pre>
<p>You have properties, you have functions, you can use <strong><em>this</em></strong> keyword to access properties of the object from its functions. Everyone is happy.<br />
Now we want to add function that will get some server data using AJAX and run one of the functions our object has.<br />
(To all who wondered what is $ stands for &#8211; I use JQuery framework in all my JS samples)</p>
<pre class="javascript" name="code">&lt;script type="text/javascript"&gt;
		var mathObj = {
			pi: 3.14,
			getCircumference : function(data) {
				alert(this.pi * 2 * data.radius);
			},
			getRemoteCircumference: function(url) {
				$.getJSON(url, this.getCircumference);
			}
		}

		mathObj.getRemoteCircumference("RadiusData.js");
&lt;/script&gt;</pre>
<p>If we have {&#8220;radius&#8221;:5} in RadiusData.js file you would expect the result of getCircumference would be 31.4 but you will get NaN. Why is that? Because <strong><em>this</em></strong> keyword in this case will refer to some kind of object with request data returned by JQuery. What can you do?<br />
Solution number one is to use your object name:</p>
<pre class="javascript" name="code">...
	getCircumference : function(data) {
		alert(mathObj.pi * 2 * data.radius);
	}
...</pre>
<p>Ugly. You don&#8217;t have to return on object name in every function.<br />
Solution number two is to use anonymous function and explicitly call your function:</p>
<pre class="javascript" name="code">
....
	getRemoteCircumference: function(url) {
		$.getJSON(url, function(data){
			mathObj.getCircumference(data);
		});
	}
...
</pre>
<p>Good enough solution, but again I don&#8217;t like reusing object name&#8230;<br />
And now to my favorite solution.</p>
<pre class="javascript" name="code">&lt;script type="text/javascript"&gt;
   function getContextFunc(context, func) {
       return function() {
           func.apply(context, arguments);
       };
   }

   var mathObj = {
       pi: 3.14,
       getCircumference: function(data) {
           alert(this.pi * 2 * data.radius);
       },
       getRemoteCircumference: function(url) {
          $.getJSON(url, getContextFunc(this, this.getCircumference));
       }
   }

   mathObj.getRemoteCircumference("RadiusData.js");
&lt;/script&gt;</pre>
<p>Here apply function will come in handy. <strong><em>getContextFunc</em></strong> returns anonymous function that will run our original method in given context.<br />
<a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/apply">See some documentation</a></p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (8 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Ffunction-context-and-apply-function%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-boolean-interpretation/' rel='bookmark' title='Permanent Link: Javascript boolean interpretation'>Javascript boolean interpretation</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/script-as-blocking-element-and-dynamic-script-loading-using-document-write/' rel='bookmark' title='Permanent Link: Script as blocking element and dynamic script loading using document.write'>Script as blocking element and dynamic script loading using document.write</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>IE Memory Leak &#8211; jQuery Fix</title>
		<link>http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/</link>
		<comments>http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 08:37:12 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[filter selector]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[html contents]]></category>
		<category><![CDATA[html elements]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[IE7]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[javascript functions]]></category>
		<category><![CDATA[jQuery Plugin]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[nyromodal]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[virtual memory]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=489</guid>
		<description><![CDATA[I suppose all of you have suffered all those terrible memory leaks in Internet Explorer. Sometimes it&#8217;s bearable, but most of the time it&#8217;s not. I say enough is enough ! A couple of days ago, I had to create some web application with a very rich client side UI. It worked like a charm [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.3" /></div><div>Rating: 4.3/<strong>5</strong> (13 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I suppose all of you have suffered all those terrible memory leaks in Internet Explorer.<br />
Sometimes it&#8217;s bearable, but most of the time it&#8217;s not. I say enough is enough !</p>
<p><span id="more-489"></span></p>
<p>A couple of days ago, I had to create some web application with a very rich client side UI.<br />
It worked like a charm in Google Chrome, Firefox&#8230; but IE7, after few dozens of nyroModal popups it just went dead. </p>
<p>Most of the styles are gone, JavaScript functions began to throw exceptions till it just stoped working, decided it can&#8217;t tolerate this kind of abuse any more and closed it self without any warning.</p>
<p>The first thing i did is to open Performance Monitor and what I see&#8230; every nyroModal popup i open cost me about 5Mb, so after a few clicks my IE7 virtual memory was about 789Mb. Terrifying, isn&#8217;t it ?</p>
<p><img src="http://kossovsky.net/wp-content/uploads/2009/07/IE7MemoryLeak.gif" alt="IE7 Memory Leak" title="IE7 Memory Leak" width="426" height="130" class="size-full wp-image-490" /></p>
<p>I&#8217;ve searched a bit and found the source of this problem was in one (of many) memory leaks IE7 proudly has &#8211; cleaning memory for removed HTML elements.</p>
<p>And now the fix.</p>
<p>1). Open your jQuery.js and find the next lines of code</p>
<pre class="javascript" name="code">
    jQuery.extend({
        cache: {},
</pre>
<p>and add new function &#8220;discardElement&#8221;</p>
<pre class="javascript" name="code">
    jQuery.extend({
        cache: {},

        discardElement: function(element) {
            var jqGCID = 'jqGarbageCollector';
            var jqGC = document.getElementById(jqGCID);
            if (!jqGC) {
                jqGC = document.createElement('div');
                jqGC.id = jqGCID;
                jqGC.style.display = 'none';
                document.body.appendChild(jqGC);
            }

            // place the element to the Garbage Collector
            // and clear it's HTML contents
            jqGC.appendChild(element);
            jqGC.innerHTML = '';
        },
</pre>
<p>2). Find the next lines of code in the opened jquery.js </p>
<pre class="javascript" name="code">
	remove: function( selector ) {
		if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
			// Prevent memory leaks
			jQuery( "*", this ).add([this]).each(function(){
				jQuery.event.remove(this);
				jQuery.removeData(this);
			});
			if (this.parentNode)
				this.parentNode.removeChild( this );
		}
	},
</pre>
<p>and replace &#8220;this.parentNode.removeChild( this );&#8221;<br />
with &#8220;jQuery.discardElement(this);&#8221;</p>
<pre class="javascript" name="code">
	remove: function( selector ) {
		if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
			// Prevent memory leaks
			jQuery( "*", this ).add([this]).each(function(){
				jQuery.event.remove(this);
				jQuery.removeData(this);
			});
			if (this.parentNode)
				// this.parentNode.removeChild( this );
				jQuery.discardElement(this);
		}
	},
</pre>
<p>That&#8217;s it, now you (and every plugin) can do $(&#8216;element&#8217;).remove() without being worry IE will eat all of your memory.</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.3" /></div><div>Rating: 4.3/<strong>5</strong> (13 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fie-memory-leak-jquery-garbage-collector%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/' rel='bookmark' title='Permanent Link: jTemplates &#8211; jQuery Template Engine'>jTemplates &#8211; jQuery Template Engine</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/' rel='bookmark' title='Permanent Link: Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object'>Javascript function context, &#8220;apply&#8221; method and lost &#8220;this&#8221; object</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/' rel='bookmark' title='Permanent Link: Javascript pseudo protocol (is EVIL)'>Javascript pseudo protocol (is EVIL)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/ie-memory-leak-jquery-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>C# Byte Iteration Question</title>
		<link>http://kossovsky.net/index.php/2009/07/csharp-byte-iteration-question/</link>
		<comments>http://kossovsky.net/index.php/2009/07/csharp-byte-iteration-question/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 08:27:34 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Teasers]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[byte]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[interview question]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[main string]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[string args]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=473</guid>
		<description><![CDATA[This one is a great c# interview question &#8211; short and simple, but tricky. static void Main(string[] args) { for (byte b = byte.MinValue; b<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.4" /></div><div>Rating: 4.4/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/' rel='bookmark' title='Permanent Link: C# LINQ Teaser'>C# LINQ Teaser</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-increment-operator-question/' rel='bookmark' title='Permanent Link: C# Increment operator (++) question'>C# Increment operator (++) question</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This one is a great c# interview question &#8211; short and simple, but tricky.</p>
<p><span id="more-473"></span></p>
<pre class="c-sharp" name="code">
static void Main(string[] args)
{
    for (byte b = byte.MinValue; b <= byte.MaxValue; b++)
        Console.Write(b);
}

// A little tip
// byte.MinValue = 0
// byte.MaxValue = 255
</pre>
<p>How many times the above statement will be executed ?</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.4" /></div><div>Rating: 4.4/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fcsharp-byte-iteration-question%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-linq-teaser/' rel='bookmark' title='Permanent Link: C# LINQ Teaser'>C# LINQ Teaser</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/csharp-increment-operator-question/' rel='bookmark' title='Permanent Link: C# Increment operator (++) question'>C# Increment operator (++) question</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/csharp-byte-iteration-question/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>C# Image Processing with AForge.NET Framework</title>
		<link>http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/</link>
		<comments>http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 21:35:20 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[computer vision library]]></category>
		<category><![CDATA[genetic evolution]]></category>
		<category><![CDATA[Gif]]></category>
		<category><![CDATA[grayscale image]]></category>
		<category><![CDATA[grayscale images]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[image edges]]></category>
		<category><![CDATA[imaging library]]></category>
		<category><![CDATA[Jpg]]></category>
		<category><![CDATA[machine learning library]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[Png]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Resize]]></category>
		<category><![CDATA[Resizer]]></category>
		<category><![CDATA[robotics kits]]></category>
		<category><![CDATA[robotics library]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[vision computer]]></category>
		<category><![CDATA[visual c#]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=436</guid>
		<description><![CDATA[AForge.NET is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence - image processing, neural networks, genetic algorithms, machine learning, robotics, etc.<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.4" /></div><div>Rating: 4.4/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />


Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/image-resizing/' rel='bookmark' title='Permanent Link: Image Resizing in C#'>Image Resizing in C#</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/cshar-rectangle-packing/' rel='bookmark' title='Permanent Link: C# Rectangle Packing'>C# Rectangle Packing</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago i found a great framework called AForge.NET.</p>
<p><a title="AForge.NET" href="http://www.aforgenet.com/framework/" target="_blank">AForge.NET</a> is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence &#8211; image processing, neural networks, genetic algorithms, machine learning, robotics, etc.</p>
<p><span id="more-436"></span></p>
<p>The framework is published under <a title="GNU LESSER GENERAL PUBLIC LICENSE" href="http://www.gnu.org/licenses/lgpl.html" target="_blank">LGPL v3 license</a> and comprised by the set of libraries and sample applications, which demonstrate their features:</p>
<ul>
<li>AForge.Imaging &#8211; library with image processing routines and filters</li>
<li>AForge.Vision &#8211; computer vision library</li>
<li>AForge.Neuro &#8211; neural networks computation library</li>
<li>AForge.Genetic &#8211; evolution programming library</li>
<li>AForge.MachineLearning &#8211; machine learning library</li>
<li>AForge.Robotics &#8211; library providing support of some robotics kits</li>
<li>AForge.Video &#8211; set of libraries for video processing</li>
</ul>
<p>The framework is provided not only with different libraries and their sources, but with many sample applications, which demonstrate the use of this framework, and with documentation help files, which are provided in HTML Help format.</p>
<p>As you can see this framework contains varied libraries, but as for me i was especially interested in the image processing routines and filters.</p>
<p>Let&#8217;s see  the  CannyEdgeDetector in action.</p>
<pre class="c-sharp" name="code">using AForge.Imaging.Filters;

// Loading some file
using (Bitmap SampleImage = (Bitmap)Image.FromFile("test.jpg"))
{
    // We must convert it to grayscale because
    // the filter accepts 8 bpp grayscale images
    Grayscale GF = new Grayscale(0.2125, 0.7154, 0.0721);
    using (Bitmap GSampleImage = GF.Apply(SampleImage))
    {
        // Saving the grayscale image, so we could see it later
        GSampleImage.SaveAsJpeg("testBW.jpg", 100);

        // Detecting image edges and saving the result
        CannyEdgeDetector CED = new CannyEdgeDetector(0,70);
        CED.ApplyInPlace(GSampleImage);
        GSampleImage.SaveAsJpeg("testEDGED.jpg",100);
    }
}

// SaveAsJpeg is an extension method i wrote to be able to save
// Jpeg images with parametrized quality
// You can use Image.Save ("image.jpg", ImageFormat.Jpeg) instead
</pre>
<p>Now, let see the results ( click the image to see full size )</p>

<a href='http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/aforgesamples/' title='The original image [ AForge Test ]'><img width="150" height="150" src="http://kossovsky.net/wp-content/uploads/2009/07/AForgeSamples-150x150.jpg" class="attachment-thumbnail" alt="The original image" title="The original image [ AForge Test ]" /></a>
<a href='http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/aforgesamplesgrayscale/' title='Grayscaled image [ AForge Test ]'><img width="150" height="150" src="http://kossovsky.net/wp-content/uploads/2009/07/AForgeSamplesGrayscale-150x150.jpg" class="attachment-thumbnail" alt="Grayscaled image" title="Grayscaled image [ AForge Test ]" /></a>
<a href='http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/aforgesamplesresult/' title='Edged image [ AForge Test ]'><img width="150" height="150" src="http://kossovsky.net/wp-content/uploads/2009/07/AForgeSamplesResult-150x150.jpg" class="attachment-thumbnail" alt="Edged image" title="Edged image [ AForge Test ]" /></a>

<p>The result is great, and of course we can modify the threshold levels to gain even better results.<br />
As for other filter and effects there are many of them in this library.<br />
There are Noise generators, color correction filters, smoothing filters and <a title="AForge.Imaging filters and effects" href="http://www.aforgenet.com/framework/features/" target="_blank">more</a>.</p>
<p>Sure, it&#8217;s no Photoshop, but i must say it&#8217;s very close to it.</p>
<p>Hope you will find this useful, I did.</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.4" /></div><div>Rating: 4.4/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Faforge-net-image-processing%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>


<p>Related posts:<ol><li><a href='http://kossovsky.net/index.php/2009/06/image-resizing/' rel='bookmark' title='Permanent Link: Image Resizing in C#'>Image Resizing in C#</a></li>
<li><a href='http://kossovsky.net/index.php/2009/07/cshar-rectangle-packing/' rel='bookmark' title='Permanent Link: C# Rectangle Packing'>C# Rectangle Packing</a></li>
<li><a href='http://kossovsky.net/index.php/2009/06/csharp-inheritance-question/' rel='bookmark' title='Permanent Link: C# Inheritance Question'>C# Inheritance Question</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/aforge-net-image-processing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
