<?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>Ian Obermiller</title>
	<atom:link href="http://ianobermiller.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianobermiller.com</link>
	<description>Part time hacker, full time dad.</description>
	<lastBuildDate>Wed, 13 Mar 2013 22:54:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Pretty printing text with even line lengths</title>
		<link>http://ianobermiller.com/blog/2013/02/18/pretty-printing-text-with-even-line-lengths/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pretty-printing-text-with-even-line-lengths</link>
		<comments>http://ianobermiller.com/blog/2013/02/18/pretty-printing-text-with-even-line-lengths/#comments</comments>
		<pubDate>Tue, 19 Feb 2013 07:31:15 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=187</guid>
		<description><![CDATA[The following demo pretty prints the entered text to the desired line width by making the lines as even as possible. The demo uses a dynamic programming algorithm to choose line breaks in such a way that the sum of the squares of the slack is minimized. Line length Basic wrapping Call me Ishmael. Some [...]]]></description>
				<content:encoded><![CDATA[<p>The following demo pretty prints the entered text to the desired line width by making the lines as even as possible. The demo uses a dynamic programming algorithm to choose line breaks in such a way that the sum of the squares of the slack is minimized.</p>
<p><span id="more-187"></span></p>
<h3>Line length</h3>
<p><input id="line-length" type="number" value="46" /></p>
<h3>Basic wrapping</h3>
<p><textarea id="raw-text" rows="6">Call me Ishmael. Some years ago, never mind how long precisely, having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world.</textarea></p>
<h3>Formatted text</h3>
<p>
<pre id="formatted"></pre>
</p>
<h2>Javascript Source</h2>
<p>The javascript source, should work in any ES5 compatible browser:</p>
<pre class="brush: jscript; title: ; notranslate">
function prettyPrint(text, lineLength) {
    var words = text.split(' ');
    var lengths = words.map(function(w) { return w.length; });
    var opt = [];
    var index = [];
    for (var j = 0; j &lt; words.length; j++)
    {
        // Let i be the index that minimizes the expression slack(i, j) + opt[i – 1]
        var minIndex = -1;
        var minError = Number.MAX_VALUE;
        for (var i = 0; i &lt;= j; i++)
        {
            // Sum the lengths of words from i to j
            var len = sum(lengths.slice(i, j + 1).map(function(n) {return n + 1; })) - 1;

            // Slack is the distance from the end of the line
            var slack = lineLength - len;

            // If it is negative, we have picked up too many words
            if (slack &lt; 0) continue;

            // Error is equal to the slack squared plus the previous optimal error
            var error = slack * slack;
            if (i &gt; 0) error += opt[i - 1];

            // Save only the lowest error
            if (error &lt; minError)
            {
                minError = error;
                minIndex = i;
            }
        }
        opt[j] = minError;
        index[j] = minIndex;
    }

    // The minimum slack will be in opt[n – 1]
    // To reconstruct the lines:
    var x = words.length - 1;
    var lines = [];
    while (x &gt;= 0)
    {
        // Add line consisting of words from index[x] to x
        lines.unshift(words.slice(index[x], x + 1).join(' '));
        x = index[x] - 1;
    }
    return lines.join('\n');
}

function sum(numbers) {
    var s = 0;
    for (var i = 0; i &lt; numbers.length; i++) {
        s += numbers[i];
    }
    return s;
}

window.onload = function() {
    var pre = document.getElementById('formatted'), 
        text = document.getElementById('raw-text'), 
        length = document.getElementById('line-length');

    var ts = function() {
        text.setAttribute('cols', length.value);
        pre.innerText = (prettyPrint(text.value, Number(length.value)));
    };

    ts();

    length.onchange = length.onclick = text.onchange = text.onkeyup = text.onclick = ts;
};
</pre>
<p><script src="/prettyPrintDemo.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2013/02/18/pretty-printing-text-with-even-line-lengths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Performance: :not() vs .not()</title>
		<link>http://ianobermiller.com/blog/2013/01/24/jquery-performance-not-vs-not/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-performance-not-vs-not</link>
		<comments>http://ianobermiller.com/blog/2013/01/24/jquery-performance-not-vs-not/#comments</comments>
		<pubDate>Fri, 25 Jan 2013 00:56:24 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=179</guid>
		<description><![CDATA[While doing some profiling on Socl, I noticed a particular jQuery selector that was taking an inordinate amount of time to run: The purpose of the code is to find elements that can be translated, but haven&#8217;t been already. My suspicion was on the .not() addition, and lo and behold, inlining the clause into the [...]]]></description>
				<content:encoded><![CDATA[<p>While doing some profiling on <a href="http://so.cl" title="Socl">Socl</a>, I noticed a particular jQuery selector that was taking an inordinate amount of time to run:</p>
<pre class="brush: jscript; title: ; notranslate">var toTranslate = this.$element.find('.translatable').not('.translated');</pre>
<p>The purpose of the code is to find elements that can be translated, but haven&#8217;t been already. My suspicion was on the <code>.not()</code> addition, and lo and behold, inlining the clause into the first selector dramatically increased performance:</p>
<pre class="brush: jscript; title: ; notranslate">var toTranslate = this.$element.find('.translatable:not(.translated)');</pre>
<p><span id="more-179"></span>But, don&#8217;t take my word alone for it; check out this <a href="http://jsperf.com/jquery-css3-not-vs-not">jsPerf testing jQuery CSS3 :not vs .not()</a>. The creator of the test summed it up nicely:</p>
<blockquote><p>So the outcome is that it&#8217;s faster to use a CSS3 selector in virtually all browsers (except IE8), by a factor of around 2-3.</p></blockquote>
<p>Where performance isn&#8217;t critical, however, heeding this advice about readability from the <a href="http://api.jquery.com/not-selector/">jQuery :not() Selector documentation</a> would be wise:</p>
<blockquote><p>The .not() method will end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter. In most cases, it is a better choice.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2013/01/24/jquery-performance-not-vs-not/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Highlight search terms in C#, Javascript and TypeScript</title>
		<link>http://ianobermiller.com/blog/2013/01/19/highlight-search-terms-in-c-javascript-and-typescript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=highlight-search-terms-in-c-javascript-and-typescript</link>
		<comments>http://ianobermiller.com/blog/2013/01/19/highlight-search-terms-in-c-javascript-and-typescript/#comments</comments>
		<pubDate>Sun, 20 Jan 2013 06:32:07 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[TypeScript]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=162</guid>
		<description><![CDATA[Following is a function that given a string and a search query will wrap bold tags around search terms that were found in the query: Example: text = &#8220;The theory of the big bang was proposed in&#8230;&#8221; query = &#8220;Big Bang Theory&#8221; result = &#8220;The &#60;b&#62;theory&#60;/b&#62; of the &#60;b&#62;big&#60;/b&#62; &#60;b&#62;bang&#60;/b&#62; was proposed in&#8230;&#8221; result as [...]]]></description>
				<content:encoded><![CDATA[<p>Following is a function that given a string and a search query will wrap bold tags around search terms that were found in the query:</p>
<p>Example:</p>
<p>text = &#8220;The theory of the big bang was proposed in&#8230;&#8221;<br />
query = &#8220;Big Bang Theory&#8221;<br />
result = &#8220;The &lt;b&gt;theory&lt;/b&gt; of the &lt;b&gt;big&lt;/b&gt; &lt;b&gt;bang&lt;/b&gt; was proposed in&#8230;&#8221;<br />
result as html = The <b>theory</b> of the <b>big</b> <b>bang</b> was proposed in&#8230;.<br />
<span id="more-162"></span><br />
C# version:<br />
<small>(note: you may want to return an HtmlString instead to make it easier to call from a view.)</small></p>
<pre class="brush: csharp; title: ; notranslate">
string HighlightSearchTerms(string text, string query)
{
    var terms = query.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(s =&gt; s.Replace(&quot;|&quot;, &quot;\\|&quot;));
    var regex = new Regex(&quot;(&quot; + string.Join(&quot;|&quot;, terms) + &quot;)&quot;, RegexOptions.IgnoreCase);
    return regex.Replace(text, &quot;&lt;b&gt;${0}&lt;/b&gt;&quot;);
}
</pre>
<p>Javascript version:<br />
<small>(note: <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map" title="Array.prototype.map at Mozilla Developer Network">Array.prototype.map is in ES5 and may require a shim</a>.)</small></p>
<pre class="brush: jscript; title: ; notranslate">
function highlightSearchTerms(text, query) {
    var terms = query.split(' ').map(function(s) { return s.replace('|', '\\|'); });
    var regex = new RegExp('(' + terms.join('|') + ')', 'gi');
    return text.replace(regex, '&lt;b&gt;$&amp;&lt;/b&gt;');
}
</pre>
<p>TypeScript version:<br />
<small>(just the JS version with type annotations)</small></p>
<pre class="brush: typescript; title: ; notranslate">
function highlightSearchTerms(text: string, query: string): string {
    var terms = query.split(' ').map(function(s) { return s.replace('|', '\\|'); });
    var regex = new RegExp('(' + terms.join('|') + ')', 'gi');
    return text.replace(regex, '&lt;b&gt;$&amp;&lt;/b&gt;');
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2013/01/19/highlight-search-terms-in-c-javascript-and-typescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TypeScript Syntax Highlighting for WordPress</title>
		<link>http://ianobermiller.com/blog/2012/10/03/typescript-syntax-highlighting-for-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=typescript-syntax-highlighting-for-wordpress</link>
		<comments>http://ianobermiller.com/blog/2012/10/03/typescript-syntax-highlighting-for-wordpress/#comments</comments>
		<pubDate>Wed, 03 Oct 2012 16:15:31 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[TypeScript]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=141</guid>
		<description><![CDATA[For my first post on TypeScript, I included many code samples, and found the Javascript highlighting to be lacking since TypeScript introduces a number of new keywords. To remedy, I&#8217;ve put together a simple plugin that adds a TypeScript brush to the SyntaxHighlighter Evolved plugin, using this excellent tutorial. Once installed, you can use the [...]]]></description>
				<content:encoded><![CDATA[<p>For my <a href="http://ianobermiller.com/blog/2012/10/01/typescript-highlights/">first post on TypeScript</a>, I included many code samples, and found the Javascript highlighting to be lacking since TypeScript introduces a number of new keywords. To remedy, I&#8217;ve put together a simple plugin that adds a TypeScript brush to the <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/">SyntaxHighlighter Evolved plugin</a>, using <a href="http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/adding-a-new-brush-language/">this excellent tutorial</a>. Once installed, you can use the new tags to highlight your TypeScript code, either <code>&#91;ts][/ts]</code> or <code>&#91;typescript][/typescript]</code>.</p>
<p><a href='http://ianobermiller.com/wp-content/uploads/2012/10/SyntaxHighlighter-Evolved-TypeScript-Brush.zip'>Download the &quot;SyntaxHighlighter Evolved: TypeScript Brush&quot; plugin</a></p>
<p><span id="more-141"></span></p>
<p>Here is an example:</p>
<pre class="brush: typescript; title: ; notranslate">
declare var jQuery: any;

module Sayings {
    export class Greeter extends BaseGreeter implements IGreeter {
        private greeting: string;

        constructor (message: string) {
            this.greeting = message;
        }

        public greet() {
            var s = &quot;Hello, &quot; + this.greeting;
            return s;
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/10/03/typescript-syntax-highlighting-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TypeScript Highlights</title>
		<link>http://ianobermiller.com/blog/2012/10/01/typescript-highlights/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=typescript-highlights</link>
		<comments>http://ianobermiller.com/blog/2012/10/01/typescript-highlights/#comments</comments>
		<pubDate>Mon, 01 Oct 2012 21:14:44 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[TypeScript]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=120</guid>
		<description><![CDATA[Microsoft recently released a new, open source language called TypeScript. It is a strict superset of Javascript, and compiles directly to Javascript. The compiler is open source, and written in TypeScript itself. My team at Microsoft has been dogfooding TypeScript for several months now, and I thought I&#8217;d share a few of my favorite parts [...]]]></description>
				<content:encoded><![CDATA[<p>Microsoft recently released a new, open source language called <a href="http://www.typescriptlang.org">TypeScript</a>. It is a strict superset of Javascript, and compiles directly to Javascript. The compiler is open source, and written in TypeScript itself. My team at Microsoft has been dogfooding TypeScript for several months now, and I thought I&#8217;d share a few of my favorite parts of the language.</p>
<p><span id="more-120"></span></p>
<p>Note: you can try out the TypeScript language easily, in your browser, with the <a href="http://typescriptlang.org/playground">TypeScript Playground</a>.</p>
<h2>Classes and modules</h2>
<p>Per the <a href="http://go.microsoft.com/fwlink/?LinkId=267238">language specification</a>: </p>
<blockquote><p>TypeScript syntax includes several proposed features of Ecmascript 6 (ES6), including classes and modules.</p></blockquote>
<p>Modules can export classes, functions, and variables, and classes can have static and instance members. Classes members can have private or public scope, which is enforced by the compiler. As an example:</p>
<pre class="brush: typescript; title: ; notranslate">
export module Sayings {
    export class Greeter {
        private greeting: string;

        constructor(greeting: string) {
            this.greeting = greeting;
        }

        public greet(): void {
            alert(this.greeting);
        }
    }
}
</pre>
<h2>Inheritance</h2>
<p>Classes can <code>extend</code> a single base class to inherit and optionally override all its members. Overridden methods in the derived class must have a compatible signature to the base class implementation.</p>
<pre class="brush: typescript; title: ; notranslate">
class A {
    x() { alert('a.x'); }
    y() { alert('a.y'); }
}

class B extends A {
    y() { alert('b.y'); }
}

new A().x(); // prints 'a.x'
new A().y(); // prints 'a.y'
new B().x(); // prints 'a.x'
new B().y(); // prints 'b.y'
</pre>
<h2>Lambdas</h2>
<p>Lambdas are not only shortened syntax for the <code>function</code> keyword, but also capture the <code>this</code> variable automatically if you are inside a class.</p>
<pre class="brush: typescript; title: ; notranslate">
class Greeter {
    greeting: string = 'hello ';

    public makeGreeter(): (name: string) =&gt; string {
        return name =&gt; this.greeting + name;
    }
}
</pre>
<h2>Interfaces and Structural Typing</h2>
<p>Interfaces are simple to use with internal and external code, and is checked using structural typing. Classes can implement interfaces to enforce checking, and interfaces can extend other interfaces.</p>
<pre class="brush: typescript; title: ; notranslate">
class Greeter {
    greet() { alert('Hello'); }
}   
interface IGreeter {
    greet();
}

var greeter: IGreeter = new Greeter();
greeter.greet();
</pre>
<h2>Type inference</h2>
<p>TypeScript has extensive type inference. In the following example, the function greet will be typed <code>(number) =&gt; string</code>:</p>
<pre class="brush: typescript; title: ; notranslate">
class Greet {
    greet(x: number) {
        var s = ' greetings';
        return x + s;
    }
}
</pre>
<p>Static and member vars, return types, local variables, all are type inferred.</p>
<h2>Javascript is TypeScript</h2>
<p>TypeScript is a superset of Javascript, so converting you codebase is instant. Once you are using the TypeScript compiler, you can begin adding type annotations to enable more robust type checking.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/10/01/typescript-highlights/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ for Javascript</title>
		<link>http://ianobermiller.com/blog/2012/09/19/linq-for-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-for-javascript</link>
		<comments>http://ianobermiller.com/blog/2012/09/19/linq-for-javascript/#comments</comments>
		<pubDate>Thu, 20 Sep 2012 00:17:31 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=115</guid>
		<description><![CDATA[While evaluating the different options for bringing LINQ-like operators to JavaScript, I compiled the following list of existing libraries: $linq - http://jscriptlinq.codeplex.com/ jLinq - http://hugoware.net/projects/jlinq from.js - http://fromjs.codeplex.com/ linq.js - http://linqjs.codeplex.com/ LINQ to JavaScript - http://jslinq.codeplex.com/ JSINQ - http://jsinq.codeplex.com/ Underscore.js - http://underscorejs.org/#chaining I&#8217;d love to hear about any others!]]></description>
				<content:encoded><![CDATA[<p>While evaluating the different options for bringing LINQ-like operators to JavaScript, I compiled the following list of existing libraries:</p>
<ul>
<li>$linq - <a href="http://jscriptlinq.codeplex.com/">http://jscriptlinq.codeplex.com/</a></li>
<li>jLinq - <a href="http://hugoware.net/projects/jlinq">http://hugoware.net/projects/jlinq</a></li>
<li>from.js - <a href="http://fromjs.codeplex.com/">http://fromjs.codeplex.com/</a></li>
<li>linq.js - <a href="http://linqjs.codeplex.com/">http://linqjs.codeplex.com/</a></li>
<li>LINQ to JavaScript - <a href="http://jslinq.codeplex.com/">http://jslinq.codeplex.com/</a></li>
<li>JSINQ - <a href="http://jsinq.codeplex.com/">http://jsinq.codeplex.com/</a></li>
<li>Underscore.js - <a href="http://underscorejs.org/#chaining">http://underscorejs.org/#chaining</a></li>
</ul>
<p>I&#8217;d love to hear about any others!</p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/09/19/linq-for-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC error: &#8220;Cannot create an abstract class&#8221;</title>
		<link>http://ianobermiller.com/blog/2012/08/02/mvc-error-cannot-create-an-abstract-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mvc-error-cannot-create-an-abstract-class</link>
		<comments>http://ianobermiller.com/blog/2012/08/02/mvc-error-cannot-create-an-abstract-class/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 22:44:03 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[T4]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=100</guid>
		<description><![CDATA[While debugging an MVC4 app, I ran into the following error: System.MissingMethodException: Cannot create an abstract class. It was only happening for a single Action, and I wasn&#8217;t able to set a breakpoint in that action. After some trial and error, I was able to find the issue in the code: The goal was to [...]]]></description>
				<content:encoded><![CDATA[<p>While debugging an MVC4 app, I ran into the following error: <code>System.MissingMethodException: Cannot create an abstract class</code>. It was only happening for a single Action, and I wasn&#8217;t able to set a breakpoint in that action. After some trial and error, I was able to find the issue in the code:</p>
<pre class="brush: csharp; title: ; notranslate">
public virtual ActionResult Login(ActionResult redirectAction = null)
{
    ...
}
</pre>
<p>The goal was to have an T4MVC style helper for passing in an ActionResult instead of an untyped path. This was a bad idea, as ActionResult is an abstract class. When I hit <code>http://localhost:2995/Account/Login</code>, the MVC framework tried to instantiate <code>ActionResult</code> to fill in the default value for <code>redirectAction</code>. I simply reverted the parameter back to a string, and all was well.</p>
<pre class="brush: csharp; title: ; notranslate">
public virtual ActionResult Login(string redirectPath = null)
{
    redirectPath = redirectPath ?? Url.Action(MVC.Home.Index());
    ...
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/08/02/mvc-error-cannot-create-an-abstract-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Type or namespace does not exist when compiling MVC View</title>
		<link>http://ianobermiller.com/blog/2012/07/28/type-or-namespace-does-not-exist-when-compiling-mvc-view/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=type-or-namespace-does-not-exist-when-compiling-mvc-view</link>
		<comments>http://ianobermiller.com/blog/2012/07/28/type-or-namespace-does-not-exist-when-compiling-mvc-view/#comments</comments>
		<pubDate>Sat, 28 Jul 2012 18:57:19 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=95</guid>
		<description><![CDATA[I ran into the following common error when trying to run my ASP.NET MVC 4 website: d:\temp\2pirqzul.5yz\temp\root\898a687c\8681620c\App_Web_jfuizczv.0.cs(27): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'DealBoxy' (are you missing an assembly reference?) While normally a straightforward error, this one was confusing, because I was certain that I had referenced [...]]]></description>
				<content:encoded><![CDATA[<p>I ran into the following common error when trying to run my ASP.NET MVC 4 website:</p>
<p><code>d:\temp\2pirqzul.5yz\temp\root\898a687c\8681620c\App_Web_jfuizczv.0.cs(27): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'DealBoxy' (are you missing an assembly reference?)</code></p>
<p>While normally a straightforward error, this one was confusing, because I was certain that I had referenced the <code>DealBoxy</code> project correctly.</p>
<p>It turns out that DealBoxy was compiling to an exe, and apparently ASP.NET won&#8217;t load exes the same way it will dlls. Changing the Output type to Class Library in the Application tab of the project settings did the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/07/28/type-or-namespace-does-not-exist-when-compiling-mvc-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Precompile Handlebars Template in .NET using Jurassic</title>
		<link>http://ianobermiller.com/blog/2012/07/25/precompile-handlebars-template-in-net-using-jurassic/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=precompile-handlebars-template-in-net-using-jurassic</link>
		<comments>http://ianobermiller.com/blog/2012/07/25/precompile-handlebars-template-in-net-using-jurassic/#comments</comments>
		<pubDate>Wed, 25 Jul 2012 17:52:36 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Handlebars]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Jurassic]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=84</guid>
		<description><![CDATA[The awesome Handlebars.js templating library, a superset of Mustache, has functions built-in for precompiling a template to a javascript function. Unfortunately, the instructions are only for Node.js. Using the Jurassic javascript compiler for .NET, it is simple to precompile your Handlebars template in C# and serve up the template functions in your javascript: The function [...]]]></description>
				<content:encoded><![CDATA[<p>The awesome <a href="http://handlebarsjs.com/">Handlebars.js</a> templating library, a superset of <a href="http://mustache.github.com/">Mustache</a>, has functions built-in for <a href="http://handlebarsjs.com/precompilation.html" title="Precompiling a Handlebars template">precompiling a template</a> to a javascript function. Unfortunately, the instructions are only for Node.js. Using the <a href="http://jurassic.codeplex.com/">Jurassic</a> javascript compiler for .NET, it is simple to precompile your Handlebars template in C# and serve up the template functions in your javascript:</p>
<p><span id="more-84"></span></p>
<pre class="brush: csharp; title: ; notranslate">
using Jurassic;

public string PrecompileHandlebarsTemplate(string name, string template)
{
    var engine = new ScriptEngine();
    engine.ExecuteFile(@&quot;handlebars-1.0.0.beta.6.js&quot;);
    engine.Execute(@&quot;var precompile = Handlebars.precompile;&quot;);
    return string.Format(&quot;var {0} = Handlebars.template({1});&quot;, 
        name, engine.CallGlobalFunction(&quot;precompile&quot;, template).ToString());
}
</pre>
<p>The function can be used as follows:</p>
<pre class="brush: csharp; title: ; notranslate">
PrecompileHandlebarsTemplate(&quot;greet&quot;, &quot;&lt;div&gt;{{hello}} world!&lt;/div&gt;&quot;);
</pre>
<p>And will output a javascript function as a string, something like this:</p>
<pre class="brush: jscript; title: ; notranslate">
var greet = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  helpers = helpers || Handlebars.helpers;
  var buffer = &quot;&quot;, stack1, foundHelper, self=this, functionType=&quot;function&quot;, helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;


  buffer += &quot;&lt;div&gt;&quot;;
  foundHelper = helpers.hello;
  stack1 = foundHelper || depth0.hello;
  if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
  else if(stack1=== undef) { stack1 = helperMissing.call(depth0, &quot;hello&quot;, { hash: {} }); }
  buffer += escapeExpression(stack1) + &quot; world!&lt;/div&gt;&quot;;
  return buffer;});
</pre>
<p>Which you can then use easily in the rest of your javascript (after including <code>handlebars.runtime.js</code>):</p>
<pre class="brush: jscript; title: ; notranslate">
$('body').append(greet({ hello: 'Bonjour' }));
</pre>
<p>You can find a <a href="http://jsbin.com/ojopig/2/">working example at JS Bin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/07/25/precompile-handlebars-template-in-net-using-jurassic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RestSharp Extensions Returning Tasks</title>
		<link>http://ianobermiller.com/blog/2012/07/23/restsharp-extensions-returning-tasks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=restsharp-extensions-returning-tasks</link>
		<comments>http://ianobermiller.com/blog/2012/07/23/restsharp-extensions-returning-tasks/#comments</comments>
		<pubDate>Tue, 24 Jul 2012 06:01:03 +0000</pubDate>
		<dc:creator>iano</dc:creator>
				<category><![CDATA[.NET 4.5]]></category>
		<category><![CDATA[async/await]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[RestSharp]]></category>

		<guid isPermaLink="false">http://ianobermiller.com/?p=80</guid>
		<description><![CDATA[In order to use RestSharp with the async/await keywords, the methods must return Task objects. Since this isn&#8217;t provided out of the box, some simple wrappers will do the trick: They can be used easily in the Async CTP or .NET 4.5 as follows: Enjoy!]]></description>
				<content:encoded><![CDATA[<p>In order to use RestSharp with the async/await keywords, the methods must return <code>Task</code> objects. Since this isn&#8217;t provided out of the box, some simple wrappers will do the trick:</p>
<p><span id="more-80"></span></p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Threading.Tasks;
using RestSharp;

namespace RestSharpEx
{
    public static class RestClientExtensions
    {
        private static Task&lt;T&gt; SelectAsync&lt;T&gt;(this RestClient client, IRestRequest request, Func&lt;IRestResponse, T&gt; selector)
        {
            var tcs = new TaskCompletionSource&lt;T&gt;();
            var loginResponse = client.ExecuteAsync(request, r =&gt;
            {
                if (r.ErrorException == null)
                {
                    tcs.SetResult(selector(r));
                }
                else
                {
                    tcs.SetException(r.ErrorException);
                }
            });
            return tcs.Task;
        }

        public static Task&lt;string&gt; GetContentAsync(this RestClient client, IRestRequest request)
        {
            return client.SelectAsync(request, r =&gt; r.Content);
        }

        public static Task&lt;IRestResponse&gt; GetResponseAsync(this RestClient client, IRestRequest request)
        {
            return client.SelectAsync(request, r =&gt; r);
        }
    }
}
</pre>
<p>They can be used easily in the Async CTP or .NET 4.5 as follows:</p>
<pre class="brush: csharp; title: ; notranslate">
var client = new RestClient(&quot;http://example.org&quot;);
var request = new RestRequest(&quot;product/42&quot;, Method.GET);
var content = await client.GetContentAsync(request);
</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://ianobermiller.com/blog/2012/07/23/restsharp-extensions-returning-tasks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
