<?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>Dan Merino&#039;s Blog</title>
	<atom:link href="http://blog.danmerino.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.danmerino.com</link>
	<description>Computer Science, Entrepreneurship and Productivity</description>
	<lastBuildDate>Sat, 05 May 2012 15:18:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Handeling and Logging Python Exceptions</title>
		<link>http://blog.danmerino.com/handeling-and-logging-python-exceptions/</link>
		<comments>http://blog.danmerino.com/handeling-and-logging-python-exceptions/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 18:48:26 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.danmerino.com/?p=758</guid>
		<description><![CDATA[To easily track down exceptions it is important to keep track the original context and trace.   To show this I have created a little example of the proper and improper way of doing]]></description>
			<content:encoded><![CDATA[<p>To easily track down exceptions it is important to keep track the original context and trace.   To show this I have created a little example of the proper and improper way of doing this.</p>
<pre class="brush: python; title: ; notranslate">

import traceback

class ExceptionExample:
    def __init__(self):
        self.log = None

    def lose_context(self):
        try:
            self.exceptional_method()
        except Exception, e:
            raise e

    def keep_context(self):
        try:
            self.exceptional_method()
        except Exception, e:
            raise

    def keep_context_log_incorrectly(self):
         try:
            self.exceptional_method()
         except Exception, e:
            self.log = e

    def keep_context_log_correctly(self):
         try:
            self.exceptional_method()
         except Exception, e:
            self.log = traceback.format_exc()

    def exceptional_method(self):
        raise Exception(&quot;I throw stuff at you&quot;)

    def print_log(self):
        if self.log:
            print &quot;\t&quot; +  str(self.log)
        else:
            print &quot;		nothing in the log\n\n&quot;

ee = ExceptionExample()
print &quot;Logging an exception incorrectly:&quot;
ee.keep_context_log_incorrectly()
ee.print_log()
print &quot;Logging an exception correctly:&quot;
ee.keep_context_log_correctly()
ee.print_log()
#print &quot;Lost context - bad - check out the line number&quot;
#ee.lose_context()
#print &quot;Proper context - check out the line number&quot;
#ee.keep_context()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/handeling-and-logging-python-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Continuos Integration (CI) for JavaScript &#8211; Jasmine and Teamcity</title>
		<link>http://blog.danmerino.com/continuos-integration-ci-for-javascript-jasmine-and-teamcity/</link>
		<comments>http://blog.danmerino.com/continuos-integration-ci-for-javascript-jasmine-and-teamcity/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 19:03:47 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.danmerino.com/?p=695</guid>
		<description><![CDATA[Web applications are using more JavaScript than ever before.  The following image (thanks to Gineer) shows the shift in the architecture types of web applications from simple thin clients to]]></description>
			<content:encoded><![CDATA[<p>Web applications are using more JavaScript than ever before.  <a href="http://efreedom.com/Question/1-1347200/Google-Earth-Rich-Client-Rich-Internet-Architecture">The following image (thanks to Gineer) shows the shift in the architecture types of web application</a>s from simple thin clients to thicker clients driven by rich presentations and client logic.</p>
<p><a href="http://blog.danmerino.com/wp-content/uploads/2012/03/architypes-small.jpg" rel="lightbox"><img class="aligncenter size-full wp-image-697" title="architypes-small" src="http://blog.danmerino.com/wp-content/uploads/2012/03/architypes-small.jpg" alt="" width="653" height="406" /></a></p>
<p>Since most of the newer web applications include business logic embedded into the client using JavaScript, we must put assurances to make sure the quality of the application is not compromised over time.</p>
<p>In most cases, the JavaScript side of the applications goes untested or is not automated which is a bad idea.</p>
<p>I have selected the following tools to be able to provide Continuous Integration to Rich Internet Applications:</p>
<ul>
<li><a href="https://github.com/pivotal/jasmine">Jasmine</a></li>
<li><a href="http://www.jetbrains.com/teamcity/" target="_blank">Team City</a></li>
<li><a href="https://github.com/larrymyers/jasmine-reporters" target="_blank">Jasmine Team City Reporter</a></li>
<li><a href="http://www.phantomjs.org/" target="_blank">PhantomJS</a></li>
</ul>
<p>Jasmine is a testing framework for JavaScript. It is usually used as a red-green tool for developing applications with either <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">TDD</a> or <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank">BDD</a>. Jasmin runs on the browser for convenience to check the TDD red-green method but this makes it a bit harder to automate.</p>
<p>Team City is a Continuos Integration server that is extremely popular due to its flexibility to work with a wide variety of projects, it is easy to configure and it works in most environments.</p>
<p>Jasmine Team City Reporter is a reporter type for Jasmine. Jasmine uses a plugin based architecture where it allows different types of reporters to consume and prepare the data. The Jasmine Team City Reporter module allows Jasmine to output the data to the web page console window of the browser that runs Jasmine.</p>
<p>PhantomJS is a headless web-kit browser that allows execution and rendering of web content. We will use it to simulate as if we would be running Jasmine with the Team City Reporter on a website, this way we can automate the whole process.</p>
<p>I built a simple PhatomJS script that consumes the Jasmine Team City Reporter example, it worked great!</p>
<p><strong>JavaScript file to control PhantomJS</strong></p>
<pre class="brush: jscript; title: ; notranslate">

console.log('Loading a web page');
var page = new WebPage();
//This was tricky, this is the way to open LOCAL files
var url = &quot;file://localhost/Users/danmerino/test/teamcity_reporter.html&quot;;
phantom.viewportSize = {width: 800, height: 600};
//This is required because PhantomJS sandboxes the website and it does not show up the console messages form that page by default
page.onConsoleMessage = function (msg) { console.log(msg); };
//Open the website
page.open(url, function (status) {
    //Page is loaded!
		if (status !== 'success') {
	            console.log('Unable to load the address!');
	        } else {
                 //Using a delay to make sure the JavaScript is executed in the browser
			   window.setTimeout(function () {
					page.render(&quot;output.png&quot;);
        			phantom.exit();
 		       }, 200);
				}
});
</pre>
<p><strong>JavaScript tests</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Console Reporter Spec&lt;/title&gt;

    &lt;link rel=&quot;stylesheet&quot; href=&quot;../ext/jasmine.css&quot; type=&quot;text/css&quot; /&gt;

    &lt;script type=&quot;text/javascript&quot; src=&quot;../ext/jasmine.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../ext/jasmine-html.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../src/jasmine.teamcity_reporter.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        describe(&quot;Basic Suite&quot;, function() {
            it(&quot;Should pass a basic truthiness test.&quot;, function() {
                expect(true).toEqual(true);
            });

            it(&quot;Should fail when it hits an inequal statement.&quot;, function() {
                expect(1+1).toEqual(3);
            });
        });

        describe(&quot;Another Suite&quot;, function() {
            it(&quot;Should pass this test as well.&quot;, function() {
                expect(0).toEqual(0);
            });
        });

        jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
        jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
        jasmine.getEnv().execute();
    &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Team City Configuration</strong></p>
<p><a href="http://blog.danmerino.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-05-at-12.16.51-AM1.png" rel="lightbox"><img class="aligncenter size-full wp-image-723" title="Screen Shot 2012-03-05 at 12.16.51 AM" src="http://blog.danmerino.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-05-at-12.16.51-AM1.png" alt="" width="958" height="533" /></a></p>
<p><strong>Team City Test Results</strong></p>
<p><a href="http://blog.danmerino.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-05-at-12.15.38-AM.png" rel="lightbox"><img class="aligncenter size-full wp-image-709" title="Team City Tests" src="http://blog.danmerino.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-05-at-12.15.38-AM.png" alt="" width="921" height="593" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/continuos-integration-ci-for-javascript-jasmine-and-teamcity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Whether you think you can&#8230;&#8221; explained by the Simpsons</title>
		<link>http://blog.danmerino.com/whether-you-think-you-can-explained-by-the-simpsons/</link>
		<comments>http://blog.danmerino.com/whether-you-think-you-can-explained-by-the-simpsons/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 04:45:03 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Motivational]]></category>

		<guid isPermaLink="false">http://blog.danmerino.com/?p=671</guid>
		<description><![CDATA[The following is one of my favorite quotes: &#8220;Whether you think you can or whether you think you can&#8217;t, you&#8217;re right.&#8221; - Henry Ford It is a very interesting quote, and]]></description>
			<content:encoded><![CDATA[<p>The following is one of my favorite quotes:</p>
<p>&#8220;Whether you think you can or whether you think you can&#8217;t, you&#8217;re right.&#8221; - <strong>Henry Ford</strong></p>
<p>It is a very interesting quote, and hard to explain. The quote resonated with me when I saw the quote exemplified in episode &#8220;<a href="http://en.wikipedia.org/wiki/He_Loves_to_Fly_and_He_D'ohs" target="_blank">He Loves to Fly and the D&#8217;Ohs</a>&#8221; from the Simpsons:</p>
<p><strong>[Colby helping Homer to land a plane]</strong></p>
<p><strong></strong><strong>Colby</strong>: Okay Homer, I don&#8217;t know anything about planes, but I know about you. You have what made America great: no understanding of the limits of your power and a complete lack of concern for what anyone thinks of you. So you&#8217;ll land that plane. And do you know why? Because I heard some guy say you <em>couldn&#8217;t</em>.</p>
<p><a title="w:Homer Simpson" href="http://en.wikipedia.org/wiki/Homer_Simpson" target="_blank">Homer</a>: <em>What!</em> I&#8217;ll show him. I&#8217;ll show that guy!</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/whether-you-think-you-can-explained-by-the-simpsons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Value of Time</title>
		<link>http://blog.danmerino.com/the-value-of-time/</link>
		<comments>http://blog.danmerino.com/the-value-of-time/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 00:13:34 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://blog.danmerino.com/?p=640</guid>
		<description><![CDATA[The most important lesson I learned from graduate school is that everything can be accomplished, as long as you have enough time to dedicate to your goals. Some people&#8217;s time is more valuable]]></description>
			<content:encoded><![CDATA[<p>The most important lesson I learned from graduate school is that everything can be accomplished, as long as you have enough time to dedicate to your goals. Some people&#8217;s time is more valuable than others, the important thing is that each one of us puts a price on our own time and how we use it to archive our goals.</p>
<p>The way I see it is that the main goal is to be very productive in a short amount of time and get things done right. This is very counter intuitive in our culture. At one time or another, we have all felt proud because we have spent countless hours in the office working on a project. In reality, this is a trick the brain plays. Sometimes we are so busy doing things that are not important, yet, we feel proud because we use time as a measure of accomplishments. Instead, we should measure our progress based in terms of <a href="/pomodoro-productivity-tools/">productivity</a> and returns on investment.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/the-value-of-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common Performance Testing Mistakes</title>
		<link>http://blog.danmerino.com/common-performance-testing-mistakes/</link>
		<comments>http://blog.danmerino.com/common-performance-testing-mistakes/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 08:18:25 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=620</guid>
		<description><![CDATA[At my lab recently we have all been benchmarking our applications. Most of our work has to deal with throughput in distributed applications. A lot of the time I see]]></description>
			<content:encoded><![CDATA[<p>At my lab recently we have all been benchmarking our applications. Most of our work has to deal with throughput in distributed applications. A lot of the time I see people making common mistakes when performing tests so I decided to blog about it.</p>
<ol>
<li>Never test from the same machine, your testing program is taking away significant resources from your application!</li>
<li>Is concurrency being tested (depends on your goals, most likely, YES)</li>
<li>If testing for real world applications, network latency is a HUGE factor in performance and affects applications in many different scenarios, some quick tips are:
<ol>
<li>Never test using a wireless network unless that is part of your tests!</li>
<li>Make sure you are not hitting your network cap or your packets are being changed by your internet provider</li>
<li>If testing a cloud service, do not test from the same service since there could be no network/connection delay. This can be due to several factors but it could be simply because the test tool might be under the same virtual machine as the application!</li>
<li>If you are using a reverse proxy for spoon feeding, make sure you test with and without it!</li>
</ol>
</li>
<li>Most importantly, calculate performance based on real values instead of approximations. Most of the times approximations are NOT true as they are extrapolated to higher values.</li>
</ol>
<p>In the web, performance is very important, if you don&#8217;t think so, ask Google: <a href="http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html">http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html</a></p>
<blockquote><p>Marissa started with a story about a user test they did. They asked a group of Google searchers how many search results they wanted to see. Users asked for more, more than the ten results Google normally shows. More is more, they said.</p>
<p>So, Marissa ran an experiment where Google increased the number of search results to thirty. Traffic and revenue from Google searchers in the experimental group dropped by 20%.</p>
<p>Ouch. Why? Why, when users had asked for this, did they seem to hate it?</p>
<p>After a bit of looking, Marissa explained that they found an uncontrolled variable. The page with 10 results took .4 seconds to generate. The page with 30 results took .9 seconds.</p>
<p><strong>Half a second delay caused a 20% drop in traffic. Half a second delay killed user satisfaction.</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/common-performance-testing-mistakes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pomodoro Productivity Tools</title>
		<link>http://blog.danmerino.com/pomodoro-productivity-tools/</link>
		<comments>http://blog.danmerino.com/pomodoro-productivity-tools/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 19:14:26 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=615</guid>
		<description><![CDATA[I have been using GTD for a couple of years and it works very well for me. To get focused on activities I use a combination of tools. Most of]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://en.wikipedia.org/wiki/Getting_Things_Done">GTD </a>for a couple of years and it works very well for me. To get focused on activities I use a combination of tools. Most of the tools are not bound to my computer because I found myself checking them all time. Instead, the tools are on my mobile devices because I can take a quick glance at them whenever I want.</p>
<h2>I recommend the following tools:</h2>
<p><a href="http://www.dueapp.com/">Due </a>for iPad, iPod touch or iPhone (needs iOS 4).<br />
<img src="http://www.dueapp.com/images/iphone-1-quick.png" alt="Due application" /></p>
<p>Pomodoro for Windows Phone 7. Here is a <a href="http://wp7.apphab.com/pomodoro-by-mark-monster/">link </a>to a description. The application is free and you can easily get it on the marketplace by typing &#8220;pomodoro&#8221;.<br />
<img src="http://image.catalog.zune.net/v3.2/image/a8f62b56-13f8-48a2-a8cc-62cf76803843?width=100&amp;height=100" alt="Pomodoro Windows Phone 7" width="300" height="450" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/pomodoro-productivity-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell</title>
		<link>http://blog.danmerino.com/powershell/</link>
		<comments>http://blog.danmerino.com/powershell/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 22:14:57 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://blog.codingadventure.com/?p=603</guid>
		<description><![CDATA[PowerShell is an amazing framework designed to streamline tasks. The main benefits of PowerShell is that it built and integrated to the .NET framework and provides core functionaly to COM]]></description>
			<content:encoded><![CDATA[<p>PowerShell is an amazing framework designed to streamline tasks. The main benefits of PowerShell is that it built and integrated to the .NET framework and provides core functionaly to COM and WMI.</p>
<p>If you have done any siginificant work with Linux then most likely you are experienced with Bash Scripts and in DOS batch files, of course there are also PowerShell scripts.</p>
<p>In addition, in PowerShell, there are small programs called cmdlets. The programs are then compiled into a DLL which then can be loaded as part of another script. It is a way of reusing and pipelining processes (think pipes and filters pattern) with objects instead of text input!</p>
<p>If you are used to Bash/MS-DOS it will make you happy to know most of the typical commands have aliases and you can use them right away!</p>
<ul>
<li>List all files = ls/dir</li>
<li>Current Dir = pwd/cd</li>
<li>Read file = cat/type</li>
<li>Clear screen = clear/cls</li>
<li>Copy = cp/copy</li>
<li>Move = mv/move</li>
<li>Delete =rm/rmdir/del</li>
<li>Rename = mv/ren/rename</li>
<li>Write = echo</li>
<li>List processes = ps/tlist/tasklisk</li>
</ul>
<p>PowerShell is great because if you have some experience with .NET and scripting you are a pro right away.  To conclude, here my favorite script for <a href="http://powershell.com/cs/blogs/tips/archive/2011/06/06/parsing-text-based-log-files-faster.aspx">parsing long log files courtesy of PowerShell.com</a>:</p>
<pre class="brush: bash; title: ; notranslate">
foreach($line in (Get-Content $env:windirwindowsupdate.log `
-ReadCount 0 -Encoding UTF8)) `
{ if ($line -like '*successfully installed*') `
{ ($line -split ': ')[-1]}}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Windows Phone 7 Programming</title>
		<link>http://blog.danmerino.com/introduction-to-windows-phone-7-programming/</link>
		<comments>http://blog.danmerino.com/introduction-to-windows-phone-7-programming/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 08:00:12 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://newdevcentral.com/?p=569</guid>
		<description><![CDATA[Windows Phone 7 Programming Introduction View more presentations from danmerino.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_5956383"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/danmerino/windows-phone-7-programming-introduction" title="Windows Phone 7 Programming Introduction">Windows Phone 7 Programming Introduction</a></strong><object id="__sse5956383" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=windowsphone7-101128212133-phpapp01&#038;stripped_title=windows-phone-7-programming-introduction&#038;userName=danmerino" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse5956383" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=windowsphone7-101128212133-phpapp01&#038;stripped_title=windows-phone-7-programming-introduction&#038;userName=danmerino" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/danmerino">danmerino</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/introduction-to-windows-phone-7-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Code Contracts .NET 4.0</title>
		<link>http://blog.danmerino.com/testing-code-contracts-net-4-0/</link>
		<comments>http://blog.danmerino.com/testing-code-contracts-net-4-0/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 08:26:02 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[Best practice]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[code contracts]]></category>
		<category><![CDATA[postconditions]]></category>
		<category><![CDATA[preconditions]]></category>
		<category><![CDATA[test project]]></category>

		<guid isPermaLink="false">http://newdevcentral.com/?p=435</guid>
		<description><![CDATA[Why use Code Contracts? By providing pre-compiled code contract interfaces other developers can adhere to signatures and also expected behavior. This is specially important due to the Liskov substitution principle.]]></description>
			<content:encoded><![CDATA[<h2>Why use Code Contracts?</h2>
<p>By providing pre-compiled <a href="http://research.microsoft.com/en-us/projects/contracts/">code contract</a> interfaces other developers can adhere to signatures and also expected behavior. This is specially important due to the <a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle">Liskov substitution principle</a>.</p>
<p>Dino Esposito wrote a great article on the topic called <a href="http://dotnetslackers.com/articles/net/code-contracts-preview-interfaces.aspx"> Code Contracts Preview: Interfaces</a>.</p>
<h2>Testing</h2>
<p>To test that all the right contracts are in place a test project can be created.</p>
<p>Testing preconditions is possible by catching the exceptions created by those preconditions.</p>
<pre class="brush: csharp; title: ; notranslate">

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ModelNegativeBlance()
        {
            Account acc = new Account()
            {
                AccountName = &quot;NewAccount&quot;,
                //0 or positive is expected
                Balance = -99,
                CreationDate = DateTime.Now

            };
        }
</pre>
<p>Testing postconditions is a bit tricky because the exceptions raised by postconditions are not meant to be caught. Therefore plain strings have to be used.</p>
<pre class="brush: csharp; title: ; notranslate">

    public static class TestHelpers
    {
        public static string ContractExceptionName = &quot;System.Diagnostics.Contracts.__ContractsRuntime+ContractException&quot;;

    }
</pre>
<pre class="brush: csharp; title: ; notranslate">
    public class RepositoryTests
    {
        public RepositoryTests()
        {

        }

        [TestMethod]
        public void InsertModelWithNoParitionKeyDueToBadRepository()
        {

            var repo = SetBadRepo();
            Account acc = new Account()
            {
                AccountName = &quot;NewAccount&quot;,
                Balance = 0,
                CreationDate = DateTime.Now

            };

            try
            {
                repo.InsertAccount(acc);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(TestHelpers.ContractExceptionName, ex.GetType().FullName);
            }
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/testing-code-contracts-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do not use $_SERVER[&#039;PHP_SELF&#039;]</title>
		<link>http://blog.danmerino.com/do-not-use-_serverphp_self/</link>
		<comments>http://blog.danmerino.com/do-not-use-_serverphp_self/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 06:33:57 +0000</pubDate>
		<dc:creator>danmerino</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[$_SERVER['PHP_SELF']]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[__FILE__]]></category>

		<guid isPermaLink="false">http://newdevcentral.com/?p=462</guid>
		<description><![CDATA[I have seen many times that logos and links to a home page of a site use the following: Sadly, its is very dangerous because it might carry additional trailing]]></description>
			<content:encoded><![CDATA[<p>I have seen many times that logos and links to a home page of a site use the following:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo $_SERVER['PHP_SELF']?&gt;
</pre>
<p>Sadly, its is very dangerous because it might carry additional trailing data. This is specially an issue when doing <a href="http://en.wikipedia.org/wiki/Search_engine_optimization">SEO</a>.</p>
<p>For example:<br />
It will work fine for: /moo/daaa/boo.php<br />
It will possibly redirect to self: /moo/daa/boo.php/mooo/daa.htm</p>
<p><a href="http://www.php.net/manual/en/reserved.variables.php#81216">According to some people the behavior is erratic on different configurations.</a></p>
<p>To prevent all problems I recommend using <a href="http://php.net/manual/en/language.constants.predefined.php">__FILE__</a>. The following solution which works on PHP 4.0.2 and up:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo basename(__FILE__) ?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.danmerino.com/do-not-use-_serverphp_self/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

