<?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/" version="2.0">

<channel>
	<title>Farblondzshet in Code</title>
	
	<link>http://matthewmanela.com</link>
	<description>The life and work of Matthew Manela</description>
	<lastBuildDate>Fri, 04 May 2012 23:41:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Farblondzshet" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="farblondzshet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Making linking between anchors in an IFrame work in Chrome and Firefox 11+</title>
		<link>http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-11-and-above/</link>
		<comments>http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-11-and-above/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 23:20:22 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1439</guid>
		<description><![CDATA[About a year ago I wrote the post Making linking between anchors in an IFrame work in Firefox 4 and above which detailed a workaround for making anchor tags in IFrame&#8217;s function as expected. Unfortunately this fix stopped working as &#8230; <a href="http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-11-and-above/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>About a year ago I wrote the post <a href="http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-4-and-above/">Making linking between anchors in an IFrame work in Firefox 4 and above</a> which detailed a workaround for making anchor tags in IFrame&#8217;s function as expected. Unfortunately this fix stopped working as of Firefox 11 and in Chrome as well.  Firefox changed how it calculated the offset of an element inside of the IFrame. It used to calculate it relative to the parent window but now calculates relative to the IFrame window. To fix this you now must add the distance between the top of the page and the IFrame in the call to the scrollto function.</p>
<p>Here is the updated code:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:73787715-c040-4d77-8d92-5ce8b4de57c7" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: jscript; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 876px; height: 639px;" style="width: 876px; height: 639px; overflow: auto;">var iframeOffset = $("#ID_OF_MY_IFRAME", window.parent.document).offset();
$("a").each(function () {
    var link = $(this);
    var href = link.attr("href");
    if (href &amp;&amp; href[0] == "#") {
        var name = href.substring(1);
        $(this).click(function () {
            var nameElement = $("[name='" + name + "']");
            var idElement = $("#" + name);
            var element = null;
            if (nameElement.length &gt; 0) {
                element = nameElement;
            } else if (idElement.length &gt; 0) {
                element = idElement;
            }

            if (element) {
                var offset = element.offset();
                window.parent.scrollTo(offset.left, offset.top + iframeOffset.top);
            }

            return false;
        });
    }
});</pre>
<p>&nbsp;</p>
</div>
<p>When using this code you must update the text “#ID_OF_MY_IFRAME” with the id that you give the IFrame tag in the parent page.</p>
<p>I create a <a href="http://matthewmanela.com/IFrameTest/Parent.html" target="_blank">demo page</a> where you can see the above fix in action.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-4-and-above/" rel="bookmark" class="crp_title">Making linking between anchors in an IFrame work in Firefox 4 and above</a></li><li><a href="http://matthewmanela.com/blog/rough-draft-of-a-new-jquery-method/" rel="bookmark" class="crp_title">Rough draft of a new JQuery method</a></li><li><a href="http://matthewmanela.com/blog/updated-jquery-resizecomplete-method/" rel="bookmark" class="crp_title">Updated JQuery ResizeComplete method</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/E4LZeDg9_tc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/making-linking-between-anchors-in-an-iframe-work-in-firefox-11-and-above/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Chutzpah 1.4.0 Released</title>
		<link>http://matthewmanela.com/blog/chutzpah-1-4-0-released/</link>
		<comments>http://matthewmanela.com/blog/chutzpah-1-4-0-released/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 04:31:10 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chutzpah]]></category>
		<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1434</guid>
		<description><![CDATA[A new version of Chutzpah is now available. Grab the new bits from CodePlex and NuGet or go to the Visual Studio Gallery to get the updated Visual Studio Extension&#160; and Test Adapter for Visual Studio 11 Beta. This release &#8230; <a href="http://matthewmanela.com/blog/chutzpah-1-4-0-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A new version of Chutzpah is now available.
<p>Grab the new bits from <a href="http://chutzpah.codeplex.com/">CodePlex</a> and <a href="http://nuget.org/List/Packages/Chutzpah">NuGet</a> or go to the Visual Studio Gallery to get the updated <a href="http://visualstudiogallery.msdn.microsoft.com/71a4e9bd-f660-448f-bd92-f5a65d39b7f0">Visual Studio Extension</a>&nbsp; and <a href="http://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe">Test Adapter for Visual Studio 11 Beta</a>.
<p>This release contains the following changes:
<ul>
<li>Support for retrieving JS dependencies through references.js (<a href="http://chutzpah.codeplex.com/workitem/37">work item</a>)
<li>Adding reference to a css file should add it to HTML test harness (<a href="http://chutzpah.codeplex.com/workitem/33">work item</a>)
<li>Upgrade to Phantom 1.3 (<a href="http://chutzpah.codeplex.com/workitem/24">work item</a>)
<li>Tests fail if source file has the same name as test file (<a href="http://chutzpah.codeplex.com/workitem/34">work item</a>)
<li>Run in browser results in blank page for Jasmine Tests (<a href="http://chutzpah.codeplex.com/workitem/38">work item</a>)
<li>Prevent temporary folder explosion (<a href="http://chutzpah.codeplex.com/workitem/39">work item</a>)</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-2-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.2.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-test-adapter-for-visual-studio-11-beta/" rel="bookmark" class="crp_title">Chutzpah test adapter for Visual Studio 11 Beta</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.3.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/XgKnWVPdOiM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/chutzpah-1-4-0-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chutzpah test adapter for Visual Studio 11 Beta</title>
		<link>http://matthewmanela.com/blog/chutzpah-test-adapter-for-visual-studio-11-beta/</link>
		<comments>http://matthewmanela.com/blog/chutzpah-test-adapter-for-visual-studio-11-beta/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 23:56:19 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chutzpah]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1431</guid>
		<description><![CDATA[Visual Studio 11 Beta was released today and one of the many cool new features is the Unit Test Explorer. The Unit Test Explorer functions using a plugin model where it scans for test adapters and uses them to find &#8230; <a href="http://matthewmanela.com/blog/chutzpah-test-adapter-for-visual-studio-11-beta/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.microsoft.com/visualstudio/11/">Visual Studio 11 Beta</a> was released today and one of the many cool new features is the Unit Test Explorer. </p>
<p><a href="http://matthewmanela.com/wp-content/uploads/2012/02/UnitTestExplorerEmpty.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="UnitTestExplorerEmpty" border="0" alt="UnitTestExplorerEmpty" src="http://matthewmanela.com/wp-content/uploads/2012/02/UnitTestExplorerEmpty_thumb.png" width="261" height="326"></a></p>
<p>The Unit Test Explorer functions using a plugin model where it scans for test adapters and uses them to find and run tests. You can download adapters from the <a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=RootCategory&amp;f%5B0%5D.Value=tools&amp;f%5B1%5D.Type=Tag&amp;f%5B1%5D.Value=Unit%20Testing&amp;f%5B2%5D.Type=VisualStudioVersion&amp;f%5B2%5D.Value=11.0&amp;f%5B2%5D.Text=Visual%20Studio%2011">Visual Studio Gallery</a> which currently hosts the <a href="http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099">xUnit.net</a>, <a href="http://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d">NUnit</a> and <a href="http://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe">Chutzpah</a> adapters. </p>
<p>With the addition of the Chutzpah adapter Visual Studio 11 Beta can discover and execute QUnit and Jasmine unit tests. VS now provides a nice graphical interface to see and run the available tests.</p>
<p><a href="http://matthewmanela.com/wp-content/uploads/2012/02/UnitTestExplorer.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="UnitTestExplorer" border="0" alt="UnitTestExplorer" src="http://matthewmanela.com/wp-content/uploads/2012/02/UnitTestExplorer_thumb.png" width="308" height="484"></a></p>
<p>&nbsp;</p>
<p>The <a href="http://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe">Chutzpah adapter</a> is still very young and has much room for improvement but I wanted to get something out there early to get feedback. Feel free to provide feedback on the <a href="http://chutzpah.codeplex.com/">Chutzpah CodePlex page</a>. Soon I will also be upgrading the standard <a href="http://visualstudiogallery.msdn.microsoft.com/71a4e9bd-f660-448f-bd92-f5a65d39b7f0">Chutzpah Visual Studio plugin</a> to VS 11 so you still have the option of a TestDriven.net type experience for JS tests.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-4-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.4.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.3.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-1-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.1.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/gKpNFBT0Shk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/chutzpah-test-adapter-for-visual-studio-11-beta/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Monadic Pratt Parser</title>
		<link>http://matthewmanela.com/blog/a-monadic-pratt-parser/</link>
		<comments>http://matthewmanela.com/blog/a-monadic-pratt-parser/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 23:56:43 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Parsing]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1025</guid>
		<description><![CDATA[Introduction I recently read Beautiful Code which contains articles from several well known programmers about the code they consider beautiful.  In Top Down Operator Precedence, Douglas Crockford discusses the Pratt Parser (named after Vaughan Pratt who wrote the paper on &#8230; <a href="http://matthewmanela.com/blog/a-monadic-pratt-parser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>I recently read <a href="http://www.amazon.com/Beautiful-Code-Leading-Programmers-Practice/dp/0596510047" target="_blank">Beautiful Code</a> which contains articles from several well known programmers about the code they consider beautiful.  In <a href="http://javascript.crockford.com/tdop/tdop.html" target="_blank">Top Down Operator Precedence</a>, Douglas Crockford discusses the <a href="http://dl.acm.org/citation.cfm?id=512931">Pratt Parser</a> (named after <a href="http://boole.stanford.edu/pratt.html">Vaughan Pratt</a> who wrote the paper on it), also known as the Top Down Operator Precedence parser.  What makes this parsing technique interesting is that the syntax is defined in terms of tokens instead of grammar rules, an interesting way to define a language parser. As an example, Crockford defines the multiplication operator in terms of <strong>*</strong> token:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:5d41b430-0623-4678-ae87-613178b5a5ad" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 644px; height: 112px;" style="width: 644px; height: 112px; overflow: auto;">symbol("*", 60).led = function (left) {
    this.first = left;
    this.second = expression(60);
    this.arity = "binary";
    return this;
};</pre>
<p>&nbsp;</p>
</div>
<p>A Pratt parser works by reading through a stream of tokens and finding a symbol defined for the current token.  The symbol definition above for the <strong>*</strong> token defines how to build an abstract syntax tree (AST) node for that part of the token stream. The rest of the parser is defined similarly with symbols and functions for each significant piece of syntax in your language. I could go on about just how a Pratt parser works but <a href="http://eli.thegreenplace.net/2010/01/02/top-down-operator-precedence-parsing/" target="_blank">someone beat me to it</a>.</p>
<p>After reading about Pratt parsing I attempted my own implementation. I use F# which is a wonderful functional language supporting imperative style programming with mutable state. However, I feel a bit dirty using mutable state in a functional programming language (blame the hidden Haskell programmer in me) so I added the restriction that I will create my Pratt Parser in a pure functional manner.</p>
<h2>Monads + Pratt?</h2>
<p>Being purely functional meant fully embracing immutability. I manage the parser state by making use of the state monad which I <a href="http://matthewmanela.com/blog/functional-stateful-program-in-f/">have discussed previously</a> which makes use of the computation expression feature in F#. This creates very clean looking code since the state is being passed along in the background which makes it very easy to string functions together.</p>
<p>To create the monadic Pratt parser I define a few key types which are used throughout the code: <strong>Symbol&lt;’ex&gt;</strong> and <strong>InputState&lt;’ex&gt;.</strong></p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:259e9a79-7080-4f07-a9d9-ab05fb1bd529" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 848px; height: 498px;" style="width: 848px; height: 498px; overflow: auto;">// Parser states consists of 'a which is the return type of any given parser combinator
// and 'ex which is the user defined type of the AST they are building
type Parser&lt;'a, 'ex&gt; = StateMonad&lt;InputState&lt;'ex&gt;,'a&gt;

// A symbol is the core component of the Pratt Parser. You define how the parsing works
// by defining symbols for operators/tokens
and Symbol&lt;'ex&gt; =
    {
        name : string;
        led : Token -&gt; 'ex -&gt; Parser&lt;'ex,'ex&gt;;
        nud : Token -&gt; int -&gt; Parser&lt;'ex,'ex&gt;;
        lbp : int;
    }

// The state type for the parser. Maintains the list of input tokens, the current token,
// the current symbol and the user defined mapping of tokens to symbols
and InputState&lt;'ex&gt; =
    {
        tokens : seq&lt;Token&gt;;
        token : Token option;
        symbol : Symbol&lt;'ex&gt; option;
        symbolMap : Map&lt;string, Symbol&lt;'ex&gt;&gt;
    }</pre>
<p>&nbsp;</p>
</div>
<p>The <strong>InputState&lt;’ex&gt; </strong>type defines all the state that is passed between the functions of the parser. It contains:</p>
<ul>
<li>Tokens: The sequence of tokens received from the <a href="http://matthewmanela.com/blog/regex-based-lexer-with-f-2/">lexer</a></li>
<li>SymbolMap: The user defined mapping from a token’s name or value to a parser symbol.</li>
<li>Token:  The current token that the parser is on</li>
<li>Symbol: The corresponding symbol for the current token</li>
</ul>
<p>The <strong>Symbol&lt;’ex&gt; </strong>type contain the user defined logic for how to parse the pieces of the language.It contains:</p>
<ul>
<li>Name: The symbol name matches either a token’s name or value</li>
<li>Lbp: The left binding power of this symbol. Determines if it will grab the previous expression.</li>
<li>Nud: The function called when this symbol is executed with no arguments</li>
<li>Led: The function called when this symbol is executed with the previous expression’s result.</li>
</ul>
<p>To parse a program you define several symbols and add them to InputState’s initial SymbolMap. The nud and led functions in these symbols will build up pieces of an AST. For example, given an AST defined by the Expression type:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:d4c1bb15-47f1-467e-aa61-ef90b486c624" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 940px; height: 245px;" style="width: 940px; height: 245px; overflow: auto;">type Expression =
    | Call of Expression * Expression list
    | Cond of Expression * Expression * Expression
    | Let of Expression * Expression
    | Fun of Expression * Expression list * Expression
    | Id of String
    | Int of int
    | Float of float
    | Bool of bool</pre>
<p>&nbsp;</p>
</div>
<p>Here is a symbol which describes how to build an identifier node using the <strong>Id </strong>data constructor:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9c44f29c-d4d1-4835-870c-3e0e3a588b75" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 848px; height: 498px;" style="width: 848px; height: 498px; overflow: auto;">// Error function for symbols that don't define led
let errorLed token left =
    parser {
        return! error token "Symbol does not take a left argument"
    }

// The nud function for id which returns an Expression type using the Id data constructor
let idNud token rbp =
    parser {
      return Id token.text
    };

// A symbol for identifiers. Defines a nud function but not a
// led function since identifiers don't consume neighboring tokens
let idSymbol =
    {
        name = "ID";
        lbp = 0;
        nud = idNud;
        led = errorLed;
    }</pre>
<p>&nbsp;</p>
</div>
<p>Most symbols will follow a similar pattern so I created several helper methods to create symbols and build up the symbol map. I won’t go into each here (you can read the <a href="https://github.com/mmanela/Flango" target="_blank">source code</a>) but they let you build the symbol map in a declarative way. For example, this is the definition of a symbol map for a simple language:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:baeab68d-b02a-4d32-b5c0-f1ddc098ac40" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 876px; height: 639px;" style="width: 876px; height: 639px; overflow: auto;">let languageSymbolMap = Map.empty |&gt;  

                        // Add empty symbols
                        // Will error if called
                        addEmptySymbol ")" |&gt;
                        addEmptySymbol "THEN" |&gt;
                        addEmptySymbol "ELSE" |&gt;

                        // Simple literal values
                        addLiteralSymbol "INT" Int int |&gt;
                        addLiteralSymbol "FLOAT" Float double |&gt;
                        addLiteralSymbol "BOOL" Bool bool  |&gt;

                        // Binary right associative symbols
                        addInfixR "=" 10 neLed |&gt;
                        addInfixR "!=" 10 neLed |&gt;
                        addInfixR "&amp;&amp;" 30 andLed |&gt;
                        addInfixR "||" 30 orLed |&gt;

                        // Binary left associative symbols
                        addInfixL "&gt;" 40 gtLed |&gt;
                        addInfixL "&gt;=" 40 gteLed |&gt;
                        addInfixL "&lt;" 40 ltLed |&gt;
                        addInfixL "&lt;=" 40 lteLed |&gt;
                        addInfixL "+"  50 plusLed |&gt;
                        addInfixL "-" 50 minusLed |&gt;
                        addInfixL "*" 60 timesLed |&gt;
                        addInfixL "/" 60 divideLed |&gt;
                        addInfixL "^" 70 powerLed|&gt;

                        // Custom symbols
                        addSymbol eqSymbol |&gt;
                        addSymbol idSymbol |&gt;
                        addSymbol leftParenSymbol |&gt;
                        addSymbol letSymbol |&gt;
                        addSymbol funSymbol |&gt;
                        addSymbol ifSymbol |&gt;
                        addSymbol endSymbol</pre>
<p>&nbsp;</p>
</div>
<h2>Expression Parsing</h2>
<p>The heart of the Pratt parser is the expression parsing code which calls the led and nud methods defined on the symbols.  My implementation follows the method in <a href="http://javascript.crockford.com/tdop/tdop.html">Crockford’s</a> article very closely except that I use recursion instead of a loop and I extend the definition of the nud function to accept a right binding power.</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:eddac124-4326-4352-b909-187a5b563105" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 669px; height: 370px;" style="width: 669px; height: 370px; overflow: auto;">let rec leftBoundExpression rbp token symbol left =
    parser {
        if (rbp &lt; symbol.lbp) then
            do! advance()
            let! newLeft = symbol.led token left
            let! newToken, newSymbol = current()
            return! leftBoundExpression rbp newToken newSymbol newLeft
        else
            return left
    }

let expression rbp =
    parser {
        let! token, symbol = current()
        do!  advance()
        let! left = symbol.nud token rbp
        let! nextToken, nextSymbol = current()
        return! leftBoundExpression rbp nextToken nextSymbol left
    }</pre>
<p>&nbsp;</p>
</div>
<p>Adding the right binding power (rbp) parameter to the nud function makes it possible to parse a call expression like the ones found in Haskell or F#</p>
<blockquote><p>someFunction arg1 arg2 arg2</p></blockquote>
<p>To parse this expression the nud method for an <em>someFunction </em>must match the multiple expressions that come after it. This creates an issue since an identifier can be matched in two different ways: as a function call with arguments or as a stand alone identifier. We need to ensure the nud function for <em>arg1</em> doesn’t try to grab <em>arg2</em>. Passing the right binding power to the nud method solves this since the nud for <em>someFunction </em>can indicate that it wants the next expressions with a high binding power. Below is an updated version of the identifier method’s nud function demonstrating this:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:659850de-2352-4546-86b4-7ba627d9548a" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 761px; height: 385px;" style="width: 761px; height: 385px; overflow: auto;">let idNud token rbp =
    parser {
        if rbp &lt; 90 then
            let! args = manyExpressions 90
            if args.Length &gt; 0
            then return Call (token, args)
            else return Id token.text
        else
            return Id token.text
    };</pre>
<p>&nbsp;</p>
</div>
<h2>Parser Combinators</h2>
<p>In the code above you may have noticed the call to <strong>manyExpressions</strong>. This function will match as many expressions as it can and then returns them in a list.</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:4578d205-b522-4abf-aa86-bb4943b04455" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: fsharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 807px; height: 295px;" style="width: 807px; height: 295px; overflow: auto;">let rec manyExpressions rbp =
    parser {
        let! exp = expression rbp
        let! rest =  (manyExpressions rbp)
        return exp :: rest
    } &lt;|&gt; parser.Return []</pre>
<p>&nbsp;</p>
</div>
<p>What is interesting about this function is its base case. It will keep recursing trying to match expressions until it finds a symbol that does not define the nud method which causes the parser to return an error. This is where the <em>&lt;|&gt; parser.Return []</em> expression takes over.  The &lt;|&gt; symbol is a function defined on the state monad which combines two monads/parsers into one. This kind of function is called a <a href="http://en.wikipedia.org/wiki/Parser_combinator" target="_blank">parser combinator</a>. The first parser given to it will execute and if it eventually errors the parsing will backtrack until if finds an alternative (the right argument to &lt;|&gt;) or unwinds the stack completely and returns the error. In the code above the second parser is defined by  <em>parser.Return []</em>  which returns an empty list when the first parser errors.</p>
<p>Those familiar with the Haskell parser combinator library called <a href="http://www.haskell.org/haskellwiki/Parsec" target="_blank">Parsec</a> may recognize the &lt;|&gt; combinator. In Parsec it is a predictive combinator and will only try the second alternative if the first didn’t consume input. This differs from my implementation which will try the second alternative even if the the first expression consumed hundreds of tokens before it errored.</p>
<p>Parser combinators offer great power since they can be used to effectively provide infinite look-ahead. They make it easy to parse ambiguous language constructs. I only use them in a limited way but there is much room to expand them.</p>
<h2>Conclusion</h2>
<p>I wasn’t sure at first what a monadic Pratt Parser would look and feel like. However, I am very pleased with how clear and readable it is. The use of computation expressions in F# enabled a simple and concise syntax. The melding of Pratt parsing with parser combinators creates really expressive and powerful parsers. I am interested in exploring this further to see what issues and pitfalls this kind of parser design may have.</p>
<p>All the code for my monadic Pratt parser can be found on this <a href="https://github.com/mmanela/Flango" target="_blank">github page</a>. This repository also contains an implementation of a simple functional language which demonstrates using the parser. The key files to look at are:</p>
<ul>
<li><strong><a href="https://github.com/mmanela/Flango/blob/master/Flango/Parser.fs" target="_blank">Parser.fs</a></strong>– The code for the monadic Pratt parser</li>
<li><strong><a href="https://github.com/mmanela/Flango/blob/master/Flango/StateMonad.fs" target="_blank">StateMonad.fs</a></strong>– The state monad implementation the parser is built on</li>
<li><strong><a href="https://github.com/mmanela/Flango/blob/master/Flango/FlangoParserDefs.fs" target="_blank">FlangoParserDefs.fs</a></strong>– The definition of a simple language using the parser</li>
<li><a href="https://github.com/mmanela/Flango/blob/master/Flango/Lexer.fs" target="_blank"><strong>Lexer.fs</strong></a> – The code for a <a href="http://matthewmanela.com/blog/regex-based-lexer-with-f-2/" target="_blank">regex based lexer</a><!--EndFragment--></li>
<li><a href="https://github.com/mmanela/Flango/blob/master/Flango/FlangoLexDefs.fs" target="_blank"><strong>FlangoLexDefs.fs</strong></a> – The definition of the tokens for the simple language</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/writing-a-regular-expression-parser-in-haskell-part-1/" rel="bookmark" class="crp_title">Writing a Regular Expression parser in Haskell: Part 1</a></li><li><a href="http://matthewmanela.com/blog/regex-based-lexer-with-f-2/" rel="bookmark" class="crp_title">Regex based Lexer with F#</a></li><li><a href="http://matthewmanela.com/blog/writing-a-regular-expression-parser-in-haskell-part-2/" rel="bookmark" class="crp_title">Writing a Regular Expression parser in Haskell: Part 2</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/2pDm6z1c1W4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/a-monadic-pratt-parser/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Chutzpah 1.3.0 Released</title>
		<link>http://matthewmanela.com/blog/chutzpah-1-3-0-released/</link>
		<comments>http://matthewmanela.com/blog/chutzpah-1-3-0-released/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 22:17:14 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chutzpah]]></category>
		<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/blog/chutzpah-1-3-0-released/</guid>
		<description><![CDATA[A new version of Chutzpah is now live on Visual Studio Gallery, CodePlex and now NuGet. This release contains the following changes: Features 1. Chutzpah is now able to run Jasmine tests in addition to QUnit. This was a large &#8230; <a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A new version of Chutzpah is now live on <a href="http://visualstudiogallery.msdn.microsoft.com/71a4e9bd-f660-448f-bd92-f5a65d39b7f0">Visual Studio Gallery</a>, <a href="http://chutzpah.codeplex.com/">CodePlex</a> and now <a href="http://nuget.org/List/Packages/Chutzpah">NuGet</a>.</p>
<p>This release contains the following changes:</p>
<h3>Features</h3>
<p>1. Chutzpah is now able to run <a href="http://pivotal.github.com/jasmine/" target="_blank">Jasmine</a> tests in addition to <a href="http://docs.jquery.com/QUnit" target="_blank">QUnit</a>. This was a large feature and new Chutzpah contributor Ben (Qube) did an amazing job with it.</p>
<p>2. Added a new configuration option to set the timeout on a test file. By default this value is 3000ms but there are many cases when you may have long running tests where you need this to be longer. You can now set this timeout from the command line:</p>
<pre class="brush: plain; gutter: false; toolbar: false;">chutzpah.console.exe /timeoutMilliseconds 5000 mytest.js</pre>
<p>You can also set this inside of Visual Studio using the newly added options menu. You can find this menu under Tools-&gt;Options-&gt;Chutzpah.</p>
<p><a href="http://matthewmanela.com/wp-content/uploads/2011/11/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://matthewmanela.com/wp-content/uploads/2011/11/image_thumb.png" width="644" height="376"></a></p>
<p>&nbsp;</p>
<h3></h3>
<h3>Bug Fixes</h3>
<p>1. Chutzpah now copies over the text fixtures that you set in your html test harness.</p>
<p>2. Added missing doctype on the generated test harness.</p>
<p>3. Fixed bug where multiple references to qunit.js were copied into the generated test harness.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-2-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.2.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-4-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.4.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-1-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.1.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/Qyi1hB-kAEU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/chutzpah-1-3-0-released/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Moving and renaming resource keys in a .resx file</title>
		<link>http://matthewmanela.com/blog/moving-and-renaming-resource-keys-in-a-resx-file/</link>
		<comments>http://matthewmanela.com/blog/moving-and-renaming-resource-keys-in-a-resx-file/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 19:19:06 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Localization]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1396</guid>
		<description><![CDATA[I work on websites where we have several resource files that are localized in many languages. This makes operations like renaming a resource key and moving a resource key to a different file annoying since you must do it across &#8230; <a href="http://matthewmanela.com/blog/moving-and-renaming-resource-keys-in-a-resx-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I work on websites where we have several resource files that are localized in many languages. This makes operations like renaming a resource key and moving a resource key to a different file annoying since you must do it across several languages. To help with this I created a couple of PowerShell scripts to automate this process.</p>
<p>These PowerShell scripts assume your .resx files live in a folder named “Resources” but this can be easily changed.</p>
<h3>RenameResource.ps1</h3>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:65641c80-0288-41d6-851d-ccf0e99475ee" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: ps; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 710px; height: 372px;" style="width: 710px; height: 372px; overflow: auto;">param([String]$keyOld, [String]$keyNew)
if(-not $keyOld -or -not $keyOld) {
  echo "RenameResource.ps1 keyOld keyNew"
  return
}

$files=get-childitem Resources *.resx

foreach($file in $files) {
  $xml = [xml](Get-Content $file.FullName)
  $dataNode = $xml.root.data | Where-Object { $_.GetAttribute("name") -eq $keyOld }
  if ($dataNode -ne $null) {
    $dataNode.SetAttribute("name", $keyNew)
    $xml.Save($file.FullName)
  }
}</pre>
<p>&nbsp;</p>
</div>
<h3>MoveResource.ps1</h3>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e57505e0-7453-4794-bf89-39f6ff068709" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: ps; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 710px; height: 372px;" style="width: 710px; height: 372px; overflow: auto;">param([String]$resourceNameSource, [String]$resourceNameDestination, [string] $keyName)
if(-not $resourceNameSource -or -not $resourceNameDestination -or -not $keyName) {
  echo "MoveResource.ps1 resourceNameSource resourceNameDestination keyName"
  return
}

$sourceFiles = Get-ChildItem "Resources\$resourceNameSource*.resx"
$destFiles = Get-ChildItem "Resources\$resourceNameDestination*.resx"
$mapping = @{}

$sourceFiles | foreach {
  $parts = $_ -split "\."
  $list = New-Object "system.collections.arraylist"
  $list.Add($_) &gt; $null
  if($parts.Length -eq 2) {
    $mapping["en-us"] = $list
  }
  else {
    $mapping[$parts[1]] = $list
  }
}

$destFiles | foreach {
  $parts = $_ -split "\."
  if($parts.Length -eq 2) {
    $mapping["en-us"].Add($_ ) &gt; $null
  }
  else {
    $mapping[$parts[1]].Add($_ ) &gt; $null
  }
}

foreach($pair in $mapping.Values) {
  $sourcePath = $pair[0]
  $destPath = $pair[1]
  $source = [xml](Get-Content $sourcePath)
  $dest = [xml](Get-Content $destPath)

  $keyNodeSource = $source.root.data | Where-Object { $_.GetAttribute("name") -eq $keyName }
  $keyNodeDest = $dest.root.data | Where-Object { $_.GetAttribute("name") -eq $keyName }
  if ($keyNodeSource -eq $null) {
      echo "Key does not exist in source"
      return;
  }
  if($keyNodeDest -ne $null) {
    echo "Key already exists in destination"
    return;
  }
  try
  {
    $newNode = $dest.ImportNode($keyNodeSource.Clone(), $true)
    $source.root.RemoveChild($keyNodeSource) &gt; $null
    $dest.root.AppendChild($newNode) &gt; $null
    $dest.Save($destPath)
    $source.Save($sourcePath)
  }
  catch {
    Write-Host "Error text: " $_
    return
  }
}</pre>
<p>&nbsp;</p>
</div>
<h3>Usage</h3>
<p>Renaming a resource key:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:baacbc39-9326-4eb8-94d5-897e0d96a8e8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: plain; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 802px; height: 80px;" style="width: 802px; height: 80px; overflow: auto;">.\RenameResource.ps1 oldKey newKey</pre>
<p>&nbsp;</p>
</div>
<p>Moving a resource with key “keyName”  from a file named “ResourceFile1.resx” to “ResourceFile2.resx”:</p>
<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a950a9fb-9f0c-4290-aebd-a21d4e14d1c8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: plain; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 848px; height: 94px;" style="width: 848px; height: 94px; overflow: auto;">.\MoveResource.ps1 ResourceFile1 ResourceFile2 keyName</pre>
<p>&nbsp;</p>
</div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/making-an-executable-take-pipelined-input-in-powershell/" rel="bookmark" class="crp_title">Making an executable take pipelined input in PowerShell</a></li><li><a href="http://matthewmanela.com/blog/inheriting-base-type-mappings-with-automapper-extension/" rel="bookmark" class="crp_title">Inheriting base type mappings with AutoMapper</a></li><li><a href="http://matthewmanela.com/blog/a-simple-javascript-stubbing-function/" rel="bookmark" class="crp_title">A simple JavaScript stubbing function</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/mO7hBkjqQ20" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/moving-and-renaming-resource-keys-in-a-resx-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chutzpah 1.2.0 Released</title>
		<link>http://matthewmanela.com/blog/chutzpah-1-2-0-released/</link>
		<comments>http://matthewmanela.com/blog/chutzpah-1-2-0-released/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 05:29:01 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chutzpah]]></category>
		<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[NuGet]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1388</guid>
		<description><![CDATA[A new version of Chutzpah is now live on Visual Studio Gallery, CodePlex and now NuGet. This release contains the following changes. 1. Added the Chutzpah console runner as a NuGet package. Once installed the Chutzpah.Console.exe file will be located &#8230; <a href="http://matthewmanela.com/blog/chutzpah-1-2-0-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A new version of Chutzpah is now live on <a href="http://visualstudiogallery.msdn.microsoft.com/71a4e9bd-f660-448f-bd92-f5a65d39b7f0">Visual Studio Gallery</a>, <a href="http://chutzpah.codeplex.com/">CodePlex</a> and now <a href="http://nuget.org/List/Packages/Chutzpah" target="_blank">NuGet</a>.</p>
<p>This release contains the following changes.</p>
<p>1. Added the Chutzpah console runner as a <a href="http://nuget.org/List/Packages/Chutzpah">NuGet package</a>. Once installed the Chutzpah.Console.exe file will be located in the Tools directory of the Chutzpah package.</p>
<p>2. Added ability from command line and Visual Studio to have Chutzpah scan for test files when you execute it on a folder. This helps alleviate a pain point that arises when you break your JavaScript tests into multiple files. Before this change you would have to specify each file individually in the call to the console runner. Now it can take a folder name instead of a file name.</p>
<pre class="brush: plain; gutter: false; toolbar: false;">chutzpah.console.exe someFolder/jsTests</pre>
<p>When Chutzpah sees that you provided a folder it will scan recursively within that folder for .js files and run any it believes are QUnit test files.</p>
<p>3. Fixed a bug that caused Chutzpah to error on read-only files. This can be quite common since many source control systems can put files in this state.</p>
<p>4. Added a command line flag /OpenInBrowser which makes Chutzpah open the test files in your default browser.  This can be helpful since it allows you to debug the tests more easily.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-4-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.4.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.3.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-1-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.1.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/e1ncsH36QYs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/chutzpah-1-2-0-released/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Make your website faster with RequestReduce</title>
		<link>http://matthewmanela.com/blog/make-your-website-faster-with-requestreduce/</link>
		<comments>http://matthewmanela.com/blog/make-your-website-faster-with-requestreduce/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 01:23:35 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1380</guid>
		<description><![CDATA[My co-worker Matt Wrock released an open source project on GitHub and Nuget called RequestReduce.&#160; It is a very quick and easy way to dramatically improve the performance of an ASP.NET website. We use this library for our sites at &#8230; <a href="http://matthewmanela.com/blog/make-your-website-faster-with-requestreduce/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My co-worker <a href="http://www.mattwrock.com" target="_blank">Matt Wrock</a> released an open source project on <a href="https://github.com/mwrock/RequestReduce" target="_blank">GitHub</a> and <a href="http://nuget.org/List/Packages/RequestReduce" target="_blank">Nuget</a> called <a href="http://requestreduce.com" target="_blank">RequestReduce</a>.&nbsp; It is a very quick and easy way to dramatically improve the performance of an ASP.NET website. We use this library for our sites at work and after adding it we saw around an 18% improvement in global page load time.</p>
<p>RequestReduce works by examining the resources in an HTTP request and optimizes them before sending to the user. It will optimize them in the following ways (Matt Wrock’s <a href="http://www.mattwrock.com/post/2011/09/10/Adopt-RequestReduce-and-see-immediate-Yslow-and-Google-Page-Speed-score-improvements-not-to-mention-a-faster-site!.aspx" target="_blank">own words</a>):</p>
<blockquote><ul>
<li>Look for background images that it can sprite. This is the process of combining multiple images into a single image and using some CSS syntax to pull in specific images from that single file into a CSS class’s background.
<li>Merge these images into a single PNG that is quantized down to 256 colors and then run through optipng for lossless compression. Unsatisfied with the quality I was getting from the popular opensource quantizers, I created a quantizer based on the Wu quantization algorithm and have released that separately as <a href="http://nquant.codeplex.com/">nQuant</a> on codeplex. This often reduces the image size up to 3x smaller than the original.
<li>Merges all CSS in the head and minifies it.
<li>Manages the downloads of these CSS and image requests using ETag and expires headers to ensure optimal caching on the browser.</li>
</ul>
</blockquote>
<p>One of the nicest aspects of RequestReduce is how simple it is to start using. Just download the binaries to your website bin folder and add the following to your web.config:</p>
<pre class="brush: xml; gutter: false; toolbar: false;">&lt;system.webServer&gt;
 &lt;modules runAllManagedModulesForAllRequests="true"&gt;
  &lt;add name="RequestReduce" type="RequestReduce.Module.RequestReduceModule, RequestReduce, Version=1.0.0.0,
  Culture=neutral" /&gt;
 &lt;/modules&gt;
&lt;/system.webServer&gt;
</pre>
<p>If you are interested I would definitely head over to the <a href="http://requestreduce.com" target="_blank">RequestReduce</a> website to read the detailed documentation (including advanced configuration options) and the source code (yay for open source <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://matthewmanela.com/wp-content/uploads/2011/09/wlEmoticon-smile.png"> ).</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.3.0 Released</a></li><li><a href="http://matthewmanela.com/blog/diffplex-1-2-released/" rel="bookmark" class="crp_title">DiffPlex 1.2 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-2-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.2.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/4P-8y4oWPsM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/make-your-website-faster-with-requestreduce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update on inheriting base type mappings with AutoMapper</title>
		<link>http://matthewmanela.com/blog/update-on-inheriting-base-type-mappings-with-automapper/</link>
		<comments>http://matthewmanela.com/blog/update-on-inheriting-base-type-mappings-with-automapper/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 16:45:04 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[AutoMapper]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1373</guid>
		<description><![CDATA[Several months ago I wrote this post which shows an extension method for inheriting the mappings on a base type for a child type in AutoMapper.&#160; Since then I have had a few comments on the post which led me &#8230; <a href="http://matthewmanela.com/blog/update-on-inheriting-base-type-mappings-with-automapper/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Several months ago I wrote <a href="http://matthewmanela.com/blog/inheriting-base-type-mappings-with-automapper-extension/" target="_blank">this post</a> which shows an extension method for inheriting the mappings on a base type for a child type in <a href="http://automapper.codeplex.com/" target="_blank">AutoMapper</a>.&nbsp; Since then I have had a few comments on the post which led me to make a small update. One of the assumptions I made in my implementation was that when inheriting base type mappings both of your mapping types will have their base types in the parent mapping. For example:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:df6587ce-ebd0-4d05-ae22-3c77071231f0" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 925px; height: 131px;" style=" width: 925px; height: 131px;overflow: auto;">Mapper.CreateMap&lt;SourceBaseClass, DestBaseClass&gt;()
&#160;&#160;&#160;&#160;.ForMember(x =&gt; x.BasePropTwo, m =&gt; m.MapFrom(x =&gt; x.BaseProp2));
&#160;
Mapper.CreateMap&lt;SourceChildClass, DestChildClass&gt;()
&#160;&#160;&#160;&#160;.ForMember(x =&gt; x.ChildPropTwo, m =&gt; m.MapFrom(x =&gt; x.ChildProp2))
&#160;&#160;&#160;&#160;.InheritMappingFromBaseType();</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>However, there are scenarios where you may have one type that is mapping to both a parent and child type and would still want to inherit the parent mapping for the child mapping. If you try this with my previous code it would look like this but not work.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:04bda575-d8b6-43c6-8864-f8838ab37a0d" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 925px; height: 148px;" style=" width: 925px; height: 148px;overflow: auto;">Mapper.CreateMap&lt;SourceClass, DestBaseClass&gt;()
&#160;&#160;&#160;&#160;.ForMember(x =&gt; x.BasePropTwo, m =&gt; m.MapFrom(x =&gt; x.BaseProp2));
&#160;
Mapper.CreateMap&lt;SourceClass, DestChildClass&gt;()
&#160;&#160;&#160;&#160;.ForMember(x =&gt; x.ChildPropTwo, m =&gt; m.MapFrom(x =&gt; x.ChildProp2))
&#160;&#160;&#160;&#160;.InheritMappingFromBaseType();</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>In order to support this scenario I updated the extension method to take an optional enum which specifies if you want to inherit a mapping that has a base type for the source type, destination type or both.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:2585aa6e-923e-4da0-b45b-4f46d6f7c497" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 925px; height: 672px;" style=" width: 925px; height: 672px;overflow: auto;">public enum WithBaseFor
{
    Source,
    Destination,
    Both
}

public static class Inheritance
{
    public static void InheritMappingFromBaseType&lt;TSource, TDestination&gt;(this IMappingExpression&lt;TSource, TDestination&gt; mappingExpression,
                                                                         WithBaseFor baseFor = WithBaseFor.Both)
    {
        var sourceType = typeof (TSource);
        var destinationType = typeof (TDestination);
        var sourceParentType = baseFor == WithBaseFor.Both || baseFor == WithBaseFor.Source
                                   ? sourceType.BaseType
                                   : sourceType;

        var destinationParentType = baseFor == WithBaseFor.Both || baseFor == WithBaseFor.Destination
                                        ? destinationType.BaseType
                                        : destinationType;

        mappingExpression
            .BeforeMap((x, y) =&gt; Mapper.Map(x, y, sourceParentType, destinationParentType))
            .ForAllMembers(x =&gt; x.Condition(r =&gt; NotAlreadyMapped(sourceParentType, destinationParentType, r)));
    }

    private static bool NotAlreadyMapped(Type sourceType, Type desitnationType, ResolutionContext r)
    {
        return !r.IsSourceValueNull &amp;&amp;
               Mapper.FindTypeMapFor(sourceType, desitnationType).GetPropertyMaps().Where(
                   m =&gt; m.DestinationProperty.Name.Equals(r.MemberName)).Select(y =&gt; !y.IsMapped()).All(b =&gt; b);
    }
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Using this new code the above mapping becomes</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:5620bf5d-9a07-46db-b921-83688e7c40d7" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: false;  width: 925px; height: 157px;" style=" width: 925px; height: 157px;overflow: auto;">Mapper.CreateMap&lt;SourceClass, DestBaseClass&gt;()
    .ForMember(x =&gt; x.BasePropTwo, m =&gt; m.MapFrom(x =&gt; x.BaseProp2));

Mapper.CreateMap&lt;SourceClass, DestChildClass&gt;()
    .ForMember(x =&gt; x.ChildPropTwo, m =&gt; m.MapFrom(x =&gt; x.ChildProp2))
    .InheritMappingFromBaseType(WithBaseFor.Destination);</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>There is one caveat to using my InheritMappingFromBaseType extension method that was discovered since my original post … it is not compatible with the <strong>Mapper.AssertConfigurationIsValid()</strong> call. It will cause this function to fail even though your mapping will work fine. I haven’t had a chance to figure out if there is a way around this but if anyone has an idea I would love to hear it.</p>
<p>I published the updated code and a sample project showing its use to the <a href="https://github.com/mmanela/InheritedAutoMapper" target="_blank">InheritedAutoMapper GitHub page</a>. Feel free to grab the code and fork it to your liking.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/inheriting-base-type-mappings-with-automapper-extension/" rel="bookmark" class="crp_title">Inheriting base type mappings with AutoMapper</a></li><li><a href="http://matthewmanela.com/blog/making-an-executable-take-pipelined-input-in-powershell/" rel="bookmark" class="crp_title">Making an executable take pipelined input in PowerShell</a></li><li><a href="http://matthewmanela.com/blog/return-type-overloading-in-haskell/" rel="bookmark" class="crp_title">Return type overloading in Haskell</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/ErM7DWN-Ves" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/update-on-inheriting-base-type-mappings-with-automapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chutzpah 1.1.0 Released</title>
		<link>http://matthewmanela.com/blog/chutzpah-1-1-0-released/</link>
		<comments>http://matthewmanela.com/blog/chutzpah-1-1-0-released/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 13:26:32 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Chutzpah]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://matthewmanela.com/?p=1371</guid>
		<description><![CDATA[A new version of Chutzpah is now live on Visual Studio Gallery and CodePlex. This release contains the following changes: Added a “Run JS Tests in Browser” menu option inside of Visual Studio. This will open your default browser and &#8230; <a href="http://matthewmanela.com/blog/chutzpah-1-1-0-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A new version of Chutzpah is now live on <a href="http://visualstudiogallery.msdn.microsoft.com/71a4e9bd-f660-448f-bd92-f5a65d39b7f0" target="_blank">Visual Studio Gallery</a> and <a href="http://chutzpah.codeplex.com/" target="_blank">CodePlex</a>.</p>
<p>This release contains the following changes:</p>
<ul>
<li>Added a “Run JS Tests in Browser” menu option inside of Visual Studio. This will open your default browser and run the selected QUnit test file.
<li>Automatically save the test file in Visual Studio when you choose “Run JS Tests”
<li>Added keyboard shortcut support for Visual Studio
<ul>
<li>Bind a shortcut to the <strong>ProjectAndSolutionsContextMenus.Project.RunJSTests</strong> command to run JS tests</li>
</ul>
<ul><!--EndFragment--></ul>
<li>Return line and column position for failed tests when you run a test JS file directly.
<li>Upgraded to <a href="http://www.phantomjs.org/" target="_blank">PhantomJS 1.2</a> </li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://matthewmanela.com/blog/chutzpah-1-2-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.2.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-4-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.4.0 Released</a></li><li><a href="http://matthewmanela.com/blog/chutzpah-1-3-0-released/" rel="bookmark" class="crp_title">Chutzpah 1.3.0 Released</a></li></ul></div><img src="http://feeds.feedburner.com/~r/Farblondzshet/~4/qGPyfpye-84" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/blog/chutzpah-1-1-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced

Served from: matthewmanela.com @ 2012-05-08 07:19:14 -->

