<?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>James Boelen &#187; Web</title>
	<atom:link href="http://james.boelen.ca/category/programming/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.boelen.ca</link>
	<description>Software Developer</description>
	<lastBuildDate>Thu, 09 May 2013 22:02:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>WebApi Routes, Optional Parameters &amp; Constraints</title>
		<link>http://james.boelen.ca/programming/webapi-routes-optional-parameters-constraints/</link>
		<comments>http://james.boelen.ca/programming/webapi-routes-optional-parameters-constraints/#comments</comments>
		<pubDate>Mon, 06 May 2013 16:22:14 +0000</pubDate>
		<dc:creator>James Boelen</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apicontroller]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[optional]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[webapi]]></category>

		<guid isPermaLink="false">http://james.boelen.ca/?p=1396</guid>
		<description><![CDATA[Recently while wiring up some Web Api routes for a asp.net MVC application, I learnt that by adding constraints to optional parameters, they no longer are optional.]]></description>
				<content:encoded><![CDATA[<p>Recently while wiring up some Web Api routes for a asp.net MVC application, I learnt that by adding constraints to optional parameters, they no longer are optional.</p>
<p>If I wanted to capture &#8220;api/{controller}/{id}&#8221; I would set up the following route:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">config<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MapHttpRoute</span><span style="color: #008000;">&#40;</span>
        name<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;DefaultApi&quot;</span>,
        routeTemplate<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;api/{controller}/{id}&quot;</span>,
        defaults<span style="color: #008000;">:</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span>id <span style="color: #008000;">=</span> RouteParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">Optional</span><span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>This will capture &#8220;api/dogs&#8221; and &#8220;api/dogs/1&#8243;.</p>
<p>But my co-worker wants to make sure that id&#8217;s are always an integer to keep away pesky internet savvy folks that try to break the application and he doesn&#8217;t trust my controller to do this for us. So he changes the route to:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;">config<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MapHttpRoute</span><span style="color: #008000;">&#40;</span>
        name<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;DefaultApi&quot;</span>,
        routeTemplate<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;api/{controller}/{id}&quot;</span>,
        defaults<span style="color: #008000;">:</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span>id <span style="color: #008000;">=</span> RouteParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">Optional</span><span style="color: #008000;">&#125;</span>,
        constraints<span style="color: #008000;">:</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span>id <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;\d+&quot;</span><span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Suddenly, the route now only captures &#8220;api/dogs/1&#8243; and not &#8220;api/dogs&#8221;. The constraint has overwritten the RoutParameter.Optional on id. While I&#8217;m not sure why the two options conflict, to avoid this, keep constraints off the route config and let the controller do its thing. It&#8217;s pretty good at it.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>HttpGet<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> HttpResponseMessage GetDogs<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">?</span> id <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>id<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> JsonNetResult<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateResult</span><span style="color: #008000;">&#40;</span>DogManager<span style="color: #008000;">.</span><span style="color: #0000FF;">GetById</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> JsonNetResult<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateResult</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Dog<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>           
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://james.boelen.ca/programming/webapi-routes-optional-parameters-constraints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Event 2</title>
		<link>http://james.boelen.ca/programming/visual-event-2/</link>
		<comments>http://james.boelen.ca/programming/visual-event-2/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 15:10:29 +0000</pubDate>
		<dc:creator>James Boelen</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[visual event 2]]></category>

		<guid isPermaLink="false">http://james.boelen.ca/?p=1366</guid>
		<description><![CDATA[This could possibly one of my greatest finds recently. The other day I was going through some code that someone else had written and was having trouble finding the script that was being fired when a DOM element was being clicked. I do my development in chrome, so the first place I looked was their [...]]]></description>
				<content:encoded><![CDATA[<p>This could possibly one of my greatest finds recently. The other day I was going through some code that someone else had written and was having trouble finding the script that was being fired when a DOM element was being clicked. I do my development in chrome, so the first place I looked was their Extensions library. The only plug-in I could find, unfortunately, only showed the jquery scripts that were being called when events occurred. This clearly wasn&#8217;t helping.</p>
<p>I then stumbled upon a <a title="StackOverflow" href="http://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node">stackoverflow</a> question in which someone was having a similar issue.</p>
<p>Enter Visual Event 2. VE2 is an open source bookmarklet that, when loaded, will highlight all of the objects with events on a page and show you what scripts will be called when they are clicked. This thing is absolutely brilliant. I was instantly able to see what script was being called and found it in seconds. Better still, since it&#8217;s a bookmarklet, it should work in most modern browsers too!</p>
<p>This thing will permanently live in my developer toolbox. I highly suggest it for developers working on sites that are js intense.</p>
<p><a title="Visual Event 2 Website" href="http://www.sprymedia.co.uk/article/Visual+Event+2" target="_blank">Visual Event 2 Website</a></p>
]]></content:encoded>
			<wfw:commentRss>http://james.boelen.ca/programming/visual-event-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE7 inline-block Fix</title>
		<link>http://james.boelen.ca/programming/ie7-inline-block-fix/</link>
		<comments>http://james.boelen.ca/programming/ie7-inline-block-fix/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 18:24:51 +0000</pubDate>
		<dc:creator>James Boelen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ie]]></category>

		<guid isPermaLink="false">http://james.boelen.ca/?p=1364</guid>
		<description><![CDATA[Oh IE, how I loath thee&#8230; IE9 is getting better, but the legacy that it left and that we developers have to deal with is cringe-worthy. One of my often used layout CSS bits is display:inline-block Unfortunately, this does not degrade gracefully in IE &#60; 8. I usually have to look this up everytime I [...]]]></description>
				<content:encoded><![CDATA[<p>Oh IE, how I loath thee&#8230;</p>
<p>IE9 is getting better, but the legacy that it left and that we developers have to deal with is cringe-worthy. One of my often used layout CSS bits is <strong>display:inline-block</strong></p>
<p>Unfortunately, this does not degrade gracefully in IE &lt; 8. I usually have to look this up everytime I view a page in IE, so I figured I&#8217;d pen it here so that I can find it more easily. The trick, as many of you might know, is to add the following in the CSS:</p>
<p><code>zoom: 1;<br />
*display: inline;</code></p>
<p>Source: <a href="http://uncorkedstudios.com/2011/12/12/how-to-fix-the-ie7-and-inline-block-css-bug/">How to fix the IE7 and inline-block CSS bug</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://james.boelen.ca/programming/ie7-inline-block-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox Range Bug</title>
		<link>http://james.boelen.ca/programming/firefox-range-bug/</link>
		<comments>http://james.boelen.ca/programming/firefox-range-bug/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 20:37:18 +0000</pubDate>
		<dc:creator>James Boelen</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://james.boelen.ca/?p=202</guid>
		<description><![CDATA[Today I came across an odd Firefox javascript bug. While trying to manipulate a range object, I ran into a wall that was preventing me from changing it a second time. On my page, I have a script that runs when a user selects text. I then delete the contents and replace it with the [...]]]></description>
				<content:encoded><![CDATA[<p>Today I came across an odd Firefox javascript bug. While trying to manipulate a range object, I ran into a wall that was preventing me from changing it a second time. On my page, I have a script that runs when a user selects text. I then delete the contents and replace it with the same text with a span tag around it. I noticed however, that if I brought up the range object again, it said it had no content. My syntax was simple:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">range.<span style="color: #660066;">deleteContents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
range.<span style="color: #660066;">insertNode</span><span style="color: #009900;">&#40;</span>newContents<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>newContents was simply a span element with some text that I had created using the <em>document.createElement</em> method.</p>
<p>This code works exactly as expected in chrome. If I look into the range object, I  correctly have the new contents. In firefox however, the range object was missing all of its delicious contenty goodness. After doing a bit of re-working, I came up with the following solution:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">range.<span style="color: #660066;">deleteContents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
range.<span style="color: #660066;">insertNode</span><span style="color: #009900;">&#40;</span>newContents<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
range <span style="color: #339933;">=</span> document.<span style="color: #660066;">createRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
range.<span style="color: #660066;">selectNode</span><span style="color: #009900;">&#40;</span>newContents<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The additional 2 lines make it work and it still functions properly in Chrome. Now when I bring up the range object, it has the new content for me to mess around with again.</p>
<p><em>Using firefox 10.0.2</em></p>
]]></content:encoded>
			<wfw:commentRss>http://james.boelen.ca/programming/firefox-range-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
