<?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>Bits, Bytes And Burps &#187; howto</title>
	<atom:link href="http://www.brainyautomation.com/blog/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brainyautomation.com/blog</link>
	<description>Tech Ramblings of a Confused Mind...</description>
	<lastBuildDate>Wed, 16 Mar 2011 20:57:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Just delete the damn folder&#8230;</title>
		<link>http://www.brainyautomation.com/blog/2011/01/28/just-delete-the-damn-folder/</link>
		<comments>http://www.brainyautomation.com/blog/2011/01/28/just-delete-the-damn-folder/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 14:53:05 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[Windows7]]></category>
		<category><![CDATA[!justworks]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.brainyautomation.com/blog/?p=126</guid>
		<description><![CDATA[So I run into a problem where there are folders on my &#8220;Storage&#8221; drive (like drive &#8220;D:&#8221; that is way<a href="http://www.brainyautomation.com/blog/2011/01/28/just-delete-the-damn-folder/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>So I run into a problem where there are folders on my &#8220;Storage&#8221; drive (like drive &#8220;D:&#8221; that is way bigger than my boot drive) that for some unknown friggin&#8217; reason I am unable to delete, Windows 7 just gives me some run around and makes me want to take a sledgehammer to the damn thing.</p>
<p>So searching around and I found how to delete it; Change the owner the admin, change the acl&#8217;s, then use rmdir from cmd line.</p>
<p>Like so (to whack folder &#8220;D:\delete_damnit&#8221;);</p>
<ul>
<li>Right-click on folder -> Properties -> Security Tab</li>
<li>Click on Advanced button -> Owner tab</li>
<li>Edit.. button</li>
<li>Select Administrators in &#8216;Change owner to&#8217;, check &#8216;replace owner on subcontainers and objects&#8217;</li>
<li>Open cmd.exe as administrator</li>
<li>Run &#8216;cacls D:\delete_damnit /T /e /g Administrators:f&#8217;</li>
<li>Run &#8216;rmdir /S D:delete_damnit&#8217;</li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2011/01/28/just-delete-the-damn-folder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery UI Themeswitcher Cookie Expires</title>
		<link>http://www.brainyautomation.com/blog/2010/09/23/jquery-ui-themeswitcher-cookie-expires/</link>
		<comments>http://www.brainyautomation.com/blog/2010/09/23/jquery-ui-themeswitcher-cookie-expires/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 21:39:48 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[jquery UI]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.brainyautomation.com/blog/?p=110</guid>
		<description><![CDATA[So I disagree with the current setup that is the default configuration with jQuery UI Themeswitcher, it expires the cookie<a href="http://www.brainyautomation.com/blog/2010/09/23/jquery-ui-themeswitcher-cookie-expires/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>So I disagree with the current setup that is the default configuration with jQuery UI Themeswitcher, it expires the cookie at the end of the session. I mean really if the user is going to change the cookie to some color scheme they like chances are its going to be for longer than the current session and for crying out loud the user is going to expect your site to load the theme they selected last &#8211; else it looks broken. Just a poor decision in my opinion &#8211; so here is how I fixed it to last 1 year.</p>
<p>Download the <a href="http://jqueryui.com/themeroller/themeswitchertool/">themeswitcher.js</a> and save it locally wherever you like.</p>
<p>Now add the &#8220;cookieName&#8221; below this to the options defition in the file;</p>
<pre name="code" class="javascript">
    var options = jQuery.extend({
        loadTheme: null,
        initialText: 'Switch Theme',
        width: 150,
        height: 200,
        buttonPreText: 'Theme: ',
        closeOnSelect: true,
        buttonHeight: 14,
        cookieName: 'jquery-ui-theme',
        cookieExpires: 365,
        onOpen: function () { },
        onClose: function () { },
        onSelect: function () { }
    }, settings);
</pre>
<p>Now modify where the cookie gets made to use this new &#8220;cookieExpires&#8221; option (line 49);</p>
<pre name="code" class="javascript">
        $.cookie(options.cookieName, themeName, { expires: options.cookieExpires });
</pre>
<p>Know you can either use the default set here (365) or set your own in the initializer in your calling script;</p>
<pre name="code" class="javascript">
    $('#switcher').themeswitcher({ cookieExpires: 365, path: '/', loadTheme: "Sunny"});
</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2010/09/23/jquery-ui-themeswitcher-cookie-expires/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Securing ELMAH with ASP.NET MVC</title>
		<link>http://www.brainyautomation.com/blog/2010/09/10/securing-elmah-with-asp-net-mvc/</link>
		<comments>http://www.brainyautomation.com/blog/2010/09/10/securing-elmah-with-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 01:31:55 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.brainyautomation.com/blog/?p=105</guid>
		<description><![CDATA[So I like Elmah and its logging of my unhandled exceptions suer, but I don&#8217;t need every yahoo with visibility<a href="http://www.brainyautomation.com/blog/2010/09/10/securing-elmah-with-asp-net-mvc/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>So I like <a href="http://code.google.com/p/elmah/">Elmah</a> and its logging of my unhandled exceptions suer, but I don&#8217;t need every yahoo with visibility to that. This is the steps I took to only allow Elmah access to users in the &#8220;Admin&#8221; role and have it still work with ASP.NET MVC.</p>
<p>Put this into the web.config;</p>
<pre name="code" class="xml">
  <location path="admin">
    <system.web>
      <httpHandlers>
        <add path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah"/>
      </httpHandlers>
      <authorization>
        <allow roles="Admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
</pre>
<p>Now put this into your global.asax, up top (before all the other routing) is best;</p>
<pre name="code" class="csharp">
            routes.IgnoreRoute("admin/elmah.axd");
            routes.IgnoreRoute("admin/{resource}.axd/{*pathInfo}");
</pre>
<p>You don&#8217;t have have any controller action setup, the handler builds this on the fly to handle the incomding axd request. Nice and simple.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2010/09/10/securing-elmah-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple merging object to object</title>
		<link>http://www.brainyautomation.com/blog/2010/08/12/91/</link>
		<comments>http://www.brainyautomation.com/blog/2010/08/12/91/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 21:07:07 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[aspnetmvc]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.brainyautomation.com/blog/?p=91</guid>
		<description><![CDATA[I use View Models to hand to my MVC views, nice and slim with little if any methods on them<a href="http://www.brainyautomation.com/blog/2010/08/12/91/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>I use View Models to hand to my MVC views, nice and slim with little if any methods on them and I use a think ORM model that has all my business logic and is generated by my ORM (BLToolkit).</p>
<p>So the problem is I wanted to take the View Model and update the ORM model with the modified values from the post, kind of a reverse AutoMapper (or BLToolkit.Mapper).</p>
<p>So a ORM class like this;</p>
<pre name="code" class="csharp">
    public class Contact
    {
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; }
         // Loads of other properties
    }
</pre>
<p>And a View Model like this (note the type and name should be &#8220;EXACTLY&#8221; the same;</p>
<pre name="code" class="csharp">
    public class ContactModel
    {
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; }
    }
</pre>
<p>Then with this generic Extension method;</p>
<pre name="code" class="csharp">
        public static void MergeWith<T1, T2>(this T1 primary, T2 secondary)
        {
            foreach (var pi in typeof(T2).GetProperties())
            {
                var tpi = typeof(T1).GetProperties().Where(x => x.Name == pi.Name).FirstOrDefault();
                if (tpi == null)
                {
                    continue;
                }
                var priValue = tpi.GetGetMethod().Invoke(primary, null);
                var secValue = pi.GetGetMethod().Invoke(secondary, null);
                if (priValue == null || !priValue.Equals(secValue))
                {
                    tpi.GetSetMethod().Invoke(primary, new object[] { secValue });
                }
            }
        }
</pre>
<p>So you make the magic in the Controller (for example) like this;</p>
<pre name="code" class="csharp">
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult EditContact(ContactModel model)
    Contact c = Repo.Get&lt;Contact,long>(model.Id);
    c.MergeWith&lt;Contact,ContactModel>(model);
    Repo.Update&lt;Contact>(c);
}
</pre>
<p>Yea its cheesy, but it works for me <img src='http://www.brainyautomation.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2010/08/12/91/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nice javascript to set window size for popups</title>
		<link>http://www.brainyautomation.com/blog/2010/02/14/nice-javascript-to-set-window-size-for-popups/</link>
		<comments>http://www.brainyautomation.com/blog/2010/02/14/nice-javascript-to-set-window-size-for-popups/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:06:00 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">/blog/post/Nice-javascript-to-set-window-size-for-popups.aspx</guid>
		<description><![CDATA[This is some spiffy javascript to get the proper sizes of the window for say a nifty colorbox popup; var<a href="http://www.brainyautomation.com/blog/2010/02/14/nice-javascript-to-set-window-size-for-popups/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>This is some spiffy javascript to get the proper sizes of the window for say a nifty colorbox popup;</p>
<pre name="code" class="javascript">
    var myWidth = 0, myHeight = 0;</span>
    function setWindowSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &amp;&amp; ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body &amp;&amp; ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
};</pre>
<p>An example of using it is like this;</p>
<pre name="code" class="javascript">
$.fn.colorbox({
    iframe: true,
    open: true,
    href: '/Controller/Action',
    width: myWidth - 40, // just a bit smaller than the window
    height: myHeight - 40 // just a bit smaller than the window
});
</pre>
<p>Dont forget to bind the window resize to reset your size variables;</p>
<pre name="code" class="js">
$(window).resize(function(e){
    setWindowSize();
});
</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2010/02/14/nice-javascript-to-set-window-size-for-popups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two forms same page?</title>
		<link>http://www.brainyautomation.com/blog/2009/12/01/two-forms-same-page/</link>
		<comments>http://www.brainyautomation.com/blog/2009/12/01/two-forms-same-page/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:13:00 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">/blog/post/Two-forms-same-page.aspx</guid>
		<description><![CDATA[I have a page that has two forms in the same page, the catch is the second form is nested<a href="http://www.brainyautomation.com/blog/2009/12/01/two-forms-same-page/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>I have a page that has two forms in the same page, the catch is the second form is nested inside the first form. Well this violates W3C, and it seems that IE8 doesn&#8217;t work with it. Color me surprised that IE8 actually is doing what it suppose to do according to the HTML specs.</p>
<p>Anyhow I needed this to work for my form to function and I was limited on time. So here is what I did to make the submit work with IE8.</p>
<p>1. Remove the &#8220;Submit&#8221; on the Button and just make it plain button;</p>
<pre name="code" class="html">
<input type="button" id="Save" value="Save" /></pre>
<p>2. Add some jQuery magic to submit the first (the outer) form;</p>
<pre name="code" class="js">
$("#Save").click(function() {
    var form = $("form:first").serialize();
        $.ajax({
	    type: "POST",
	    url: "/Tickets/Edit/",
	    data: form,
	    success: function(msg) {
	    window.location = '/Tickets/Details/';
	    }
	});
});</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2009/12/01/two-forms-same-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Fiddler with Localhost and ASP.NET DEV IIS Server</title>
		<link>http://www.brainyautomation.com/blog/2009/09/27/using-fiddler-with-localhost-and-asp-net-dev-iis-server/</link>
		<comments>http://www.brainyautomation.com/blog/2009/09/27/using-fiddler-with-localhost-and-asp-net-dev-iis-server/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 03:53:00 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fiddler]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">/blog/post/Using-Fiddler-with-Localhost-and-ASPNET-DEV-IIS-Server.aspx</guid>
		<description><![CDATA[Quick and to the point (the 1234 is the port your local IIS dev server is running on); http://localhost:1234 &#60;-<a href="http://www.brainyautomation.com/blog/2009/09/27/using-fiddler-with-localhost-and-asp-net-dev-iis-server/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Quick and to the point (the 1234 is the port your local IIS dev server is running on);</p>
<p>http://localhost:1234 &lt;- fails</p>
<p>http://ipv4.fiddler:1234 &lt;- works</p>
<p>Enjoy!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2009/09/27/using-fiddler-with-localhost-and-asp-net-dev-iis-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid get Row Column Value</title>
		<link>http://www.brainyautomation.com/blog/2009/09/19/jqgrid-get-row-column-value/</link>
		<comments>http://www.brainyautomation.com/blog/2009/09/19/jqgrid-get-row-column-value/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 04:10:00 +0000</pubDate>
		<dc:creator>steven</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">/blog/post/jqGrid-get-Row-Column-Value.aspx</guid>
		<description><![CDATA[This took me a while to figure out, so I am putting it here for prosperity. This is how to<a href="http://www.brainyautomation.com/blog/2009/09/19/jqgrid-get-row-column-value/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>This took me a while to figure out, so I am putting it here for prosperity. This is how to get the value of a specific column in a jqGrid selected Row;</p>
<p><pre name="code" class="js">
ondblClickRow: function(id, rowid) {
    var ret = $("#grid").getRowData(id);
    window.location = '/Clients/Details/' + ret.ClientID;
}</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brainyautomation.com/blog/2009/09/19/jqgrid-get-row-column-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

