<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>{Dev Tricks}</title>
	
	<link>http://dev-tricks.net</link>
	<description>Blogging developper tips and tricks</description>
	<lastBuildDate>Sun, 30 Aug 2009 00:14:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/devTricks" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Post data lost on 301 Moved Permanently</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/NAXeQyi_yLY/post-data-lost-on-301-moved-permanently</link>
		<comments>http://dev-tricks.net/post-data-lost-on-301-moved-permanently#comments</comments>
		<pubDate>Fri, 15 May 2009 10:50:05 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=227</guid>
		<description><![CDATA[What the hell with 301 Moved Permanently HTTP header  !?
I&#8217;ll take an exemple to explain my ugly problem, take, a [very ugly cause it's PHP] index.php, it could be retrieved by using :
http://example.com/directory/index.php
  -> Got the page, 200 OK
or http://example.com/directory/
  -> Got the page, 200 OK
or http://example.com/directory
  -> Got a 301 [...]]]></description>
			<content:encoded><![CDATA[<p>What the hell with 301 Moved Permanently HTTP header  !?</p>
<p>I&#8217;ll take an exemple to explain my ugly problem, take, a [very ugly cause it's PHP] index.php, it could be retrieved by using :<br />
http://example.com/directory/index.php<br />
  -> Got the page, 200 OK<br />
or http://example.com/directory/<br />
  -> Got the page, 200 OK<br />
or http://example.com/directory<br />
  -> Got a 301 Moved Permanently Location: http://example.com/directory/</p>
<p>Just like expected &#8230; but&#8230;</p>
<p>As you can see, on the captured HTTP headers below, when you POST data on a 301 target, you&#8217;ll be redirected, but unfortunately you&#8217;ll lost your POST data, even worse, your request can be reforged as a GET request !</p>
<p><span id="more-227"></span><br />
Let me show you an example :<br />
Request :</p>
<blockquote><p>POST /directory HTTP/1.1<br />
Host: example.com<br />
[user agent, referer, cache control, origin, content type, accept, accept-encoding, blah blah ...]<br />
Content-Length: 7</p>
<p>foo=bar</p></blockquote>
<p>Response :</p>
<blockquote><p>HTTP/1.0 301 Moved Permanently<br />
Location: http://example.com/directory/<br />
[... blah blah]</p></blockquote>
<p>Reforged request :</p>
<blockquote><p>GET /directory/ HTTP/1.1<br />
Host: example.com</p></blockquote>
<p>Why my data isn&#8217;t kept in the reforged one !?</p>
<p>So let&#8217;s read The RFC 2616 (about HTTP &#8230;)</p>
<blockquote><p>
10.3.2 301 Moved Permanently</p>
<p>   [...]</p>
<p>   The new permanent URI SHOULD be given by the Location field in the<br />
   response. Unless the request method was HEAD, the entity of the<br />
   response SHOULD contain a short hypertext note with a hyperlink to<br />
   the new URI(s).</p>
<p>   If the 301 status code is received in response to a request other<br />
   than GET or HEAD, the user agent MUST NOT automatically redirect the<br />
   request unless it can be confirmed by the user, since this might<br />
   change the conditions under which the request was issued.</p>
<p>      Note: When automatically redirecting a POST request after<br />
      receiving a 301 status code, some existing HTTP/1.0 user agents<br />
      will erroneously change it into a GET request.
</p></blockquote>
<p>Ahh, ok, so, for request other than GET or HEAD, the user agent MUST NOT automatically redirect to the request ? Ugh, it&#8217;s not the case in IE 6, 7, 8, Firefox, nor Chrome.<br />
And, about the security, while the server recieves the data, it can do everything, for example send it to another server directly.<br />
 Then I&#8217;m wondering, why asking to the user if he allows his data to be transfered ?</p>
<p>Then, the RFC says an interesting thing &#8230;</p>
<blockquote><p>
      Note: When automatically redirecting a POST request after<br />
      receiving a 301 status code, some existing HTTP/1.0 user agents<br />
      will erroneously change it into a GET request.
</p></blockquote>
<p>But, not only HTTP/1.0 user agents, but HTTP/1.1 user agents like browsers and frameworks (as, I encountred the problem firstly in the .NET Framework 3.5, in HttpWebRequest) )o:</p>
<p>OK, end of this article, have a nice day )o&#8217;,:</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/post-data-lost-on-301-moved-permanently/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/post-data-lost-on-301-moved-permanently</feedburner:origLink></item>
		<item>
		<title>Integrating google bookmarks in google chrome</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/LxPZERFkEJY/integrating-google-bookmarks-in-google-chrome</link>
		<comments>http://dev-tricks.net/integrating-google-bookmarks-in-google-chrome#comments</comments>
		<pubDate>Thu, 16 Apr 2009 15:56:18 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=223</guid>
		<description><![CDATA[As every developer, you have 42 computers, 8 browsers, and spent a lot of time asking why google chrome does not integrate google bookmarks ?

Here is a solution :
First add the &#8220;Add to Google Bookmarks&#8221; bookmarklet found here
http://www.google.com/support/chrome/bin/answer.py?hl=en&#038;answer=100215
And then go to chrome&#8217;s options -> base tab -> Default search engine -> Manage
Click &#8220;Add&#8221; and fill [...]]]></description>
			<content:encoded><![CDATA[<p>As every developer, you have 42 computers, 8 browsers, and spent a lot of time asking why google chrome does not integrate google bookmarks ?<br />
<span id="more-223"></span><br />
Here is a solution :<br />
First add the &#8220;Add to Google Bookmarks&#8221; bookmarklet found here<br />
<a href="http://www.google.com/support/chrome/bin/answer.py?hl=en&#038;answer=100215">http://www.google.com/support/chrome/bin/answer.py?hl=en&#038;answer=100215</a><br />
And then go to chrome&#8217;s options -> base tab -> Default search engine -> Manage<br />
Click &#8220;Add&#8221; and fill :<br />
Name : Google Bookmarks<br />
Keyword : The keyword you wanna enter before a bookmark search in the chrome&#8217;s address bar (to search 42, if your keyword is, like mine &#8216;b&#8217;, type &#8220;b 42&#8243; in the chrome&#8217;s address bar and 42 will be searched in your bookmarks)<br />
URL : http://www.google.com/bookmarks/find?q=%s</p>
<p>Enjoy !</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/integrating-google-bookmarks-in-google-chrome/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/integrating-google-bookmarks-in-google-chrome</feedburner:origLink></item>
		<item>
		<title>C# Using alias directives</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/H_Xz26EY00Q/c-sharp-using-alias-directives</link>
		<comments>http://dev-tricks.net/c-sharp-using-alias-directives#comments</comments>
		<pubDate>Wed, 25 Mar 2009 09:49:50 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=218</guid>
		<description><![CDATA[Just found in section 9.4.1 of the C# language specification :
The using keyword can be used to alias a namespace or a type name :
using-alias-directive:
using   identifier   =   namespace-or-type-name   ;

You can read more about that here : csharp language specification.doc
Or just try to use it :

// As the [...]]]></description>
			<content:encoded><![CDATA[<p>Just found in section 9.4.1 of the C# language specification :<br />
The <em>using</em> keyword can be used to alias a namespace or a type name :</p>
<p><em>using-alias-directive:<br />
using   identifier   =   namespace-or-type-name   ;</em></p>
<p><span id="more-218"></span><br />
You can read more about that here : <a href="http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/csharp%20language%20specification.doc">csharp language specification.doc</a></p>
<p>Or just try to use it :</p>
<pre class="vsh_code">
<span class="Comment">// As the specification show it :</span>
<span class="Type">namespace</span> N1.N2
{
                <span class="Type">class</span> A {}
}
<span class="Type">namespace</span> N3
{
                <span class="Statement">using</span> A = N1.N2.A;
                <span class="Type">class</span> B: A {}
}

<span class="Comment">// My foobar exemple :</span>
<span class="Type">namespace</span> Foo
{
                <span class="Statement">using</span> Bar = Dictionary&lt;<span class="Type">string</span>, <span class="Type">string</span>&gt;;
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/using_alias/ex.cs">ex.cs</a></p>
<p>Enjoy !</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/c-sharp-using-alias-directives/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/c-sharp-using-alias-directives</feedburner:origLink></item>
		<item>
		<title>Covariance and Contravariance in C#3</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/70j2hAVgodc/covariance-and-contravariance-in-c-sharp-3</link>
		<comments>http://dev-tricks.net/covariance-and-contravariance-in-c-sharp-3#comments</comments>
		<pubDate>Mon, 09 Mar 2009 19:19:51 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=203</guid>
		<description><![CDATA[A short introduction to Covariance and Contravariance in C# 3 preparing you to an article about that in C# 4.
So what is covariance ?
Covariance is basically using a method which returns something derived from the expected type.
An exemple ? It&#8217;s safe to have a method returning a cat when you expect it to return an [...]]]></description>
			<content:encoded><![CDATA[<p>A short introduction to Covariance and Contravariance in C# 3 preparing you to an article about that in C# 4.<br />
So what is covariance ?<br />
Covariance is basically using a method which returns something derived from the expected type.</p>
<p>An exemple ? It&#8217;s safe to have a method returning a cat when you expect it to return an animal.<br />
<span id="more-203"></span><br />
In C sharp it&#8217;s</p>
<pre class="vsh_code">
<span class="Type">public</span> <span class="Type">class</span> Animal
{
}

<span class="Type">public</span> <span class="Type">class</span> Cat : Animal
{
}

<span class="Type">public</span> <span class="Type">class</span> Dog : Animal
{
}

<span class="Comment">// It's safe to say that something returns a Animal when in fact this thing returns a Cat</span>
<span class="Type">class</span> Covariance
{
        <span class="Type">void</span> test()
        {
                Func&lt;Animal&gt; a = Method; <span class="Comment">// OK</span>
                Func&lt;Animal&gt; b = <span class="Type">delegate</span> { <span class="Statement">return</span> <span class="Statement">new</span> Cat(); }; <span class="Comment">// OK</span>
                Func&lt;Animal&gt; c = () =&gt; <span class="Statement">new</span> Cat(); <span class="Comment">// OK</span>
        }

        Cat Method()
        {
                <span class="Statement">return</span> <span class="Statement">new</span> Cat();
        }
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/covariance_contravariance/covariance.cs">covariance.cs</a></p>
<p>So Funcs a, b, and c are returning animals which in fact are cats, which is true.</p>
<p>And, what is contravariance ?<br />
Contravariance is basically using a method which takes something which is a parent of the expected type.<br />
An exemple ? It&#8217;s safe to have a method taking an animal when you expect it to take a cat</p>
<pre class="vsh_code">
<span class="Comment">// It's safe to say that something can take a Cat if in fact this thing can take any Animal</span>
<span class="Type">class</span> Contravariance
{
        <span class="Type">static</span> <span class="Type">void</span> test()
        {
                Action&lt;Cat&gt; a = Method; <span class="Comment">// OK</span>
                Action&lt;Cat&gt; b = <span class="Type">delegate</span>(Animal <span class="Statement">value</span>) { }; <span class="Comment">// ERROR</span>
                <span class="Comment">// From C#3 Specification :</span>
                <span class="Comment">// $7.14.1 Anonymous function signatures :</span>
                <span class="Comment">// [...] contra-variance of anonymous function parameter types is not supported.</span>
                Action&lt;Cat&gt; d = (Animal <span class="Statement">value</span>) =&gt; { }; <span class="Comment">// idem... anonymous... not supported.</span>
        }

        <span class="Type">public</span> <span class="Type">static</span> <span class="Type">void</span> Method(Animal <span class="Statement">value</span>)
        {
        }
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/covariance_contravariance/contravariance.cs">contravariance.cs</a></p>
<p>So Action a take Cats, but in fact can take any Animals, so it&#8217;s safe.  </p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/covariance-and-contravariance-in-c-sharp-3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/covariance-and-contravariance-in-c-sharp-3</feedburner:origLink></item>
		<item>
		<title>Silverlight Tutorial – Flashlight Tutorial</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/-DAIMdHGUe8/silverlight-flashlight-tutorial</link>
		<comments>http://dev-tricks.net/silverlight-flashlight-tutorial#comments</comments>
		<pubDate>Mon, 19 Jan 2009 20:48:13 +0000</pubDate>
		<dc:creator>Antoine Angot</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[blend]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=80</guid>
		<description><![CDATA[How to make a flashlight effect with silverlight ?
&#160;
&#160;

&#160;
&#160;


What you need :
&#160;
 be familiar with Blend
 be familiar with Visual Studio
 half an hour


&#160;
&#160;
&#160;
Introduction
&#160;
Many years ago, a friend taught me how to make a flash light effect with flash.
You probably saw it in many tutorials.
&#160;
&#160;

&#160;
Today, we will try to do better with silverlight :)
&#160;
&#160;
&#160;
The Blend [...]]]></description>
			<content:encoded><![CDATA[<p>How to make a flashlight effect with silverlight ?<br />
&nbsp;<br />
&nbsp;<br />
<iframe frameborder="no" height="300" width="400" src="http://oa.mandark.fr/blog/flashlight/Default.html"></iframe><br />
&nbsp;<br />
&nbsp;<br />
<span id="more-80"></span></p>
<ul>
<strong>What you need :</strong><br />
&nbsp;</p>
<li> be familiar with Blend</li>
<li> be familiar with Visual Studio</li>
<li> half an hour</li>
</ul>
<ul>
&nbsp;<br />
&nbsp;<br />
&nbsp;</p>
<h3>Introduction</h3>
<p>&nbsp;<br />
Many years ago, a friend taught me <strong>how to make a flash light effect with flash</strong>.<br />
You probably saw it in many <a href="http://oa.mandark.fr/blog/flashlight/swf.swf">tutorials</a>.<br />
&nbsp;<br />
&nbsp;<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="250"><param name="movie" value="http://oa.mandark.fr/blog/flashlight/swf.swf"><param name="quality" value="high"><embed src="http://www.newtutorials.com/flashlight/flashlight-6.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="250"></embed></object><br />
&nbsp;<br />
Today, we will try to do better with silverlight :)</p>
<p>&nbsp;<br />
&nbsp;<br />
&nbsp;</p>
<h3>The Blend Part</h3>
<p>&nbsp;</p>
<ol>
<h4>Create a new project</h4>
</ol>
<p>&nbsp;<br />
<img src="http://dev-tricks.net/wp-content/uploads/2009/01/1-300x181.jpg" alt="I’m doing it with Blend, but you can use Visual Studio if you want. " title="Create a silverlight project" width="400" class="size-medium wp-image-132" /></p>
<ol>
<em>I&#8217;m doing it with Blend, but you can use Visual Studio if you want. </em></ol>
<p>&nbsp;<br />
&nbsp;</p>
<ol>
<h4>Add an image</h4>
</ol>
<p>&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/a.JPG" width="200"></p>
<ol>
<em>Add it to the project.</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/2.JPG"></p>
<ol>
<em>Resize the image to give it the same size that the LayoutRoot</em></ol>
<p>&nbsp;<br />
&nbsp;</p>
<ol>
<h4>Draw a rectangle</h4>
</ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/b.JPG" width="200"></p>
<ol>
<em>select the tool</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/3.JPG" width="400"></p>
<ol>
<em>You should get this.</em></ol>
<p>&nbsp;<br />
&nbsp;</p>
<ol>
<h4>Gradient Brush and Radial Gradient</h4>
</ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/c.JPG"></p>
<ol>
<em>Set up the rectangle background as a gradientbrush</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/d.JPG"></p>
<ol>
<em>And click on the radial gradient option</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/4.JPG"></p>
<ol>
<em>You rectangle should look like this.</em></ol>
<p>&nbsp;<br />
&nbsp;</p>
<ol>
<h4>Transparency</h4>
</ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/e.JPG"></p>
<ol>
<em>Set the first gradiant to black</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/f.JPG"></p>
<ol>
<em>For the other one, same color but set transparenrcy to half</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/5.JPG"></p>
<ol>
<em>We begin to see the final result</em></ol>
<ol>
&nbsp;<br />
&nbsp;</p>
<h4>Draw your Flashlight</h4>
</ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/g.JPG"></p>
<ol>
<em>Play with gradiant and try to make something which looks like a light.</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/6.JPG"></p>
<ol>
<em>Here is the artistical part :)</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/h.JPG"></p>
<ol>
<em>Well, i think i&#8217;m fine.</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/7.JPG"></p>
<ol>
<em>For me, it looks like this.</em></ol>
<p>&nbsp;<br />
&nbsp;</p>
<ol>
<h4>Transform the Brush</h4>
</ol>
<p>&nbsp;<br />
&nbsp;<br />
if you want to be able to move, you have to enlarge the brush.<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/i.JPG"></p>
<ol>
<em>Select the &#8220;Brush Transform&#8221; tool.</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
<img src="http://oa.mandark.fr/blog/flashlight/8.JPG"></p>
<ol>
<em>Resize the brush to about one and half.</em></ol>
<p>&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;</p>
<h3>The Visual Studio part</h3>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Ok this part is ridiculous you have to add a method in FlashLight.xaml.cs to register mouse move.<br />
&nbsp;</p>
<pre class="vsh_code">
<span class="Type">namespace</span> FlashLight
{
    <span class="Type">public</span> <span class="Statement">partial</span> <span class="Type">class</span> Page : UserControl
    {
        <span class="Type">public</span> Page()
        {
            <span class="Comment">// Required to initialize variables</span>
            InitializeComponent();
            LayoutRoot.MouseMove += <span class="Statement">new</span> MouseEventHandler(LayoutRoot_MouseMove);
        }

        <span class="Type">void</span> LayoutRoot_MouseMove(<span class="Type">object</span> sender, MouseEventArgs e)
        {
            Point newPosition = e.GetPosition(<span class="Statement">this</span>);
            RadialGradientBrush radialGradient = (RadialGradientBrush)Light.Fill;
            radialGradient.GradientOrigin = <span class="Statement">new</span> Point(newPosition.X / <span class="Constant">640</span>, newPosition.Y / <span class="Constant">400</span>);
            Light.Fill = radialGradient;
        }
    }
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/FlashLight/FlashLight.cs">FlashLight.cs</a></p>
<p>&nbsp;<br />
&nbsp;<br />
&nbsp;</p>
<h3>Conclusion</h3>
<p>&nbsp;<br />
&nbsp;<br />
Actually, i&#8217;m pretty sure that you can do the same with the last version of Flash but this tutorial is a good exercise to practice with Blend.<br />
Thanks for reading. You can download the <strong> source code </strong> <a href="http://oa.mandark.fr/blog/flashlight/FlashLight.zip">here</a>.<br />
&nbsp;<br />
&nbsp;
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/silverlight-flashlight-tutorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/silverlight-flashlight-tutorial</feedburner:origLink></item>
		<item>
		<title>Silverlight Custom Control – II : Properties</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/R04xinxf-O0/silverlight-custom-control-properties</link>
		<comments>http://dev-tricks.net/silverlight-custom-control-properties#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:14:44 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=78</guid>
		<description><![CDATA[This is the second part of my serie about creating Custom Controls, if you missed the first, you should read it : Part I
In this Part, we&#8217;ll speak about Custom Control&#8217;s properties : How to databind a template property to an exposed property, and how to create new exposed properties.

The idea is to expose properties [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of my serie about creating Custom Controls, if you missed the first, you should read it : <a href="http://dev-tricks.net/silverlight-custom-control-i">Part I</a></p>
<p>In this Part, we&#8217;ll speak about Custom Control&#8217;s properties : How to databind a template property to an exposed property, and how to create new exposed properties.</p>
<p><span id="more-78"></span><br />
The idea is to expose properties of your custom control to its users, as your custom control is inheriting another, its basically exposes the sames, in the previous article, we got<br />
public class EditableTextBlock : Control<br />
so our EditableTextBlock exposes Width, Height, Background &#8230;</p>
<p>But setting EditableTextBlock&#8217;s Background to Red does not affects the Grid&#8217;s Background Property (setted to AliceBlue) in the Template (generic.xaml), you can try it :</p>
<pre class="vsh_code">
&lt;ctrl:EditableTextBlock Background=&quot;Red&quot;&gt;&lt;/ctrl:EditableTextBlock&gt;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_2/Page.part.xaml">Page.part.xaml</a></p>
<p>The control stay in AliceBlue &#8230;</p>
<p>At this point you can use some DataBinding to link the value of a property in your control template to the value of some exposed property of its parent, to do this, in generic.xaml, the Grid&#8217;s Background property must be Binded to the exposed Background Property :</p>
<pre class="vsh_code">
&lt;ResourceDictionary
  xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>&quot;
  xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>&quot;
  xmlns:controls=&quot;clr-namespace:Custom_Control_1&quot;&gt;
    &lt;Style TargetType=&quot;controls:EditableTextBlock&quot;&gt;
        &lt;Setter Property=&quot;Template&quot;&gt;
            &lt;Setter.Value&gt;
                &lt;ControlTemplate TargetType=&quot;controls:EditableTextBlock&quot;&gt;
                    &lt;Grid Background=&quot;{TemplateBinding Background}&quot;&gt;
                    &lt;/Grid&gt;
                &lt;/ControlTemplate&gt;
            &lt;/Setter.Value&gt;
        &lt;/Setter&gt;
    &lt;/Style&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_2/generic.xaml">generic.xaml</a></p>
<p>Now, the Grid&#8217;s Background is binded to the exposed Background !</p>
<p>How to create a new property ?<br />
You have to use a DependencyProperty to expose your property :<br />
Basically, a DependencyPorperty look like this :</p>
<pre class="vsh_code">
<span class="Comment">// Replace [TYPE] with your property type</span>
<span class="Comment">// Replace [NAME] with your property name</span>
<span class="Type">public</span> [TYPE] [NAME]
{
    <span class="Statement">get</span>
    {
        <span class="Statement">return</span> ([TYPE])GetValue([NAME]Property);
    }
    <span class="Statement">set</span>
    {
        SetValue([NAME]Property, <span class="Statement">value</span>);
    }
}

<span class="Type">public</span> <span class="Type">static</span> <span class="Type">readonly</span> DependencyProperty [NAME]Property = DependencyProperty.Register(<span class="Constant">&quot;[NAME]&quot;</span>, <span class="Statement">typeof</span>([TYPE]), <span class="Statement">typeof</span>(EditableTextBlock), <span class="Statement">new</span> PropertyMetadata([DEPEND ON THE TYPE]);
<span class="Comment">// For more informations about PropertyMetadata and DependencyProperty</span>
<span class="Comment">// Read : <a href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.aspx">http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.aspx</a></span>
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_2/DependencyProperty.cs">DependencyProperty.cs</a></p>
<p>So a Text Property looks like this :</p>
<pre class="vsh_code">
<span class="Type">public</span> <span class="Type">string</span> Text
{
        <span class="Statement">get</span>
        {
                <span class="Statement">return</span> (<span class="Type">string</span>)GetValue(TextProperty);
        }
        <span class="Statement">set</span>
        {
                SetValue(TextProperty, <span class="Statement">value</span>);
        }
}

<span class="Type">public</span> <span class="Type">static</span> <span class="Type">readonly</span> DependencyProperty TextProperty = DependencyProperty.Register(<span class="Constant">&quot;Text&quot;</span>, <span class="Statement">typeof</span>(<span class="Type">string</span>), <span class="Statement">typeof</span>(EditableTextBlock), <span class="Statement">new</span> PropertyMetadata(<span class="Type">string</span>.Empty));
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_2/TextProperty.cs">TextProperty.cs</a></p>
<p>The EditableTextBlock control now exposes a Text property which can be Binded in your Template.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/silverlight-custom-control-properties/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/silverlight-custom-control-properties</feedburner:origLink></item>
		<item>
		<title>Silverlight Custom Control – I</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/Oj4jEFh04T0/silverlight-custom-control-i</link>
		<comments>http://dev-tricks.net/silverlight-custom-control-i#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:31:49 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[silverlight]]></category>
		<category><![CDATA[silverlight control]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=76</guid>
		<description><![CDATA[This article is my first about creating Custom Controls in Silverlight 2.
So let&#8217;s build a simple one :
You need :

A .cs file, named with your new Custom Control name
A directory named Themes
A generic.xaml file in it (just delete generic.xaml.cs if it was created)



A basic custom control .cs file (the logic part):

using System.Windows.Controls;

namespace Custom_Control_1
{
   [...]]]></description>
			<content:encoded><![CDATA[<p>This article is my first about creating Custom Controls in Silverlight 2.<br />
So let&#8217;s build a simple one :<br />
You need :</p>
<ul>
<li>A .cs file, named with your new Custom Control name</li>
<li>A directory named Themes</li>
<li>A generic.xaml file in it (just delete generic.xaml.cs if it was created)</li>
</ul>
<p><span id="more-76"></span></p>
<p><img src="http://code.dev-tricks.net/custom_control_1/EditableTextBlock.jpg" alt="Silverlight Custom Control Tree in Visual Studio" /></p>
<p>A basic custom control .cs file (the logic part):</p>
<pre class="vsh_code">
<span class="Statement">using</span> System.Windows.Controls;

<span class="Type">namespace</span> Custom_Control_1
{
    <span class="Type">public</span> <span class="Type">class</span> EditableTextBlock : Control
    {
        <span class="Type">public</span> EditableTextBlock()
        {
            DefaultStyleKey = <span class="Statement">typeof</span>(EditableTextBlock);
        }
    }
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_1/EditableTextBlock.cs">EditableTextBlock.cs</a></p>
<p>A basic custom control generic.xaml file (the graphic part):</p>
<pre class="vsh_code">
&lt;ResourceDictionary
  xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>&quot;
  xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>&quot;
  xmlns:controls=&quot;clr-namespace:Custom_Control_1&quot;&gt;
    &lt;Style TargetType=&quot;controls:EditableTextBlock&quot;&gt;
        &lt;Setter Property=&quot;Template&quot;&gt;
            &lt;Setter.Value&gt;
                &lt;ControlTemplate TargetType=&quot;controls:EditableTextBlock&quot;&gt;
                    &lt;Grid Background=&quot;AliceBlue&quot;&gt;
                    &lt;/Grid&gt;
                &lt;/ControlTemplate&gt;
            &lt;/Setter.Value&gt;
        &lt;/Setter&gt;
    &lt;/Style&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_1/generic.xaml">generic.xaml</a></p>
<p>Now, to test, you need to add the xmlns of your namespace, and add the usercontrol :</p>
<pre class="vsh_code">
&lt;UserControl x:Class=&quot;Custom_Control_1.Page&quot;
    xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>&quot;
    xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>&quot;
    xmlns:ctrl=&quot;clr-namespace:Custom_Control_1&quot;
    Width=&quot;400&quot; Height=&quot;300&quot;&gt;
    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;ctrl:EditableTextBlock&gt;&lt;/ctrl:EditableTextBlock&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/custom_control_1/page.xaml">page.xaml</a></p>
<p>In the next article, we&#8217;ll see how to bind properties with TemplateBinding.<br />
Don&#8217;t forgot to read the MSDN !</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/silverlight-custom-control-i/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/silverlight-custom-control-i</feedburner:origLink></item>
		<item>
		<title>Combinatory logic from scratch</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/YepYtM2NuIk/combinatory-logic-from-scratch</link>
		<comments>http://dev-tricks.net/combinatory-logic-from-scratch#comments</comments>
		<pubDate>Thu, 27 Nov 2008 23:56:32 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Combinatory Logic]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=64</guid>
		<description><![CDATA[Cause it&#8217;s sooooo sexy, let&#8217;s speak about Combinatory Logic !
Rule 1 : You don&#8217;t talk about Combinatory Logic
Rule 2 : You don&#8217;t talk about Combinatory Logic
Rule 3 : Combinatory Logic is based on Lambda Calculus (see Wikipedia for both)
Rule 4 : A combinator is a Lambda expression taking One and only One combinator as parameter, [...]]]></description>
			<content:encoded><![CDATA[<p>Cause it&#8217;s sooooo sexy, let&#8217;s speak about Combinatory Logic !<br />
Rule 1 : You don&#8217;t talk about Combinatory Logic<br />
Rule 2 : You don&#8217;t talk about Combinatory Logic<br />
Rule 3 : Combinatory Logic is based on Lambda Calculus (see Wikipedia for both)<br />
Rule 4 : A combinator is a Lambda expression taking One and only One combinator as parameter, and returning a Combinator.</p>
<p><span id="more-64"></span><br />
As i&#8217;m speaking to developers, i&#8217;ll use the C# Lambda syntax which is :<br />
(parameter) => statement</p>
<p>Let&#8217;s now try our first Combinator, named the Identity Combinator<br />
I = (a) => a;<br />
I named it I, it takes one parameter, localy named &#8216;a&#8217; and return the parameter as is.</p>
<p>Important Point : How to build combinator taking more than one parameter ?<br />
In C# you should use (a, b, c) => blah blah&#8230; but the Rule 4 forbid us to give more than one paraneter, so let&#8217;s cheat, imagine :<br />
K = (x) => (y) => x;<br />
K is a Combinator taking x, returning a Combinator taking y and returning x.<br />
so we have K(x) = (y) => x and K(x)(y) = x !<br />
So K take two arguments, x and y, and returns x, but ! K can take only one argument, look at the &#8220;K(x) = (y) => x&#8221; &#8230;</p>
<p>Let&#8217;s try with three arguments :</p>
<p>S = (x) => (y) => (z) => x(z)(y(z))<br />
can be called with one, two, or three arguments :<br />
S(x) returns (y) => (z) => x(z)(y(z))<br />
S(x)(y) returns (z) => x(z)(y(z))<br />
s(x)(y)(z) returns x(z)(y(z))</p>
<p>In combinatory logic, they wrote :<br />
I a = a<br />
K x y = x<br />
S x y z = x(z)(y(z))</p>
<p>then they say that in fact, I can be build from S and K :<br />
I = SKK<br />
Ok but what does it means ? where are arguments ? it&#8217;s easy :</p>
<p>I = S(K)(K);<br />
S can take 2 parameters &#8220;S(x)(y) returns (z) => x(z)(y(z))&#8221; ok ? so :<br />
I = (z) => K(z)(K(z))<br />
We have to execute it from left to right, remember, K(a)(b) returns a, so (with a == z and b == K(z)) :<br />
I = (z) => z;</p>
<p>Do you want more ?</p>
<p>Let&#8217;s try to understand<br />
B = S (K S) K x y z<br />
B stands for Barbara, from &#8220;Syllogism Barbara&#8221; (wikipedia says :)<br />
Barbara :<br />
    All men are animals.<br />
    All animals are mortal.<br />
    All men are mortal. </p>
<p>So before all, write B as we understand it, and for readability reasons, i&#8217;ll underline parameters for the bolded combinator :<br />
B = <strong>S</strong> <u>(K(S))</u>  <u>K</u>  <u>(x)</u> (y) (z)<br />
We have to execute it from left to right, and we have a S with three parameters :<br />
<strong>S</strong>(<u>a</u>)(<u>b</u>)(<u>c</u>) returns a(c)(b(c)) :<br />
B = <strong>K</strong>  <u>(S)</u>  <u>(x)</u>  (K(x)) (y) (z)<br />
From left to right we have a K with two parameters, S and y, it will return S :<br />
B = <strong>S</strong> <u>(K(x))</u>  <u>(y)</u> <u>(z)</u><br />
Calling S with three parameters (K(x)), (y), (z) returns (K(x))(z)((y)(z)) :<br />
B = <strong>K</strong>  <u>(x)</u>  <u>(z)</u>  ((y)(z))<br />
Calling K with two parameters (x), (z), it returns x :<br />
B = x((y)(z))<br />
Which can be simplified to :<br />
B = x(y(z))</p>
<p>It&#8217;s time to try it !</p>
<pre class="vsh_code">
<span class="Type">delegate</span> C C(C c);
<span class="Type">static</span> <span class="Type">void</span> Main(<span class="Type">string</span>[] args)
{
        C K = (a) =&gt; (b) =&gt; a;
        C S = (a) =&gt; (b) =&gt; (c) =&gt; a(c)(b(c));
        C I = S(K)(K);
        C B = S(K(S))(K);
}
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/Combinatory/test.cs">test.cs</a></p>
<p>It works ! Enjoy ! ! Next time, we will try a Swap combinator, a Combinator reducing to himself and progressing step to the Y Combinator !<br />
[dramatic chord]</p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/combinatory-logic-from-scratch/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/combinatory-logic-from-scratch</feedburner:origLink></item>
		<item>
		<title>The ?? operator aka the Null Coalescing Operator</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/j1iChqiQy4A/the-operator-aka-null-coalescing-operator</link>
		<comments>http://dev-tricks.net/the-operator-aka-null-coalescing-operator#comments</comments>
		<pubDate>Sun, 23 Nov 2008 16:01:40 +0000</pubDate>
		<dc:creator>valerian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[?:]]></category>
		<category><![CDATA[??]]></category>
		<category><![CDATA[coalescing]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[ternary]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=61</guid>
		<description><![CDATA[If are familiar to the use of ternary operators, you must have encountered several situations like this one :

string pageTitle = getTitle() ? getTitle() : &#34;Default Title&#34;;

Download this code: bad_situation.cs
You would want to call getTitle() only once, but then you wouldn&#8217;t have a simple one-lined initialization of you variable.
Actually there is a simple solution that [...]]]></description>
			<content:encoded><![CDATA[<p>If are familiar to the use of ternary operators, you must have encountered several situations like this one :</p>
<pre class="vsh_code">
<span class="Type">string</span> pageTitle = getTitle() ? getTitle() : <span class="Constant">&quot;Default Title&quot;</span>;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/valerian/coalescing/bad_situation.cs">bad_situation.cs</a></p>
<p>You would want to call <strong>getTitle()</strong> only once, but then you wouldn&#8217;t have a simple one-lined initialization of you variable.</p>
<p>Actually there is a simple solution that most langages implements, the <strong>null coalescing operator</strong>; let&#8217;s replace the above C# code with this one :</p>
<pre class="vsh_code">
<span class="Type">string</span> pageTitle = getTitle() ?? <span class="Constant">&quot;Default Title&quot;</span>;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/valerian/coalescing/solution.cs">solution.cs</a></p>
<p>Now you have the same behaviour, but with only one call to your function. The syntax is simple :</p>
<p><code>    possibly_null_value ?? value_if_null</code></p>
<p>the &#8220;??&#8221; operator is implemented in C# since C# 2.0.</p>
<p>You also have it in C and C++ as a GNU extension using the &#8220;?:&#8221; operator :</p>
<pre class="vsh_code">
string pageTitle = getTitle() ?: <span class="Constant">&quot;Default Title&quot;</span>;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/valerian/coalescing/solution.cpp">solution.cpp</a></p>
<p>You can get the same behaviour in javascript using the &#8220;||&#8221; operator :</p>
<pre class="vsh_code">
pageTitle = getTitle() || <span class="Constant">&quot;Default Title&quot;</span>;
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/valerian/coalescing/solution.js">solution.js</a></p>
<p>You can read more about this operator <a href="http://en.wikipedia.org/wiki/Coalescing_Operator">here</a> and <a href="http://en.wikipedia.org/wiki/%3F:">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/the-operator-aka-null-coalescing-operator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/the-operator-aka-null-coalescing-operator</feedburner:origLink></item>
		<item>
		<title>Lazy Loading in php with spl_autload</title>
		<link>http://feedproxy.google.com/~r/devTricks/~3/pHzXKgXllmU/lazy-loading-in-php-with-spl_autload</link>
		<comments>http://dev-tricks.net/lazy-loading-in-php-with-spl_autload#comments</comments>
		<pubDate>Sun, 16 Nov 2008 18:40:44 +0000</pubDate>
		<dc:creator>Julien Palard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://dev-tricks.net/?p=51</guid>
		<description><![CDATA[Today, a very short post about the lazy loading in PHP : spl_autoload
I&#8217;ll not expose everything about it here, cause it&#8217;s already done here :
http://php.net/autoload
Basically, a Lazy Loading allow you to predifine some paths where PHP should seek for classes to include, this allow you to directly instantiate an object without having included its file.

public [...]]]></description>
			<content:encoded><![CDATA[<p>Today, a very short post about the lazy loading in PHP : spl_autoload<br />
I&#8217;ll not expose everything about it here, cause it&#8217;s already done here :<br />
<a href="http://php.net/autoload">http://php.net/autoload</a></p>
<p>Basically, a Lazy Loading allow you to predifine some paths where PHP should seek for classes to include, this allow you to directly instantiate an object without having included its file.</p>
<pre class="vsh_code">
public static function lazyLoad($strClassName)
{
        /* some work to find the file to include mixing strClassName */

        /* include your files here... */
}
spl_autoload_register(&quot;lazyLoad&quot;);
</pre>
<p class="vsh_info"><strong>Download this code: </strong><a href="http://code.dev-tricks.net/php_lazy_loading/lazy.php">lazy.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dev-tricks.net/lazy-loading-in-php-with-spl_autload/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dev-tricks.net/lazy-loading-in-php-with-spl_autload</feedburner:origLink></item>
	</channel>
</rss>
